[build] possibility combine app default config with external

This commit is contained in:
Maxim Kadushkin 2019-10-14 16:46:01 +03:00
parent 1bf6271a80
commit b28919275f

View file

@ -102,14 +102,42 @@ module.exports = function(grunt) {
}
function doRegisterInitializeAppTask(name, appName, configFile) {
if ( !!process.env['EXTRA_CONFIG_PATH'] &&
grunt.file.exists(process.env['EXTRA_CONFIG_PATH'] + '/' + configFile) )
{
var _extConfig = require(process.env['EXTRA_CONFIG_PATH'] + '/' + configFile);
}
return grunt.registerTask('init-build-' + name, 'Initialize build ' + appName, function(){
defaultConfig = configFile;
packageFile = require('./' + defaultConfig);
if (packageFile)
if (packageFile) {
grunt.log.ok(appName + ' config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
if ( !!_extConfig && _extConfig.name == packageFile.name ) {
function _merge(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (_.isObject(target) && _.isObject(source)) {
for (const key in source) {
if (_.isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
else if (_.isArray(source[key])) target[key].push(...source[key]);
else _merge(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return _merge(target, ...sources);
}
_merge(packageFile, _extConfig);
}
} else grunt.log.error().writeln('Could not load config file'.red);
});
}