使用默认文件中的策略覆盖 YAML 中的设置?
Overriding setting in YAML using a strategy from the default file?
experienceList:
- dbAnalyst: &dbAnalyst
posName: 'Database Analyst / Net Tech'
companyName: 'Choices People Supporting People'
- webDevXetex: &webDevXetex
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
# ...
experienceStrategies:
- defaultExperience: &defaultExperience
- <<: *dbAnalyst
- <<: *webDevXetex
- webDevExperience: &webDevExperience
- <<: *webDevXetex
#...
experience: *defaultExperience
config/default.yml
这导致 experience
在 YAML 中输出为:
experience:
- dbAnalyst:
posName: 'Database Analyst / Net Tech'
companyName: 'Choices People Supporting People'
- webDevXetex:
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
现在我想做的是,将默认值保留在 config/default.yml
中,并在类似于以下内容的覆盖文件中选择不同的策略(上述 experienceStrategies:
之一)覆盖它们:
experience: *webDevExperience
config/override.yml
并希望产生以下结果:
experience:
- webDevXetex:
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
...
但是,我没有使用 node-config 库,而是遇到了错误;有没有办法在 yaml 和 node.js 中使用其他库或坚持使用节点配置来做到这一点?我见过另一个名为 node-config-yaml 的库,它允许您包含其他 yaml 文件,但不确定它是否允许您以使用 node-config
.
的方式覆盖设置
/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:933
throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3);
^
Error: Cannot parse config file: '/home/leeand00/Documents/lifehacker organized/docs/projdir/config/company_job.yml'
: YAMLException: unidentified alias "webDevExperience" at line 14, column 30:
experience: *webDevExperience
^
at util.parseFile (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:
933:11)
at /home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:702:28
at Array.forEach (native)
at /home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:698:14
at Array.forEach (native)
at util.loadFileConfigs (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/conf
ig.js:697:13)
at new Config (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:122:
27)
at Object.<anonymous> (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config
.js:1767:31)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
使用 node-config-yml
库实际上达到了目的,尽管它在这方面的文档很少,但它工作得很好。
看来是将两者的配置在内存中做成了一个文件。您可以使用别名和 node-config
中的合并功能,并根据需要覆盖。
experienceList:
- dbAnalyst: &dbAnalyst
posName: 'Database Analyst / Net Tech'
companyName: 'Choices People Supporting People'
- webDevXetex: &webDevXetex
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
# ...
experienceStrategies:
- defaultExperience: &defaultExperience
- <<: *dbAnalyst
- <<: *webDevXetex
- webDevExperience: &webDevExperience
- <<: *webDevXetex
#...
experience: *defaultExperience
config/default.yml
这导致 experience
在 YAML 中输出为:
experience:
- dbAnalyst:
posName: 'Database Analyst / Net Tech'
companyName: 'Choices People Supporting People'
- webDevXetex:
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
现在我想做的是,将默认值保留在 config/default.yml
中,并在类似于以下内容的覆盖文件中选择不同的策略(上述 experienceStrategies:
之一)覆盖它们:
experience: *webDevExperience
config/override.yml
并希望产生以下结果:
experience:
- webDevXetex:
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
...
但是,我没有使用 node-config 库,而是遇到了错误;有没有办法在 yaml 和 node.js 中使用其他库或坚持使用节点配置来做到这一点?我见过另一个名为 node-config-yaml 的库,它允许您包含其他 yaml 文件,但不确定它是否允许您以使用 node-config
.
/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:933
throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3);
^
Error: Cannot parse config file: '/home/leeand00/Documents/lifehacker organized/docs/projdir/config/company_job.yml'
: YAMLException: unidentified alias "webDevExperience" at line 14, column 30:
experience: *webDevExperience
^
at util.parseFile (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:
933:11)
at /home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:702:28
at Array.forEach (native)
at /home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:698:14
at Array.forEach (native)
at util.loadFileConfigs (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/conf
ig.js:697:13)
at new Config (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:122:
27)
at Object.<anonymous> (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config
.js:1767:31)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
使用 node-config-yml
库实际上达到了目的,尽管它在这方面的文档很少,但它工作得很好。
看来是将两者的配置在内存中做成了一个文件。您可以使用别名和 node-config
中的合并功能,并根据需要覆盖。