-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
list-stories.ts
29 lines (25 loc) · 958 Bytes
/
list-stories.ts
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
import * as path from 'path';
import slash from 'slash';
import { glob } from 'glob';
import { normalizeStories, commonGlobOptions } from '@storybook/core-common';
import type { Options } from '@storybook/types';
export async function listStories(options: Options) {
const { normalizePath } = await import('vite');
return (
await Promise.all(
normalizeStories(await options.presets.apply('stories', [], options), {
configDir: options.configDir,
workingDir: options.configDir,
}).map(({ directory, files }) => {
const pattern = path.join(directory, files);
const absolutePattern = path.isAbsolute(pattern)
? pattern
: path.join(options.configDir, pattern);
return glob(slash(absolutePattern), {
...commonGlobOptions(absolutePattern),
follow: true,
});
})
)
).reduce((carry, stories) => carry.concat(stories.map(normalizePath)), []);
}