/
types.ts
272 lines (249 loc) · 6.75 KB
/
types.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import type ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import type { PluginOptions } from '@storybook/react-docgen-typescript-plugin';
import { Configuration, Stats } from 'webpack';
import { TransformOptions } from '@babel/core';
import { Router } from 'express';
import { FileSystemCache } from 'file-system-cache';
import { Server } from 'http';
/**
* ⚠️ This file contains internal WIP types they MUST NOT be exported outside this package for now!
*/
export interface TypescriptConfig {
check: boolean;
reactDocgen: false | string;
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: boolean;
shouldRemoveUndefinedFromOptional: boolean;
propFilter: (prop: any) => boolean;
};
}
export interface CoreConfig {
builder: 'webpack4' | 'webpack5';
disableWebpackDefaults?: boolean;
}
export interface Presets {
apply(
extension: 'typescript',
config: TypescriptConfig,
args?: Options
): Promise<TypescriptConfig>;
apply(extension: 'babel', config: {}, args: any): Promise<TransformOptions>;
apply(extension: 'entries', config: [], args: any): Promise<unknown>;
apply(extension: 'stories', config: [], args: any): Promise<unknown>;
apply(
extension: 'webpack',
config: {},
args: { babelOptions?: TransformOptions } & any
): Promise<Configuration>;
apply(extension: 'managerEntries', config: [], args: any): Promise<string[]>;
apply(extension: 'refs', config: [], args: any): Promise<unknown>;
apply(extension: 'core', config: {}, args: any): Promise<CoreConfig>;
apply(
extension: 'managerWebpack',
config: {},
args: Options & { babelOptions?: TransformOptions } & ManagerWebpackOptions
): Promise<Configuration>;
apply<T extends unknown>(extension: string, config?: T, args?: unknown): Promise<T>;
}
export interface LoadedPreset {
name: string;
preset: any;
options: any;
}
export interface PresetsOptions {
corePresets: string[];
overridePresets: string[];
frameworkPresets: string[];
}
export type PresetConfig =
| string
| {
name: string;
options?: unknown;
};
export interface Ref {
id: string;
url: string;
title: string;
version: string;
type?: string;
}
export interface VersionCheck {
success: boolean;
data?: any;
error?: any;
time: number;
}
export interface ReleaseNotesData {
success: boolean;
currentVersion: string;
showOnFirstLaunch: boolean;
}
export interface BuilderResult {
stats?: Stats;
totalTime?: ReturnType<typeof process.hrtime>;
}
// TODO: this is a generic interface that we can share across multiple SB packages (like @storybook/cli)
export interface PackageJson {
name: string;
version: string;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
}
// TODO: This could be exported to the outside world and used in `options.ts` file of each `@storybook/APP`
// like it's described in docs/api/new-frameworks.md
export interface LoadOptions {
packageJson: PackageJson;
framework: string;
frameworkPresets: string[];
outputDir?: string;
configDir?: string;
ignorePreview?: boolean;
extendServer?: (server: Server) => void;
}
export interface ManagerWebpackOptions {
entries: string[];
refs: Record<string, Ref>;
}
export interface CLIOptions {
port?: number;
ignorePreview?: boolean;
previewUrl?: string;
forceBuildPreview?: boolean;
host?: string;
staticDir?: string[];
configDir?: string;
https?: boolean;
sslCa?: string[];
sslCert?: string;
sslKey?: string;
smokeTest?: boolean;
managerCache?: boolean;
ci?: boolean;
loglevel?: string;
quiet?: boolean;
versionUpdates?: boolean;
releaseNotes?: boolean;
dll?: boolean;
docs?: boolean;
docsDll?: boolean;
uiDll?: boolean;
debugWebpack?: boolean;
webpackStatsJson?: string | boolean;
outputDir?: string;
modern?: boolean;
}
export interface BuilderOptions {
configType?: 'DEVELOPMENT' | 'PRODUCTION';
ignorePreview: boolean;
cache: FileSystemCache;
configDir: string;
docsMode: boolean;
features?: StorybookConfig['features'];
versionCheck?: VersionCheck;
releaseNotesData?: ReleaseNotesData;
disableWebpackDefaults?: boolean;
}
export interface StorybookConfigOptions {
presets: Presets;
presetsList?: LoadedPreset[];
}
export type Options = LoadOptions & StorybookConfigOptions & CLIOptions & BuilderOptions;
export interface Builder<Config, Stats> {
getConfig: (options: Options) => Promise<Config>;
start: (args: {
options: Options;
startTime: ReturnType<typeof process.hrtime>;
router: Router;
server: Server;
}) => Promise<void | {
stats: Stats;
totalTime: ReturnType<typeof process.hrtime>;
bail: (e?: Error) => Promise<void>;
}>;
build: (arg: {
options: Options;
startTime: ReturnType<typeof process.hrtime>;
}) => Promise<void | Stats>;
bail: (e?: Error) => Promise<void>;
corePresets?: string[];
overridePresets?: string[];
}
/**
* Options for TypeScript usage within Storybook.
*/
export interface TypescriptOptions {
/**
* Enables type checking within Storybook.
*
* @default `false`
*/
check: boolean;
/**
* Configures `fork-ts-checker-webpack-plugin`
*/
checkOptions?: ForkTsCheckerWebpackPlugin['options'];
/**
* Sets the type of Docgen when working with React and TypeScript
*
* @default `'react-docgen-typescript'`
*/
reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
/**
* Configures `react-docgen-typescript-plugin`
*
* @default
* @see https://github.com/storybookjs/storybook/blob/next/lib/builder-webpack5/src/config/defaults.js#L4-L6
*/
reactDocgenTypescriptOptions: PluginOptions;
}
/**
* The interface for Storybook configuration in `main.ts` files.
*/
export interface StorybookConfig {
/**
* Sets the addons you want to use with Storybook.
*
* @example `['@storybook/addon-essentials']` or `[{ name: '@storybook/addon-essentials', options: { backgrounds: false } }]`
*/
addons?: Array<
| string
| {
name: string;
options?: any;
}
>;
core?: CoreConfig;
logLevel?: string;
features?: {
/**
* Allows to disable deprecated implicit PostCSS loader.
*/
postcss?: boolean;
/**
* Build stories.json automatically on start/build
*/
buildStoriesJson?: boolean;
/**
* Activate preview of CSF v3.0
*/
previewCsfV3?: boolean;
};
/**
* Tells Storybook where to find stories.
*
* @example `['./src/*.stories.@(j|t)sx?']`
*/
stories: string[];
/**
* Controls how Storybook handles TypeScript files.
*/
typescript?: Partial<TypescriptOptions>;
/**
* Modify or return a custom Webpack config.
*/
webpackFinal?: (
config: Configuration,
options: Options
) => Configuration | Promise<Configuration>;
}