YAML patcher to keep comments
Note: This module is dependent on yawn-yaml
module
npm install yaml-patcher
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 😭
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);
}
There may be any breaking changes before the first stable version.