generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 64
/
getStorybookMain.ts
32 lines (26 loc) 路 1.08 KB
/
getStorybookMain.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
30
31
32
import { join, resolve } from 'path';
import { serverRequire } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/types';
import dedent from 'ts-dedent';
let storybookMainConfig: StorybookConfig;
export const getStorybookMain = (configDir: string) => {
if (storybookMainConfig) {
return storybookMainConfig;
}
storybookMainConfig = serverRequire(join(resolve(configDir), 'main'));
if (!storybookMainConfig) {
throw new Error(
`Could not load main.js in ${configDir}. Is the config directory correct? You can change it by using --config-dir <path-to-dir>`
);
}
if (!storybookMainConfig.stories || storybookMainConfig.stories.length === 0) {
throw new Error(
dedent`
Could not find stories in main.js in ${configDir}.
If you are using a mono-repository, please run the test-runner only against your sub-package, which contains a .storybook folder with "stories" defined in main.js.
You can change the config directory by using --config-dir <path-to-dir>
`
);
}
return storybookMainConfig;
};