generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 64
/
getCliOptions.ts
59 lines (50 loc) 路 1.39 KB
/
getCliOptions.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { getParsedCliOptions } from './getParsedCliOptions';
import type { BrowserType } from 'jest-playwright-preset';
type CliOptions = {
runnerOptions: {
indexJson?: boolean;
url?: string;
configDir?: string;
eject?: boolean;
coverage?: boolean;
junit?: boolean;
browsers?: BrowserType | BrowserType[];
};
jestOptions: string[];
};
type StorybookRunnerCommand = keyof CliOptions['runnerOptions'];
const STORYBOOK_RUNNER_COMMANDS: StorybookRunnerCommand[] = [
'indexJson',
'configDir',
'browsers',
'eject',
'url',
'coverage',
'junit',
];
export const getCliOptions = () => {
const { options: allOptions, extraArgs } = getParsedCliOptions();
const defaultOptions: CliOptions = {
runnerOptions: {},
jestOptions: process.argv.splice(0, 2),
};
const finalOptions = Object.keys(allOptions).reduce((acc, key: any) => {
if (STORYBOOK_RUNNER_COMMANDS.includes(key)) {
//@ts-ignore
acc.runnerOptions[key] = allOptions[key];
} else {
if (allOptions[key] === true) {
acc.jestOptions.push(`--${key}`);
} else if (allOptions[key] === false) {
acc.jestOptions.push(`--no-${key}`);
} else {
acc.jestOptions.push(`--${key}`, allOptions[key]);
}
}
return acc;
}, defaultOptions);
if (extraArgs.length) {
finalOptions.jestOptions.push(...extraArgs);
}
return finalOptions;
};