forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-sb-packages-versions.js
43 lines (36 loc) · 1.21 KB
/
generate-sb-packages-versions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { writeJson, readJson } = require('fs-extra');
const path = require('path');
const globby = require('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, '..', 'src', 'versions.json'), packageToVersionMap, {
spaces: 2,
});
};
run().catch((e) => {
logger.error(e);
process.exit(1);
});