storybook/scripts/utils/package-json.ts
2023-01-17 15:40:39 +01:00

16 lines
600 B
TypeScript

import { readJSON, writeJSON } from 'fs-extra';
import { join } from 'path';
export async function updatePackageScripts({ cwd, prefix }: { cwd: string; prefix: string }) {
const packageJsonPath = join(cwd, 'package.json');
const packageJson = await readJSON(packageJsonPath);
packageJson.scripts = {
...packageJson.scripts,
...(packageJson.scripts.storybook && {
storybook: `${prefix} ${packageJson.scripts.storybook}`,
'build-storybook': `${prefix} ${packageJson.scripts['build-storybook']}`,
}),
};
await writeJSON(packageJsonPath, packageJson, { spaces: 2 });
}