storybook/scripts/utils/package-json.ts

25 lines
914 B
TypeScript
Raw Normal View History

2022-10-03 17:16:39 +11:00
import { readJSON, writeJSON } from 'fs-extra';
import { join } from 'path';
const logger = console;
2022-10-11 09:20:05 +11:00
export async function updatePackageScripts({ cwd, prefix }: { cwd: string; prefix: string }) {
logger.info(`🔢 Adding package scripts:`);
2022-10-03 17:16:39 +11:00
const packageJsonPath = join(cwd, 'package.json');
const packageJson = await readJSON(packageJsonPath);
packageJson.scripts = {
...packageJson.scripts,
storybook: packageJson.scripts.storybook.replace(/(npx )?storybook/, `${prefix} storybook`),
'build-storybook': packageJson.scripts['build-storybook'].replace(
/(npx )?storybook/,
`${prefix} storybook`
),
// See comment in combine-compodoc as to why this is necessary
...(packageJson.scripts['docs:json'] && {
'docs:json': 'DIR=$PWD; cd ../../scripts; yarn ts-node combine-compodoc $DIR',
}),
2022-10-03 17:16:39 +11:00
};
await writeJSON(packageJsonPath, packageJson, { spaces: 2 });
}