storybook/lib/cli/scripts/generate-sb-packages-versions.js
Gaëtan Maisse 6ab9520716
chore(cli): refactor script to extract and save versions of all SB packages
The previous script was only extracting version for packages under `app`
directory. Now, all `@storybook` packages are processed and save with
their current version in the monorepo in `versions.json`. This file will
be use to find out which version of the packages should be installed
when running `sb init`.
2020-07-11 11:09:59 +02:00

42 lines
1.2 KiB
JavaScript

import { writeJson, readJson } from 'fs-extra';
import path from 'path';
import globby from 'globby';
const rootDirectory = path.join(__dirname, '..', '..', '..');
const logger = console;
const run = async () => {
const storybookPackagesPaths = await globby(
`${rootDirectory}/@(app|addons|lib)/**/package.json`,
{
ignore: '**/node_modules/**/*',
}
);
const packageToVersionMap = (
await Promise.all(
storybookPackagesPaths.map(async (storybookPackagePath) => {
const { name, version } = await readJson(storybookPackagePath);
return {
name,
version,
};
})
)
)
// Remove non-`@storybook/XXX` package (like: `cli-sb`, `cli-storybook`)
.filter(({ name }) => /@storybook/.test(name))
// As some previous steps are asynchronous order is not always the same so sort them to avoid that
.sort((package1, package2) => package1.name.localeCompare(package2.name))
.reduce((acc, { name, version }) => ({ ...acc, [name]: version }), {});
await writeJson(path.join(__dirname, '..', 'versions.json'), packageToVersionMap, { spaces: 2 });
};
run().catch((e) => {
logger.error(e);
process.exit(1);
});