You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
736 B
25 lines
736 B
import type { PackageJson } from "type-fest";
|
|
import fs from "fs-extra";
|
|
import path from "path";
|
|
|
|
export async function getPackageJson(
|
|
projectFolder: string,
|
|
): Promise<PackageJson> {
|
|
return JSON.parse(
|
|
(
|
|
await fs.promises.readFile(path.join(projectFolder, "./package.json"))
|
|
).toString(),
|
|
);
|
|
}
|
|
|
|
export async function modifyPackageJson(
|
|
projectFolder: string,
|
|
modifyCallback: (packageJson: PackageJson) => Promise<PackageJson>,
|
|
): Promise<void> {
|
|
const packageJson: PackageJson = await getPackageJson(projectFolder);
|
|
const newPackageJson = await modifyCallback(packageJson);
|
|
await fs.promises.writeFile(
|
|
path.join(projectFolder, "./package.json"),
|
|
JSON.stringify(newPackageJson, null, 2),
|
|
);
|
|
}
|
|
|