diff --git a/index.js b/index.js index 5a0987b..f5220ef 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,10 @@ const path = require('path') const commander = require('commander') const deepmerge = require('deepmerge') +const my = { secretKeys:[] } + module.exports = { - mergeConfig: function(rawConfig) { + mergeConfig(rawConfig) { if (!global.EnviConfig) { global.EnviConfig = rawConfig // 不知为何,必须定义成全局变量,才能保证多次require只执行一次。 @@ -33,7 +35,9 @@ module.exports = { } if (fs.existsSync((configFile = path.join(process.cwd(), './ConfigSecret.js')))) { // 如果存在,覆盖掉 ConfigBasic 和 ConfigCustom 里的参数 - global.EnviConfig = deepmerge(global.EnviConfig, require(configFile)) + let secretConfig = require(configFile) + my.secretKeys = Object.keys(secretConfig) + global.EnviConfig = deepmerge(global.EnviConfig, secretConfig) console.info(`${configFile} loaded`) } else { console.warn(` - Missing and omitting ${configFile}`) @@ -61,13 +65,14 @@ module.exports = { } } } + delete global.EnviConfig.commanderOptions // do not print commanderOptions to console - console.log('- Final Configuration: ', global.EnviConfig) - console.log('######## Completed System Configuration ########') + + console.log('######## Completed Environment Configuration ########') return global.EnviConfig }, - getDynamicConfig: function (dynamicConfigFile='ConfigDynamic.js') { // dynamicConfigFile should be absolute or relative to the node process's dir. + getDynamicConfig(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] 不起作用 @@ -76,4 +81,16 @@ module.exports = { return {} } }, + + showEnvi() { + console.log('{') + for (let key in global.EnviConfig) { + if (my.secretKeys.hasOwnProperty(key)) { + console.log(` ${key} : ******,`) + } else { + console.log(` ${key} : `, global.EnviConfig[key], ',') + } + } + console.log('}') + } }