2023-04-06 14:38:42 +00:00
|
|
|
import fs from 'node:fs/promises';
|
|
|
|
import path from 'node:path';
|
|
|
|
import micromatch from 'micromatch';
|
|
|
|
import main from './main';
|
2023-04-06 13:25:40 +00:00
|
|
|
|
2023-04-06 13:58:59 +00:00
|
|
|
fs.readFile(
|
2023-04-06 14:38:42 +00:00
|
|
|
path.resolve(__dirname, '../storybook-static/preview-stats.json')
|
2023-04-06 13:58:59 +00:00
|
|
|
).then((buffer) => {
|
|
|
|
const stats = JSON.parse(buffer.toString());
|
|
|
|
const modules = new Set(
|
2023-04-06 14:38:42 +00:00
|
|
|
process.argv
|
|
|
|
.slice(2)
|
|
|
|
.map((arg) =>
|
|
|
|
path.relative(
|
|
|
|
path.resolve(__dirname, '..'),
|
|
|
|
path.resolve(__dirname, '../../..', arg)
|
|
|
|
)
|
|
|
|
)
|
2023-04-06 13:58:59 +00:00
|
|
|
);
|
|
|
|
if (
|
|
|
|
micromatch(Array.from(modules), [
|
2023-04-06 14:38:42 +00:00
|
|
|
'../../assets/**',
|
|
|
|
'../../fluent-emojis/**',
|
|
|
|
'../../locales/**',
|
|
|
|
'../../misskey-assets/**',
|
|
|
|
'assets/**',
|
|
|
|
'public/**',
|
|
|
|
'../../pnpm-lock.yaml',
|
2023-04-06 13:58:59 +00:00
|
|
|
]).length
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
const oldSize = modules.size;
|
|
|
|
for (const module of Array.from(modules)) {
|
|
|
|
if (stats.modules[module]) {
|
|
|
|
for (const reason of stats.modules[module].reasons) {
|
|
|
|
modules.add(reason.moduleName);
|
2023-04-06 13:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-06 13:58:59 +00:00
|
|
|
if (modules.size === oldSize) {
|
|
|
|
break;
|
2023-04-06 13:25:40 +00:00
|
|
|
}
|
2023-04-06 13:58:59 +00:00
|
|
|
}
|
2023-04-06 14:38:42 +00:00
|
|
|
const stories = micromatch(
|
|
|
|
Array.from(modules),
|
|
|
|
main.stories.map((story) => path.resolve(__dirname, story))
|
|
|
|
);
|
2023-04-06 14:47:42 +00:00
|
|
|
if (stories.length) {
|
|
|
|
for (const story of stories) {
|
|
|
|
process.stdout.write(` --only-story-files ${story}`);
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-06 14:56:37 +00:00
|
|
|
process.stdout.write(` --skip`)
|
2023-04-06 13:58:59 +00:00
|
|
|
}
|
|
|
|
});
|