2023-08-28 04:25:31 -05:00
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-08-28 04:25:31 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-04-07 06:34:23 -05:00
|
|
|
import fs from 'node:fs/promises';
|
2023-07-09 03:19:07 -05:00
|
|
|
import { fileURLToPath } from 'node:url';
|
2023-04-07 06:34:23 -05:00
|
|
|
import path from 'node:path';
|
|
|
|
import micromatch from 'micromatch';
|
2023-07-09 03:19:07 -05:00
|
|
|
import main from './main.js';
|
|
|
|
|
|
|
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
2023-04-07 06:34:23 -05:00
|
|
|
|
|
|
|
interface Stats {
|
|
|
|
readonly modules: readonly {
|
|
|
|
readonly id: string;
|
|
|
|
readonly name: string;
|
|
|
|
readonly reasons: readonly {
|
|
|
|
readonly moduleName: string;
|
|
|
|
}[];
|
|
|
|
}[];
|
|
|
|
}
|
|
|
|
|
2023-07-09 03:19:07 -05:00
|
|
|
await fs.readFile(
|
|
|
|
new URL('../storybook-static/preview-stats.json', import.meta.url)
|
2023-04-07 06:34:23 -05:00
|
|
|
).then((buffer) => {
|
|
|
|
const stats: Stats = JSON.parse(buffer.toString());
|
|
|
|
const keys = new Set(stats.modules.map((stat) => stat.id));
|
|
|
|
const map = new Map(
|
|
|
|
Array.from(keys, (key) => [
|
|
|
|
key,
|
|
|
|
new Set(
|
|
|
|
stats.modules
|
|
|
|
.filter((stat) => stat.id === key)
|
|
|
|
.flatMap((stat) => stat.reasons)
|
|
|
|
.map((reason) => reason.moduleName)
|
|
|
|
),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
const modules = new Set(
|
|
|
|
process.argv
|
|
|
|
.slice(2)
|
|
|
|
.map((arg) =>
|
|
|
|
path.relative(
|
|
|
|
path.resolve(__dirname, '..'),
|
|
|
|
path.resolve(__dirname, '../../..', arg)
|
|
|
|
)
|
|
|
|
)
|
2023-04-16 06:00:07 -05:00
|
|
|
.map((path) => path.replace(/(?:(?<=\.stories)\.(?:impl|meta)|\.msw)(?=\.ts$)/g, ''))
|
2023-04-07 06:34:23 -05:00
|
|
|
);
|
|
|
|
if (
|
|
|
|
micromatch(Array.from(modules), [
|
|
|
|
'../../assets/**',
|
|
|
|
'../../fluent-emojis/**',
|
2023-05-11 08:05:37 -05:00
|
|
|
'../../locales/ja-JP.yml',
|
2023-04-07 06:34:23 -05:00
|
|
|
'assets/**',
|
|
|
|
'public/**',
|
|
|
|
'../../pnpm-lock.yaml',
|
|
|
|
]).length
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
const oldSize = modules.size;
|
|
|
|
for (const module of Array.from(modules)) {
|
|
|
|
if (map.has(module)) {
|
|
|
|
for (const dependency of Array.from(map.get(module)!)) {
|
|
|
|
modules.add(dependency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (modules.size === oldSize) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const stories = micromatch(
|
|
|
|
Array.from(modules),
|
|
|
|
main.stories.map((story) => `./${path.relative('..', story)}`)
|
|
|
|
);
|
|
|
|
if (stories.length) {
|
|
|
|
for (const story of stories) {
|
|
|
|
process.stdout.write(` --only-story-files ${story}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
process.stdout.write(` --skip`);
|
|
|
|
}
|
|
|
|
});
|