Files
TermiNexus e9e4693333
Some checks failed
Run mypy_primer on push / Run mypy_primer on push (push) Has been cancelled
Validation / Typecheck (push) Has been cancelled
Validation / Style (push) Has been cancelled
Validation / Test macos-latest (push) Has been cancelled
Validation / Test ubuntu-latest (push) Has been cancelled
Validation / Test windows-latest (push) Has been cancelled
Validation / Build (push) Has been cancelled
Validation / Required (push) Has been cancelled
初始化上传
2026-07-24 17:08:39 +08:00

38 lines
820 B
JavaScript

/* eslint-disable @typescript-eslint/no-var-requires */
//@ts-check
const { promises: fsAsync } = require('fs');
/**
* @param {string} filepath
* @param {(obj: any) => void} modifier
*/
async function modifyJsonInPlace(filepath, modifier) {
const input = await fsAsync.readFile(filepath, 'utf-8');
const obj = JSON.parse(input);
modifier(obj);
// Always 4 spaces for indent.
let output = JSON.stringify(obj, null, 4);
if (input.endsWith('\n')) {
output += '\n';
}
if (input.indexOf('\r\n') !== -1) {
output = output.replace(/\n/g, '\r\n');
}
await fsAsync.writeFile(filepath, output, 'utf-8');
}
async function main() {
const name = process.argv[2];
await modifyJsonInPlace('package.json', (obj) => {
obj.name = name;
});
}
main();