generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 64
/
getStorybookMain.ts
38 lines (31 loc) 路 1.25 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
33
34
35
36
37
38
import { join, resolve } from 'path';
import { serverRequire } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/types';
import dedent from 'ts-dedent';
let storybookMainConfig = new Map<string, StorybookConfig>();
export const getStorybookMain = (configDir: string) => {
if (storybookMainConfig.has(configDir)) {
return storybookMainConfig.get(configDir);
} else {
storybookMainConfig.set(configDir, serverRequire(join(resolve(configDir), 'main')));
}
const mainConfig = storybookMainConfig.get(configDir);
if (!mainConfig) {
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 (!mainConfig.stories || mainConfig.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 mainConfig;
};
export function resetStorybookMainCache() {
storybookMainConfig.clear();
}