yaml-merge
用于合并YAML文件的超简单工具.
安装
对于命令行
npm install -g @alexlafroscia/yaml-merge
供通过节点使用
npm install --save @alexlafroscia/yaml-merge
使用量
yaml-merge 使用一系列 yaml 文件并把它们从左到右合并。 这意味着第一个文件将被第二个文件的属性所覆盖,而第三个文件的属性所覆盖,等等.
命令行
当从命令行使用此工具时, 输出文件将只写到 STDOUT
yaml-merge test/fixtures/basic/a.yml test/fixtures/basic/b.yml
a:
foo: bar
b:
foo: bar
这样,就可以将输出吹入任何你想要的. 例如,这将写入新的 yaml 文件为 output.yml
yaml-merge test/fixtures/basic/a.yml test/fixtures/basic/b.yml > output.yml
所提供的文件名称将相对于当前目录解决 。 因此,你提供了与文件相对的路径,或者一个绝对路径-- 要么方法有效.
作为节点包
yaml-merge 还提供a node 软件包,可以用于程序化获取输出文件.
const resolve = require('path').resolve;
const merge = require('@alexlafroscia/yaml-merge');
const output = merge(resolve('relative/path/to/file.yml'), '/Users/you/some/other/file.yml');
console.log(output); // Prints out the resulting YAML as a string