(opts: {
scripts: Record<string, string>;
projectDir: string;
})
| 4 | import { type PackageJson } from "type-fest"; |
| 5 | |
| 6 | export const addPackageScript = (opts: { |
| 7 | scripts: Record<string, string>; |
| 8 | projectDir: string; |
| 9 | }) => { |
| 10 | const { scripts, projectDir } = opts; |
| 11 | |
| 12 | const packageJsonPath = path.join(projectDir, "package.json"); |
| 13 | const packageJsonContent = fs.readJSONSync(packageJsonPath) as PackageJson; |
| 14 | |
| 15 | packageJsonContent.scripts = { |
| 16 | ...packageJsonContent.scripts, |
| 17 | ...scripts, |
| 18 | }; |
| 19 | |
| 20 | const sortedPkgJson = sortPackageJson(packageJsonContent); |
| 21 | |
| 22 | fs.writeJSONSync(packageJsonPath, sortedPkgJson, { |
| 23 | spaces: 2, |
| 24 | }); |
| 25 | }; |
no outgoing calls
no test coverage detected