mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 22:48:06 +00:00
836afde273
* chore(tools): pre-format output JSON files This also helps when running changes locally, as there's no need to run `prettier` to check the actual updates between what's committed. Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io> * refactor: directly use `prettier` * fixup! refactor: directly use `prettier` --------- Co-authored-by: gpt-4.1 <jamie.tanna+github-copilot@mend.io>
27 lines
753 B
JavaScript
27 lines
753 B
JavaScript
import { isString } from '@sindresorhus/is';
|
|
import fs from 'fs-extra';
|
|
import prettier from 'prettier';
|
|
|
|
/**
|
|
* Update given file with new provided data.
|
|
* @param {string} file Path to a data file
|
|
* @param {string|NodeJS.ArrayBufferView} newData New data to be written
|
|
*/
|
|
export async function updateJsonFile(file, newData) {
|
|
try {
|
|
console.log(`Updating ${file}`);
|
|
const newString = isString(newData)
|
|
? newData
|
|
: Buffer.from(
|
|
newData.buffer,
|
|
newData.byteOffset,
|
|
newData.byteLength,
|
|
).toString('utf8');
|
|
const pretty = await prettier.format(newString, { parser: 'json' });
|
|
await fs.writeFile(file, pretty);
|
|
} catch (e) {
|
|
console.error(e.toString());
|
|
process.exit(1);
|
|
}
|
|
}
|