@better-builds/lets-version
Version:
A package that reads your conventional commits and git history and recommends (or applies) a SemVer version bump for you
15 lines (14 loc) • 585 B
JavaScript
import os from 'node:os';
import path from 'node:path';
import detectIndent from 'detect-indent';
import fs from 'fs-extra';
/**
* Flushes package.json contents to disk,
* maintaining the user's original indentation size and type
*/
export async function writePackageJSON(contents, filePath) {
const p = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);
const ogPackageJson = await fs.readFile(p, 'utf-8');
const indent = detectIndent(ogPackageJson);
await fs.writeFile(p, `${JSON.stringify(contents, null, indent.indent ?? ' ')}${os.EOL}`, 'utf-8');
}