ignore *nogit* and *nosf*

This commit is contained in:
Luk 2024-09-22 15:51:25 +08:00
parent 6939fed6e2
commit 94fa5915b3
3 changed files with 42 additions and 8 deletions

6
.gitignore vendored
View File

@ -13,9 +13,13 @@
?*.gitignore.*
?*.gitignore.*/
*.gitomit
*.gitomit/
*.gitomit.*
*.gitomit/
*.gitomit.*/
*.nogit
*.nogit.*
*.nogit/
*.nogit.*/
# 保留
!.gitignore
!.gitignore.*

View File

@ -16,11 +16,16 @@ module.exports = {
// .on('all', (event, onpath)) 但这时即使server刚启动也会调用到这里一次
console.log('envarTool.start_watching: envar file changed:', onpath)
try {
// 或者调用 get_dynamic_envar。
delete require.cache[require.resolve(path.resolve(onpath))]
assign_deep(rawEnvar, require(path.resolve(onpath)))
console.log(`envarTool.start_watching: successfully reload ${onpath}`)
let newEnvar = require(path.resolve(onpath))
if (typeof newEnvar === 'function') newEnvar = newEnvar()
// 注意assign_deep 会用 newEnvar 里的 undefined 属性覆盖掉 rawEnvar 里的原属性!所以要注意保持一致。(这和发送到前端的不一样,发送到前端的会被 JSON.stringify 以及 express 过滤掉 undefined.)
// 目前的解决方案里,已通过 base2app 参数来确保只在发送给前端时才设置 undefined但为防万一在这里通过 JSON.stringify 确保删除了 undefined
assign_deep(rawEnvar, JSON.parse(JSON.stringify(newEnvar)))
console.log(`envarTool.start_watching: OK reload ${onpath}`)
} catch (expt) {
console.log(`envarTool.start_watching: failed reload ${onpath}`)
console.log(`envarTool.start_watching: Fail reload ${onpath}`)
}
})
},
@ -58,7 +63,12 @@ module.exports = {
if (Array.isArray(envarFiles)) {
for (let configFile of envarFiles) {
if (fs.existsSync(path.resolve(configFile))) {
assign_deep(rawEnvar, require(path.resolve(configFile)))
const fileContent = require(path.resolve(configFile))
if (typeof fileContent === 'object') {
assign_deep(rawEnvar, fileContent)
} else if (typeof fileContent === 'function') {
assign_deep(rawEnvar, fileContent())
}
console.info({ _at: new Date().toJSON(), _from: 'merge_envar', about: ` - ${configFile} is loaded.` }, '\n,')
} else {
console.warn({ _at: new Date().toJSON(), _from: 'merge_envar', about: ` - ${configFile} is missing.` }, '\n,')
@ -66,6 +76,8 @@ module.exports = {
}
} else if (typeof envarFiles === 'object') {
assign_deep(rawEnvar, envarFiles)
} else if (typeof envarFiles === 'function') {
assign_deep(rawEnvar, envarFiles())
} else {
console.warn({ _at: new Date().toJSON(), _from: 'merge_envar', about: ` - unrecognized envarFiles!` }, '\n,')
}
@ -95,7 +107,7 @@ module.exports = {
/*
*/
get_dynamic_envar ({ dynamicEnvarFiles = ['./envar-base-dynamic.js', './envar-base-dynamic.gitignore.js'] } = {}) {
get_dynamic_envar ({ dynamicEnvarFiles = ['./envar-base-dynamic.js', './envar-base-dynamic.gitignore.js'], base2app } = {}) {
// config file should be absolute or relative to the node process's dir.
let dynamicEnvar = {}
@ -114,7 +126,12 @@ module.exports = {
for (let dynamicFile of dynamicEnvarFiles) {
if (fs.existsSync(path.resolve(dynamicFile))) {
delete require.cache[require.resolve(path.resolve(dynamicFile))] // delete require.cache[fullpath] 不起作用,必须要加 require.resolve
assign_deep(dynamicEnvar, require(path.resolve(dynamicFile))) // 在这里其实不需要 assign_deep
const fileContent = require(path.resolve(dynamicFile))
if (typeof fileContent === 'object') {
assign_deep(dynamicEnvar, fileContent)
} else if (typeof fileContent === 'function') {
assign_deep(dynamicEnvar, fileContent({ base2app }))
}
console.info({ _at: new Date().toJSON(), _from: 'get_dynamic_envar', about: ` - ${dynamicFile} is parsed.` }, '\n,')
} else {
console.warn({ _at: new Date().toJSON(), _from: 'get_dynamic_envar', about: ` - ${dynamicFile} is missing.` }, '\n,')
@ -122,6 +139,8 @@ module.exports = {
}
} else if (typeof dynamicEnvarFiles === 'object') {
dynamicEnvar = dynamicEnvarFiles
} else if (typeof dynamicEnvarFiles === 'function') {
dynamicEnvar = dynamicEnvarFiles()
} else {
console.warn({ _at: new Date().toJSON(), _from: 'get_dynamic_envar', about: ` - unrecognized dynamicEnvarFiles!` }, '\n,')
}
@ -150,7 +169,12 @@ module.exports = {
if (Array.isArray(secretEnvarFiles)) {
for (let secretFile of secretEnvarFiles) {
if (fs.existsSync(path.resolve(secretFile))) {
assign_deep(secretEnvar, require(path.resolve(secretFile))) // 在这里其实不需要 assign_deep
const fileContent = require(path.resolve(secretFile))
if (typeof fileContent === 'object') {
assign_deep(secretEnvar, fileContent)
} else if (typeof fileContent === 'function') {
assign_deep(secretEnvar, fileContent())
}
console.info({ _at: new Date().toJSON(), _from: 'mask_secret_envar', about: ` - ${secretFile} is parsed.` }, '\n,')
} else {
console.warn({ _at: new Date().toJSON(), _from: 'mask_secret_envar', about: ` - ${secretFile} is missing.` }, '\n,')
@ -158,6 +182,8 @@ module.exports = {
}
} else if (typeof secretEnvarFiles === 'object') {
secretEnvar = secretEnvarFiles
} else if (typeof secretEnvarFiles === 'function') {
dynamicEnvar = secretEnvarFiles()
} else {
console.warn({ _at: new Date().toJSON(), _from: 'mask_secret_envar', about: ` - unrecognized secretEnvarFiles!` }, '\n,')
}

View File

@ -17,6 +17,10 @@
*.sfomit.*
*.sfomit/
*.sfomit.*/
*.nosf
*.nosf.*
*.nosf/
*.nosf.*/
.DS_Store
*/.DS_Store