forked from histoire-dev/histoire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
211 lines (204 loc) · 5.26 KB
/
config.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
import type {
UserConfig as ViteConfig,
ConfigEnv as ViteConfigEnv,
} from 'vite'
import type MarkdownIt from 'markdown-it'
import type { ServerTreeFile, StoryProps } from './story.js'
import type { Plugin } from './plugin.js'
export interface SupportMatchPattern {
id: string
patterns: string[]
pluginIds: string[]
}
export type CustomizableColors = 'primary' | 'gray'
export type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
export type GrayColorKeys = ColorKeys | '750' | '850' | '950'
export interface ResponsivePreset {
label: string
width: number
height: number
}
export interface BackgroundPreset {
label: string
color: string
contrastColor?: string
}
export interface TreeGroupConfig {
title: string
id?: string
include?: (file: ServerTreeFile) => boolean
}
export interface HistoireConfig {
plugins: Plugin[]
/**
* Output directory.
*/
outDir: string
/**
* Glob patterns for story files to include.
*/
storyMatch: string[]
/**
* Glob patterns to ignore files while searching for story files.
*/
storyIgnored: string[]
/**
* Patterns to match stories to support plugins automatically.
*/
supportMatch: SupportMatchPattern[]
/**
* How to generate the story tree.
*/
tree: {
/**
* Use `'title'` to create the path from the title of the story, using `/` as the separator.
*
* Use `'path'` use the real folder structure on your computer.
*/
file?: 'title' | 'path' | ((file: ServerTreeFile) => string[])
order?: 'asc' | ((a: string, b: string) => number)
groups?: TreeGroupConfig[]
}
/**
* Customize the look of the histoire book.
*/
theme: {
/**
* Main page title. For example: 'Acme Inc.'
*/
title?: string
/**
* Custom logo files. Should be import paths (processed by Vite).
*
* Example: `'/src/assets/my-logo.svg'`
*/
logo?: {
/**
* Square logo without text.
*/
square?: string
/**
* Full logo for light theme.
*/
light?: string
/**
* Full logo for dark theme.
*/
dark?: string
}
/**
* Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
*
* Example: `'/favicon.ico'`
*/
favicon?: string
/**
* Customize the colors. Each color should be an object with shades as keys.
*
* Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
*
* You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
*/
colors?: {
[key in CustomizableColors]?: key extends 'gray' ? {
[key in GrayColorKeys]?: string
} :{
[key in ColorKeys]?: string
}
}
/**
* Add a link to the main logo
*/
logoHref?: string
}
/**
* Setup file exporting a default function executed when setting up each story preview.
*
* Import custom CSS files from this file.
*
* Example: `'/src/histoire-setup.ts'`
*/
setupFile?: string | {
/**
* Only loaded in the browser client.
*/
browser: string
} | {
/**
* Only loaded while collecting stories in the node server.
*/
server: string
} | {
/**
* Only loaded in the browser client.
*/
browser: string
/**
* Only loaded while collecting stories in the node server.
*/
server: string
}
/**
* Setup code created by plugins
*/
setupCode?: string[]
/**
* Predefined responsive sizes for story playgrounds.
*/
responsivePresets?: ResponsivePreset[]
/**
* Background color of the story preview.
*/
backgroundPresets?: BackgroundPreset[]
/**
* Class added to the html root of the story preview when dark mode is enabled.
*/
sandboxDarkClass?: string
/**
* Default props for stories.
*/
defaultStoryProps?: Omit<StoryProps, 'id' | 'setupApp' | 'title' | 'source'>
/**
* Customize the markdown-it renderer
*/
markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
/**
* Change the router mode.
* - history: use HTML history with cleaner URLs
* - hash: use hashtag hack in the URL to support more hosting services
*/
routerMode?: 'history' | 'hash'
/**
* Vite config override
*/
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
/**
* Remove those plugins from the Vite configuration
*/
viteIgnorePlugins?: string[]
/**
* Transpile dependencies when collecting stories on Node.js
*/
viteNodeInlineDeps?: RegExp[]
/**
* Determine the transform method of modules
*/
viteNodeTransformMode?: {
/**
* Use SSR transform pipeline for the specified files.
* Vite plugins will receive `ssr: true` flag when processing those files.
*
* @default [/\.([cm]?[jt]sx?|json)$/]
*/
ssr?: RegExp[]
/**
* First do a normal transform pipeline (targeting browser),
* then then do a SSR rewrite to run the code in Node.
* Vite plugins will receive `ssr: false` flag when processing those files.
*
* @default other than `ssr`
*/
web?: RegExp[]
}
}
export type ConfigMode = 'build' | 'dev'