From fa009491ac0f3ccf6b03a4e4f0d80ad861231782 Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Sat, 12 Mar 2022 08:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20showEnvi()=EF=BC=8C?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=8E=89=E6=9C=BA=E5=AF=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=86=8D=E8=BE=93=E5=87=BA=EF=BC=8C=E4=BB=A5=E9=98=B2=E8=A2=AB?= =?UTF-8?q?=E5=AD=98=E5=85=A5=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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('}') + } }