From b8f677155c449c99d0c844ed61147d7c1aa0653e Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Sat, 23 Apr 2022 16:03:59 +0800 Subject: [PATCH] renaming Config*.js to envar-base-*.js --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 127be9a..4da59ff 100644 --- a/index.js +++ b/index.js @@ -13,31 +13,31 @@ module.exports = { console.info('<<<<<<<< Merging Environment Configuration (依次载入基础配置、用户配置、机密配置、命令行参数) <<<<<<<<') // 配置参数(按优先级从低到高): - // ConfigBasic: 系统常量(全大写) 以及 默认参数(小写开头驼峰式) - // ConfigCustom: 用户或应用自定义参数。本文件不应纳入版本管理。 - // ConfigSecret: 机密参数,例如哈希盐,webtoken密钥,等等。本文件绝对不能纳入版本管理。 + // envar-base-basic.js: 系统常量(全大写) 以及 默认参数(小写开头驼峰式) + // envar-base-custom.js: 用户或应用自定义参数。本文件不应纳入版本管理。 + // envar-base-secret.js: 机密参数,例如哈希盐,webtoken密钥,等等。本文件绝对不能纳入版本管理。 // 命令行参数 console.info('(1) Loading Configuration Files (读取配置文件)') let configFile - if (fs.existsSync((configFile = path.join(process.cwd(), './ConfigBasic.js')))) { + if (fs.existsSync((configFile = path.join(process.cwd(), './envar-base-basic.js')))) { global.envar = deepmerge(global.envar, require(configFile)) console.info(` - ${configFile} is loaded.`) } else { console.warn(` - ${configFile} is missing.`) } - if (fs.existsSync((configFile = path.join(process.cwd(), './ConfigCustom.js')))) { - // 如果存在,覆盖掉 ConfigBasic 里的默认参数 + if (fs.existsSync((configFile = path.join(process.cwd(), './envar-base-custom.js')))) { + // 如果存在,覆盖掉 envar-base-basic.js 里的默认参数 global.envar = deepmerge(global.envar, require(configFile)) // 注意,objectMerge后,产生了一个新的对象,而不是在原来的Config里添加 console.info(`${configFile} is loaded.`) } else { console.warn(` - ${configFile} is missing.`) } - if (fs.existsSync((configFile = path.join(process.cwd(), './ConfigSecret.js')))) { - // 如果存在,覆盖掉 ConfigBasic 和 ConfigCustom 里的参数 + if (fs.existsSync((configFile = path.join(process.cwd(), './envar-base-secret.js')))) { + // 如果存在,覆盖掉 envar-base-basic.js 和 envar-base-custom.js 里的参数 let secretConfig = require(configFile) my.secretKeys = Object.keys(secretConfig) global.envar = deepmerge(global.envar, secretConfig) @@ -75,7 +75,7 @@ module.exports = { return global.envar }, - getDynamicConfig(dynamicConfigFile='ConfigDynamic.js') { // dynamicConfigFile should be absolute or relative to the node process's dir. + getDynamicConfig(dynamicConfigFile='config-dynamic.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] 不起作用