use config to determine active theme

This commit is contained in:
Art Lowel
2019-06-04 17:12:12 +02:00
parent 8bccdac99d
commit c58e6f6239
8 changed files with 224 additions and 12 deletions

View File

@@ -6,6 +6,8 @@ const projectRoot = (relativePath) => {
return path.resolve(__dirname, '..', relativePath);
};
const srcPath = projectRoot('src');
const buildRoot = (relativePath) => {
if (process.env.DSPACE_BUILD_DIR) {
return path.resolve(projectRoot(process.env.DSPACE_BUILD_DIR), relativePath);
@@ -14,10 +16,46 @@ const buildRoot = (relativePath) => {
}
};
// const theme = '';
const theme = 'mantis';
//TODO refactor to share between this and config.ts.
const getThemeName = () => {
let defaultCfg = require(projectRoot('config/environment.default.js'));
let envConfigFile, envConfigOverride;
const themePath = path.normalize(path.join(__dirname, '..', 'themes', theme));
switch (process.env.NODE_ENV) {
case 'prod':
case 'production':
// webpack.prod.dspace-angular-config.ts defines process.env.NODE_ENV = 'production'
envConfigFile = projectRoot('config/environment.prod.js');
break;
case 'test':
// webpack.test.dspace-angular-config.ts defines process.env.NODE_ENV = 'test'
envConfigFile = projectRoot('config/environment.test.js');
break;
default:
// if not using webpack.prod.dspace-angular-config.ts or webpack.test.dspace-angular-config.ts, it must be development
envConfigFile = projectRoot('config/environment.dev.js');
}
if (envConfigFile) {
try {
envConfigOverride = require(envConfigFile);
} catch (e) {
}
}
return Object.assign({}, defaultCfg.theme, envConfigOverride.theme).name;
}
const theme = getThemeName();
let themePath;
if (theme !== null && theme !== undefined) {
themePath = path.normalize(path.join(__dirname, '..', 'themes', theme));
}
else {
themePath = srcPath;
}
const globalCSSImports = [
buildRoot('styles/_variables.scss'),
@@ -35,7 +73,6 @@ const themeReplaceOptions =
]
};
const srcPath = projectRoot('src');
const getThemedPath = (componentPath, ext) => {
const parsedPath = path.parse(componentPath);
@@ -71,7 +108,7 @@ const themedUse = (resource, extension) => {
module.exports = {
projectRoot,
buildRoot,
theme,
theme: theme,
themePath,
getThemedPath,
themedTest,

View File

@@ -1,23 +0,0 @@
const replace = require('replace-in-file');
const {
projectRoot,
} = require('./helpers');
/**
* This script ensures you can use ~ to reference the project dir
* in scss imports for AoT builds as well.
*/
const options = {
files: projectRoot('build') + '/**/*.scss',
from: /@import '~\//g,
to: `@import '${projectRoot('./')}/`,
};
try {
replace.sync(options);
}
catch (error) {
console.error('Error occurred:', error);
}

View File

@@ -1,13 +0,0 @@
const path = require('path');
const child_process = require('child_process');
const heapSize = 4096;
const webpackPath = path.join('node_modules', 'webpack', 'bin', 'webpack.js');
const params = [
'--max_old_space_size=' + heapSize,
webpackPath,
...process.argv.slice(2)
];
child_process.spawn('node', params, { stdio:'inherit' });

View File

@@ -97,7 +97,6 @@ module.exports = {
includePaths: [path.join(themePath, 'styles')]
}
},
'debug-loader',
{
loader: 'sass-resources-loader',
options: {