upgrade to include mergeConfig() and getDynamicConfig()
This commit is contained in:
parent
41d5fe36fd
commit
533d8126b2
14
index.js
14
index.js
@ -3,7 +3,8 @@ const path = require('path')
|
|||||||
const commander = require('commander')
|
const commander = require('commander')
|
||||||
const deepmerge = require('deepmerge')
|
const deepmerge = require('deepmerge')
|
||||||
|
|
||||||
module.exports = function (rawConfig) {
|
module.exports = {
|
||||||
|
mergeConfig: function(rawConfig) {
|
||||||
if (!global.EnviConfig) {
|
if (!global.EnviConfig) {
|
||||||
global.EnviConfig = rawConfig
|
global.EnviConfig = rawConfig
|
||||||
// 不知为何,必须定义成全局变量,才能保证多次require只执行一次。
|
// 不知为何,必须定义成全局变量,才能保证多次require只执行一次。
|
||||||
@ -63,4 +64,15 @@ module.exports = function (rawConfig) {
|
|||||||
console.log('- Final Configuration: ', global.EnviConfig)
|
console.log('- Final Configuration: ', global.EnviConfig)
|
||||||
console.log('######## Completed System Configuration ########')
|
console.log('######## Completed System Configuration ########')
|
||||||
return global.EnviConfig
|
return global.EnviConfig
|
||||||
|
},
|
||||||
|
|
||||||
|
getDynamicConfig: function (dynamicConfigFile='ConfigDynamic.js') { // dynamicConfigFile should be absolute or relative to the node process's dir.
|
||||||
|
const fullpath = path.join(process.cwd(), dynamicConfigFile)
|
||||||
|
if (fs.existsSync(fullpath)) {
|
||||||
|
delete require.cache[require.resolve(fullpath)] // delete require.cache[fullpath] 不起作用
|
||||||
|
return require(fullpath)
|
||||||
|
} else {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user