0.0.2 • Published 3 years ago
yaml-patcher v0.0.2
yaml-patcher
YAML patcher to keep comments
Install
Note: This module is dependent on yawn-yaml
module
npm install yaml-patcher
Why
YAML is a human-readable data-serialization language, and may contains comments
With no consideration about it, parse, manipulate, serialize it leads all comments gone :sob:
Usage
import yaml from 'js-yaml';
import YamlPatcher from 'yaml-patcher';
import CONFIG_PATH from '@src/constants';
import { readFile, writeFile } from '@src/utils';
export async function updateConfig(configUpdateAction) {
const oldContent = await readFile(CONFIG_PATH);
const oldConfig = yaml.load(oldContent);
const newConfig = configUpdateAction(oldConfig);
const newContent = YamlPatcher(oldContent, newConfig);
await writeFile(CONFIG_PATH, newContent);
}
Notice
There may be any breaking changes before the first stable version.