renaming Config*.js to envar-base-*.js
This commit is contained in:
parent
44b89632d7
commit
b8f677155c
18
index.js
18
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] 不起作用
|
||||
|
Loading…
Reference in New Issue
Block a user