mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
use config to determine active theme
This commit is contained in:
@@ -155,5 +155,9 @@ module.exports = {
|
|||||||
edit: {
|
edit: {
|
||||||
undoTimeout: 10000 // 10 seconds
|
undoTimeout: 10000 // 10 seconds
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
theme: {
|
||||||
|
name: 'default',
|
||||||
|
cssClass: 'default',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
10
package.json
10
package.json
@@ -24,9 +24,9 @@
|
|||||||
"prebuild": "yarn run clean:bld && yarn run clean:dist",
|
"prebuild": "yarn run clean:bld && yarn run clean:dist",
|
||||||
"prebuild:aot": "yarn run prebuild",
|
"prebuild:aot": "yarn run prebuild",
|
||||||
"prebuild:prod": "yarn run prebuild",
|
"prebuild:prod": "yarn run prebuild",
|
||||||
"build": "node ./webpack/run-webpack.js --progress --mode development",
|
"build": "node ./scripts/webpack.js --progress --mode development",
|
||||||
"build:aot": "yarn run syncbuilddir && node ./webpack/run-replace.js && DSPACE_BUILD_DIR=./build node ./webpack/run-webpack.js --env.aot --env.server --mode development && DSPACE_BUILD_DIR=./build node ./webpack/run-webpack.js --env.aot --env.client --mode development",
|
"build:aot": "yarn run syncbuilddir && node ./scripts/resolve-absolute-scss-imports.js && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.server --mode development && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.client --mode development",
|
||||||
"build:prod": "yarn run syncbuilddir && node ./webpack/run-replace.js && DSPACE_BUILD_DIR=./build node ./webpack/run-webpack.js --env.aot --env.server --mode production && DSPACE_BUILD_DIR=./build node ./webpack/run-webpack.js --env.aot --env.client --mode production",
|
"build:prod": "yarn run syncbuilddir && node ./scripts/resolve-absolute-scss-imports.js && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.server --mode production && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.client --mode production",
|
||||||
"postbuild:prod": "yarn run rollup",
|
"postbuild:prod": "yarn run rollup",
|
||||||
"rollup": "rollup -c rollup.config.js",
|
"rollup": "rollup -c rollup.config.js",
|
||||||
"prestart": "yarn run build:prod",
|
"prestart": "yarn run build:prod",
|
||||||
@@ -41,8 +41,8 @@
|
|||||||
"server": "node dist/server.js",
|
"server": "node dist/server.js",
|
||||||
"server:watch": "nodemon dist/server.js",
|
"server:watch": "nodemon dist/server.js",
|
||||||
"server:watch:debug": "nodemon --debug dist/server.js",
|
"server:watch:debug": "nodemon --debug dist/server.js",
|
||||||
"syncbuilddir": "copyfiles -u 1 \"./src/**/*\" build && copyfiles -u 2 \"./themes/mantis/**/*\" build",
|
"syncbuilddir": "node ./scripts/sync-build-dir.js",
|
||||||
"webpack:watch": "node ./webpack/run-webpack.js -w --mode development",
|
"webpack:watch": "node ./scripts/webpack.js -w --mode development",
|
||||||
"watch": "yarn run build && npm-run-all -p webpack:watch server:watch",
|
"watch": "yarn run build && npm-run-all -p webpack:watch server:watch",
|
||||||
"watch:debug": "yarn run build && npm-run-all -p webpack:watch server:watch:debug",
|
"watch:debug": "yarn run build && npm-run-all -p webpack:watch server:watch:debug",
|
||||||
"predebug": "yarn run build",
|
"predebug": "yarn run build",
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
const replace = require('replace-in-file');
|
const replace = require('replace-in-file');
|
||||||
const {
|
const {
|
||||||
projectRoot,
|
projectRoot,
|
||||||
} = require('./helpers');
|
} = require('../webpack/helpers');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This script ensures you can use ~ to reference the project dir
|
* This script ensures you can use ~ to reference the project dir
|
22
scripts/sync-build-dir.js
Normal file
22
scripts/sync-build-dir.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const syncBuildDir = require('copyfiles');
|
||||||
|
const path = require('path');
|
||||||
|
const {
|
||||||
|
projectRoot,
|
||||||
|
theme,
|
||||||
|
themePath,
|
||||||
|
} = require('../webpack/helpers');
|
||||||
|
|
||||||
|
const projectDepth = projectRoot('./').split(path.sep).length;
|
||||||
|
|
||||||
|
let callback;
|
||||||
|
|
||||||
|
if (theme !== null && theme !== undefined) {
|
||||||
|
callback = () => {
|
||||||
|
syncBuildDir([path.join(themePath, '**/*'), 'build'], { up: projectDepth + 2 }, () => {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
callback = () => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
syncBuildDir([projectRoot('src/**/*'), 'build'], { up: projectDepth + 1 }, callback);
|
150
src/config.js
Normal file
150
src/config.js
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
let production = false;
|
||||||
|
|
||||||
|
let mergedConfig;
|
||||||
|
|
||||||
|
let envConfigOverride;
|
||||||
|
|
||||||
|
let envConfigFile;
|
||||||
|
|
||||||
|
__webpack
|
||||||
|
|
||||||
|
// check process.env.NODE_ENV to determine which environment config to use
|
||||||
|
// process.env.NODE_ENV is defined by webpack, else assume development
|
||||||
|
switch (process.env.NODE_ENV) {
|
||||||
|
case 'prod':
|
||||||
|
case 'production':
|
||||||
|
// webpack.prod.dspace-angular-config.ts defines process.env.NODE_ENV = 'production'
|
||||||
|
envConfigFile = './environment.prod.js';
|
||||||
|
production = true;
|
||||||
|
break;
|
||||||
|
case 'test':
|
||||||
|
// webpack.test.dspace-angular-config.ts defines process.env.NODE_ENV = 'test'
|
||||||
|
envConfigFile = './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 = './environment.dev.js';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mergedConfig = require(path.resolve(__dirname, '..', 'config', 'environment.default.js'));
|
||||||
|
} catch (e) {
|
||||||
|
console.log('e', e);
|
||||||
|
throw new Error('Cannot find file config/environment.default.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
// if envConfigFile set try to get configs
|
||||||
|
if (envConfigFile) {
|
||||||
|
try {
|
||||||
|
envConfigOverride = require(path.resolve(__dirname, '..', 'config', envConfigFile));
|
||||||
|
} catch (e) {
|
||||||
|
console.log('e', e);
|
||||||
|
console.warn('Cannot find file ' + envConfigFile.substring(2, envConfigFile.length), 'Using default environment');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
merge(envConfigOverride);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Unable to merge the default environment');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow to override a few important options by environment variables
|
||||||
|
function createServerConfig(host, port, nameSpace, ssl) {
|
||||||
|
const result = { host, nameSpace };
|
||||||
|
|
||||||
|
if (port !== null && port !== undefined) {
|
||||||
|
result.port = port * 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ssl !== null && ssl !== undefined) {
|
||||||
|
result.ssl = ssl.trim().match(/^(true|1|yes)$/i) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const processEnv = {
|
||||||
|
ui: createServerConfig(
|
||||||
|
process.env.DSPACE_HOST,
|
||||||
|
process.env.DSPACE_PORT,
|
||||||
|
process.env.DSPACE_NAMESPACE,
|
||||||
|
process.env.DSPACE_SSL),
|
||||||
|
rest: createServerConfig(
|
||||||
|
process.env.DSPACE_REST_HOST,
|
||||||
|
process.env.DSPACE_REST_PORT,
|
||||||
|
process.env.DSPACE_REST_NAMESPACE,
|
||||||
|
process.env.DSPACE_REST_SSL)
|
||||||
|
};
|
||||||
|
|
||||||
|
// merge the environment variables with our configuration.
|
||||||
|
try {
|
||||||
|
merge(processEnv)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Unable to merge environment variable into the configuration')
|
||||||
|
}
|
||||||
|
|
||||||
|
buildBaseUrls();
|
||||||
|
|
||||||
|
// set config for whether running in production
|
||||||
|
mergedConfig.production = production;
|
||||||
|
|
||||||
|
function merge(config) {
|
||||||
|
innerMerge(mergedConfig, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
function innerMerge(globalConfig, config) {
|
||||||
|
for (const key in config) {
|
||||||
|
if (config.hasOwnProperty(key)) {
|
||||||
|
if (isObject(config[key])) {
|
||||||
|
innerMerge(globalConfig[key], config[key]);
|
||||||
|
} else {
|
||||||
|
if (isDefined(config[key])) {
|
||||||
|
globalConfig[key] = config[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildBaseUrls() {
|
||||||
|
for (const key in mergedConfig) {
|
||||||
|
if (mergedConfig.hasOwnProperty(key) && mergedConfig[key].host) {
|
||||||
|
mergedConfig[key].baseUrl = [
|
||||||
|
getProtocol(mergedConfig[key].ssl),
|
||||||
|
getHost(mergedConfig[key].host),
|
||||||
|
getPort(mergedConfig[key].port),
|
||||||
|
getNameSpace(mergedConfig[key].nameSpace)
|
||||||
|
].join('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProtocol(ssl) {
|
||||||
|
return ssl ? 'https://' : 'http://';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHost(host) {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPort(port) {
|
||||||
|
return port ? (port !== 80 && port !== 443) ? ':' + port : '' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNameSpace(nameSpace) {
|
||||||
|
return nameSpace ? nameSpace.charAt(0) === '/' ? nameSpace : '/' + nameSpace : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDefined(value) {
|
||||||
|
return typeof value !== 'undefined' && value !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isObject(item) {
|
||||||
|
return item && typeof item === 'object' && !Array.isArray(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mergedConfig: mergedConfig
|
||||||
|
};
|
@@ -6,6 +6,8 @@ const projectRoot = (relativePath) => {
|
|||||||
return path.resolve(__dirname, '..', relativePath);
|
return path.resolve(__dirname, '..', relativePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const srcPath = projectRoot('src');
|
||||||
|
|
||||||
const buildRoot = (relativePath) => {
|
const buildRoot = (relativePath) => {
|
||||||
if (process.env.DSPACE_BUILD_DIR) {
|
if (process.env.DSPACE_BUILD_DIR) {
|
||||||
return path.resolve(projectRoot(process.env.DSPACE_BUILD_DIR), relativePath);
|
return path.resolve(projectRoot(process.env.DSPACE_BUILD_DIR), relativePath);
|
||||||
@@ -14,10 +16,46 @@ const buildRoot = (relativePath) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// const theme = '';
|
//TODO refactor to share between this and config.ts.
|
||||||
const theme = 'mantis';
|
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 = [
|
const globalCSSImports = [
|
||||||
buildRoot('styles/_variables.scss'),
|
buildRoot('styles/_variables.scss'),
|
||||||
@@ -35,7 +73,6 @@ const themeReplaceOptions =
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const srcPath = projectRoot('src');
|
|
||||||
|
|
||||||
const getThemedPath = (componentPath, ext) => {
|
const getThemedPath = (componentPath, ext) => {
|
||||||
const parsedPath = path.parse(componentPath);
|
const parsedPath = path.parse(componentPath);
|
||||||
@@ -71,7 +108,7 @@ const themedUse = (resource, extension) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
projectRoot,
|
projectRoot,
|
||||||
buildRoot,
|
buildRoot,
|
||||||
theme,
|
theme: theme,
|
||||||
themePath,
|
themePath,
|
||||||
getThemedPath,
|
getThemedPath,
|
||||||
themedTest,
|
themedTest,
|
||||||
|
@@ -97,7 +97,6 @@ module.exports = {
|
|||||||
includePaths: [path.join(themePath, 'styles')]
|
includePaths: [path.join(themePath, 'styles')]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'debug-loader',
|
|
||||||
{
|
{
|
||||||
loader: 'sass-resources-loader',
|
loader: 'sass-resources-loader',
|
||||||
options: {
|
options: {
|
||||||
|
Reference in New Issue
Block a user