histoire 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +1 -2
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +1 -1
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +1 -1
- package/dist/node/config.d.ts +1 -174
- package/dist/node/context.d.ts +1 -2
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/load.d.ts +1 -5
- package/dist/node/plugin.d.ts +4 -54
- package/dist/node/tree.d.ts +1 -2
- package/dist/node/vite.js +1 -1
- package/package.json +5 -5
- package/src/node/build.ts +5 -1
- package/src/node/builtin-plugins/tailwind-tokens.ts +2 -2
- package/src/node/builtin-plugins/vanilla-support/plugin.ts +1 -1
- package/src/node/config.ts +6 -181
- package/src/node/context.ts +8 -2
- package/src/node/index.ts +1 -0
- package/src/node/load.ts +1 -6
- package/src/node/plugin.ts +12 -51
- package/src/node/tree.ts +7 -2
- package/src/node/vite.ts +1 -1
package/client.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export * from '@histoire/app'
|
|
1
|
+
export function hstEvent (name: string, argument): void
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Plugin } from '
|
|
1
|
+
import type { Plugin } from '@histoire/shared';
|
|
2
2
|
export declare function vanillaSupport(): Plugin;
|
package/dist/node/config.d.ts
CHANGED
|
@@ -1,176 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type MarkdownIt from 'markdown-it';
|
|
3
|
-
import type { ServerTreeFile } from '@histoire/shared';
|
|
4
|
-
import { Plugin } from './plugin.js';
|
|
5
|
-
export interface SupportMatchPattern {
|
|
6
|
-
id: string;
|
|
7
|
-
patterns: string[];
|
|
8
|
-
pluginIds: string[];
|
|
9
|
-
}
|
|
10
|
-
declare type CustomizableColors = 'primary' | 'gray';
|
|
11
|
-
declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
|
12
|
-
declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
|
|
13
|
-
export interface ResponsivePreset {
|
|
14
|
-
label: string;
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
}
|
|
18
|
-
export interface BackgroundPreset {
|
|
19
|
-
label: string;
|
|
20
|
-
color: string;
|
|
21
|
-
}
|
|
22
|
-
export interface TreeGroupConfig {
|
|
23
|
-
title: string;
|
|
24
|
-
id?: string;
|
|
25
|
-
include?: (file: ServerTreeFile) => boolean;
|
|
26
|
-
}
|
|
27
|
-
export interface HistoireConfig {
|
|
28
|
-
plugins: Plugin[];
|
|
29
|
-
/**
|
|
30
|
-
* Output directory.
|
|
31
|
-
*/
|
|
32
|
-
outDir: string;
|
|
33
|
-
/**
|
|
34
|
-
* Glob patterns for story files to include.
|
|
35
|
-
*/
|
|
36
|
-
storyMatch: string[];
|
|
37
|
-
/**
|
|
38
|
-
* Glob patterns to ignore files while searching for story files.
|
|
39
|
-
*/
|
|
40
|
-
storyIgnored: string[];
|
|
41
|
-
/**
|
|
42
|
-
* Patterns to match stories to support plugins automatically.
|
|
43
|
-
*/
|
|
44
|
-
supportMatch: SupportMatchPattern[];
|
|
45
|
-
/**
|
|
46
|
-
* How to generate the story tree.
|
|
47
|
-
*/
|
|
48
|
-
tree: {
|
|
49
|
-
/**
|
|
50
|
-
* Use `'title'` to create the path from the title of the story, using `/` as the separator.
|
|
51
|
-
*
|
|
52
|
-
* Use `'path'` use the real folder structure on your computer.
|
|
53
|
-
*/
|
|
54
|
-
file?: 'title' | 'path' | ((file: ServerTreeFile) => string[]);
|
|
55
|
-
order?: 'asc' | ((a: string, b: string) => number);
|
|
56
|
-
groups?: TreeGroupConfig[];
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Customize the look of the histoire book.
|
|
60
|
-
*/
|
|
61
|
-
theme: {
|
|
62
|
-
/**
|
|
63
|
-
* Main page title. For example: 'Acme Inc.'
|
|
64
|
-
*/
|
|
65
|
-
title?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Custom logo files. Should be import paths (processed by Vite).
|
|
68
|
-
*
|
|
69
|
-
* Example: `'/src/assets/my-logo.svg'`
|
|
70
|
-
*/
|
|
71
|
-
logo?: {
|
|
72
|
-
/**
|
|
73
|
-
* Square logo without text.
|
|
74
|
-
*/
|
|
75
|
-
square?: string;
|
|
76
|
-
/**
|
|
77
|
-
* Full logo for light theme.
|
|
78
|
-
*/
|
|
79
|
-
light?: string;
|
|
80
|
-
/**
|
|
81
|
-
* Full logo for dark theme.
|
|
82
|
-
*/
|
|
83
|
-
dark?: string;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
|
|
87
|
-
*
|
|
88
|
-
* Example: `'/favicon.ico'`
|
|
89
|
-
*/
|
|
90
|
-
favicon?: string;
|
|
91
|
-
/**
|
|
92
|
-
* Customize the colors. Each color should be an object with shades as keys.
|
|
93
|
-
*
|
|
94
|
-
* Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
|
|
95
|
-
*
|
|
96
|
-
* You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
|
|
97
|
-
*/
|
|
98
|
-
colors?: {
|
|
99
|
-
[key in CustomizableColors]?: key extends 'gray' ? {
|
|
100
|
-
[key in GrayColorKeys]?: string;
|
|
101
|
-
} : {
|
|
102
|
-
[key in ColorKeys]?: string;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Add a link to the main logo
|
|
107
|
-
*/
|
|
108
|
-
logoHref?: string;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Setup file exporting a default function executed when setting up each story preview.
|
|
112
|
-
*
|
|
113
|
-
* Import custom CSS files from this file.
|
|
114
|
-
*
|
|
115
|
-
* Example: `'/src/histoire-setup.ts'`
|
|
116
|
-
*/
|
|
117
|
-
setupFile?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Setup code created by plugins
|
|
120
|
-
*/
|
|
121
|
-
setupCode?: string[];
|
|
122
|
-
/**
|
|
123
|
-
* Predefined responsive sizes for story playgrounds.
|
|
124
|
-
*/
|
|
125
|
-
responsivePresets?: ResponsivePreset[];
|
|
126
|
-
/**
|
|
127
|
-
* Background color of the story preview.
|
|
128
|
-
*/
|
|
129
|
-
backgroundPresets?: BackgroundPreset[];
|
|
130
|
-
/**
|
|
131
|
-
* Class added to the html root of the story preview when dark mode is enabled.
|
|
132
|
-
*/
|
|
133
|
-
sandboxDarkClass?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Customize the markdown-it renderer
|
|
136
|
-
*/
|
|
137
|
-
markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
|
|
138
|
-
/**
|
|
139
|
-
* Change the router mode.
|
|
140
|
-
* - history: use HTML history with cleaner URLs
|
|
141
|
-
* - hash: use hashtag hack in the URL to support more hosting services
|
|
142
|
-
*/
|
|
143
|
-
routerMode?: 'history' | 'hash';
|
|
144
|
-
/**
|
|
145
|
-
* Vite config override
|
|
146
|
-
*/
|
|
147
|
-
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>);
|
|
148
|
-
/**
|
|
149
|
-
* Transpile dependencies when collecting stories on Node.js
|
|
150
|
-
*/
|
|
151
|
-
viteNodeInlineDeps?: RegExp[];
|
|
152
|
-
/**
|
|
153
|
-
* Determine the transform method of modules
|
|
154
|
-
*/
|
|
155
|
-
viteNodeTransformMode?: {
|
|
156
|
-
/**
|
|
157
|
-
* Use SSR transform pipeline for the specified files.
|
|
158
|
-
* Vite plugins will receive `ssr: true` flag when processing those files.
|
|
159
|
-
*
|
|
160
|
-
* @default [/\.([cm]?[jt]sx?|json)$/]
|
|
161
|
-
*/
|
|
162
|
-
ssr?: RegExp[];
|
|
163
|
-
/**
|
|
164
|
-
* First do a normal transform pipeline (targeting browser),
|
|
165
|
-
* then then do a SSR rewrite to run the code in Node.
|
|
166
|
-
* Vite plugins will receive `ssr: false` flag when processing those files.
|
|
167
|
-
*
|
|
168
|
-
* @default other than `ssr`
|
|
169
|
-
*/
|
|
170
|
-
web?: RegExp[];
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
export declare type ConfigMode = 'build' | 'dev';
|
|
1
|
+
import type { HistoireConfig, ConfigMode } from '@histoire/shared';
|
|
174
2
|
export declare function getDefaultConfig(): HistoireConfig;
|
|
175
3
|
export declare const configFileNames: string[];
|
|
176
4
|
export declare function resolveConfigFile(cwd?: string): string;
|
|
@@ -284,4 +112,3 @@ declare module 'vite' {
|
|
|
284
112
|
histoire?: Partial<HistoireConfig>;
|
|
285
113
|
}
|
|
286
114
|
}
|
|
287
|
-
export {};
|
package/dist/node/context.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ServerStoryFile, FinalSupportPlugin, ServerMarkdownFile } from '@histoire/shared';
|
|
2
|
-
import { HistoireConfig, ConfigMode } from './config.js';
|
|
1
|
+
import type { ServerStoryFile, FinalSupportPlugin, ServerMarkdownFile, HistoireConfig, ConfigMode } from '@histoire/shared';
|
|
3
2
|
export interface Context {
|
|
4
3
|
root: string;
|
|
5
4
|
config: HistoireConfig;
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.js
CHANGED
package/dist/node/load.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import type { ViteDevServer } from 'vite';
|
|
2
|
+
import type { ModuleLoader } from '@histoire/shared';
|
|
2
3
|
export interface UseModuleLoaderOptions {
|
|
3
4
|
server: ViteDevServer;
|
|
4
5
|
throws?: boolean;
|
|
5
6
|
}
|
|
6
|
-
export interface ModuleLoader {
|
|
7
|
-
clearCache: () => void;
|
|
8
|
-
loadModule: (file: string) => Promise<any>;
|
|
9
|
-
destroy: () => void;
|
|
10
|
-
}
|
|
11
7
|
export declare function useModuleLoader(options: UseModuleLoaderOptions): ModuleLoader;
|
|
12
8
|
export declare const loadModule: ModuleLoader['loadModule'];
|
package/dist/node/plugin.d.ts
CHANGED
|
@@ -1,52 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import chokidar from 'chokidar';
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
|
-
import type {
|
|
5
|
-
import type { ConfigMode, HistoireConfig } from './config.js';
|
|
4
|
+
import type { Plugin, PluginApiBase, PluginApiDev, PluginApiBuild, BuildEndCallback, PreviewStoryCallback, ModuleLoader } from '@histoire/shared';
|
|
6
5
|
import type { Context } from './context.js';
|
|
7
|
-
|
|
8
|
-
export interface Plugin {
|
|
9
|
-
/**
|
|
10
|
-
* Name of the plugin
|
|
11
|
-
*/
|
|
12
|
-
name: string;
|
|
13
|
-
/**
|
|
14
|
-
* Modify histoire default config. The hook can either mutate the passed config or
|
|
15
|
-
* return a partial config object that will be deeply merged into the existing
|
|
16
|
-
* config. User config will have higher priority than default config.
|
|
17
|
-
*
|
|
18
|
-
* Note: User plugins are resolved before running this hook so injecting other
|
|
19
|
-
* plugins inside the `config` hook will have no effect.
|
|
20
|
-
*/
|
|
21
|
-
defaultConfig?: (defaultConfig: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>;
|
|
22
|
-
/**
|
|
23
|
-
* Modify histoire config. The hook can either mutate the passed config or
|
|
24
|
-
* return a partial config object that will be deeply merged into the existing
|
|
25
|
-
* config.
|
|
26
|
-
*
|
|
27
|
-
* Note: User plugins are resolved before running this hook so injecting other
|
|
28
|
-
* plugins inside the `config` hook will have no effect.
|
|
29
|
-
*/
|
|
30
|
-
config?: (config: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>;
|
|
31
|
-
/**
|
|
32
|
-
* Use this hook to read and store the final resolved histoire config.
|
|
33
|
-
*/
|
|
34
|
-
configResolved?: (config: HistoireConfig) => void | Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Use this hook to do processing during development. The `onCleanup` hook
|
|
37
|
-
* should handle cleanup tasks when development server is closed.
|
|
38
|
-
*/
|
|
39
|
-
onDev?: (api: DevPluginApi, onCleanup: (cb: () => void | Promise<void>) => void) => void | Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Use this hook to do processing during production build.
|
|
42
|
-
*/
|
|
43
|
-
onBuild?: (api: BuildPluginApi) => void | Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* This plugin exposes a support plugin (example: Vue, Svelte, etc.)
|
|
46
|
-
*/
|
|
47
|
-
supportPlugin?: SupportPlugin;
|
|
48
|
-
}
|
|
49
|
-
export declare class BasePluginApi {
|
|
6
|
+
export declare class BasePluginApi implements PluginApiBase {
|
|
50
7
|
protected ctx: Context;
|
|
51
8
|
protected plugin: Plugin;
|
|
52
9
|
moduleLoader: ModuleLoader;
|
|
@@ -62,17 +19,10 @@ export declare class BasePluginApi {
|
|
|
62
19
|
error(...msg: any[]): void;
|
|
63
20
|
addStoryFile(file: string): void;
|
|
64
21
|
}
|
|
65
|
-
export declare class DevPluginApi extends BasePluginApi {
|
|
22
|
+
export declare class DevPluginApi extends BasePluginApi implements PluginApiDev {
|
|
66
23
|
watcher: typeof chokidar;
|
|
67
24
|
}
|
|
68
|
-
export declare
|
|
69
|
-
export declare type PreviewStoryCallback = (payload: {
|
|
70
|
-
file: string;
|
|
71
|
-
story: ServerStory;
|
|
72
|
-
variant: ServerVariant;
|
|
73
|
-
url: string;
|
|
74
|
-
}) => Promise<void> | void;
|
|
75
|
-
export declare class BuildPluginApi extends BasePluginApi {
|
|
25
|
+
export declare class BuildPluginApi extends BasePluginApi implements PluginApiBuild {
|
|
76
26
|
buildEndCallbacks: BuildEndCallback[];
|
|
77
27
|
previewStoryCallbacks: PreviewStoryCallback[];
|
|
78
28
|
onBuildEnd(cb: BuildEndCallback): void;
|
package/dist/node/tree.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ServerStoryFile, ServerTree, ServerTreeFile } from '@histoire/shared';
|
|
2
|
-
import type { HistoireConfig } from './config.js';
|
|
1
|
+
import type { ServerStoryFile, ServerTree, ServerTreeFile, HistoireConfig } from '@histoire/shared';
|
|
3
2
|
export declare function createPath(config: HistoireConfig, file: ServerTreeFile): string[];
|
|
4
3
|
export declare function makeTree(config: HistoireConfig, files: ServerStoryFile[]): ServerTree;
|
package/dist/node/vite.js
CHANGED
|
@@ -247,7 +247,7 @@ if (import.meta.hot) {
|
|
|
247
247
|
// List
|
|
248
248
|
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
249
249
|
// Setups
|
|
250
|
-
ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
250
|
+
...ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
251
251
|
for (const setup of setupList) {
|
|
252
252
|
if (setup?.${fnName}) {
|
|
253
253
|
await setup.${fnName}(payload)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"histoire": "./bin.mjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@histoire/app": "^0.10.
|
|
33
|
-
"@histoire/controls": "^0.10.
|
|
34
|
-
"@histoire/shared": "^0.10.
|
|
35
|
-
"@histoire/vendors": "^0.10.
|
|
32
|
+
"@histoire/app": "^0.10.3",
|
|
33
|
+
"@histoire/controls": "^0.10.3",
|
|
34
|
+
"@histoire/shared": "^0.10.3",
|
|
35
|
+
"@histoire/vendors": "^0.10.3",
|
|
36
36
|
"@types/flexsearch": "^0.7.3",
|
|
37
37
|
"@types/markdown-it": "^12.2.3",
|
|
38
38
|
"birpc": "^0.1.1",
|
package/src/node/build.ts
CHANGED
|
@@ -11,13 +11,17 @@ import fs from 'fs-extra'
|
|
|
11
11
|
import { lookup as lookupMime } from 'mrmime'
|
|
12
12
|
import pc from 'picocolors'
|
|
13
13
|
import { performance } from 'perf_hooks'
|
|
14
|
+
import type {
|
|
15
|
+
BuildEndCallback,
|
|
16
|
+
PreviewStoryCallback,
|
|
17
|
+
} from '@histoire/shared'
|
|
14
18
|
import { APP_PATH } from './alias.js'
|
|
15
19
|
import { Context } from './context.js'
|
|
16
20
|
import { getViteConfigWithPlugins, resolveViteConfig } from './vite.js'
|
|
17
21
|
import { findAllStories } from './stories.js'
|
|
18
22
|
import type { RollupOutput } from 'rollup'
|
|
19
23
|
import { useCollectStories } from './collect/index.js'
|
|
20
|
-
import {
|
|
24
|
+
import { BuildPluginApi } from './plugin.js'
|
|
21
25
|
import { useModuleLoader } from './load.js'
|
|
22
26
|
import { startPreview } from './preview.js'
|
|
23
27
|
import { createMarkdownFilesWatcher } from './markdown.js'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Plugin, PluginApiBase } from '@histoire/shared'
|
|
2
2
|
import { getInjectedImport } from '../util/vendors.js'
|
|
3
3
|
import { findUp } from '../util/find-up.js'
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ export function tailwindTokens (options: TailwindTokensOptions = {}): Plugin {
|
|
|
18
18
|
'tailwind-config.ts',
|
|
19
19
|
])
|
|
20
20
|
|
|
21
|
-
async function generate (api:
|
|
21
|
+
async function generate (api: PluginApiBase) {
|
|
22
22
|
try {
|
|
23
23
|
await api.fs.ensureDir(api.pluginTempDir)
|
|
24
24
|
await api.fs.emptyDir(api.pluginTempDir)
|
package/src/node/config.ts
CHANGED
|
@@ -3,197 +3,22 @@ import { createDefu } from 'defu'
|
|
|
3
3
|
import {
|
|
4
4
|
createServer,
|
|
5
5
|
resolveConfig as resolveViteConfig,
|
|
6
|
-
UserConfig as ViteConfig,
|
|
7
|
-
ConfigEnv as ViteConfigEnv,
|
|
8
6
|
mergeConfig as mergeViteConfig,
|
|
9
7
|
} from 'vite'
|
|
10
8
|
import { ViteNodeServer } from 'vite-node/server'
|
|
11
9
|
import { ViteNodeRunner } from 'vite-node/client'
|
|
12
10
|
import pc from 'picocolors'
|
|
13
|
-
import type
|
|
14
|
-
|
|
11
|
+
import type {
|
|
12
|
+
HistoireConfig,
|
|
13
|
+
SupportMatchPattern,
|
|
14
|
+
ConfigMode,
|
|
15
|
+
Plugin,
|
|
16
|
+
} from '@histoire/shared'
|
|
15
17
|
import { defaultColors } from './colors.js'
|
|
16
|
-
import { Plugin } from './plugin.js'
|
|
17
18
|
import { findUp } from './util/find-up.js'
|
|
18
19
|
import { tailwindTokens } from './builtin-plugins/tailwind-tokens.js'
|
|
19
20
|
import { vanillaSupport } from './builtin-plugins/vanilla-support/plugin.js'
|
|
20
21
|
|
|
21
|
-
export interface SupportMatchPattern {
|
|
22
|
-
id: string
|
|
23
|
-
patterns: string[]
|
|
24
|
-
pluginIds: string[]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type CustomizableColors = 'primary' | 'gray'
|
|
28
|
-
type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
|
|
29
|
-
type GrayColorKeys = ColorKeys | '750' | '850' | '950'
|
|
30
|
-
|
|
31
|
-
export interface ResponsivePreset {
|
|
32
|
-
label: string
|
|
33
|
-
width: number
|
|
34
|
-
height: number
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface BackgroundPreset {
|
|
38
|
-
label: string
|
|
39
|
-
color: string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface TreeGroupConfig {
|
|
43
|
-
title: string
|
|
44
|
-
id?: string
|
|
45
|
-
include?: (file: ServerTreeFile) => boolean
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface HistoireConfig {
|
|
49
|
-
plugins: Plugin[]
|
|
50
|
-
/**
|
|
51
|
-
* Output directory.
|
|
52
|
-
*/
|
|
53
|
-
outDir: string
|
|
54
|
-
/**
|
|
55
|
-
* Glob patterns for story files to include.
|
|
56
|
-
*/
|
|
57
|
-
storyMatch: string[]
|
|
58
|
-
/**
|
|
59
|
-
* Glob patterns to ignore files while searching for story files.
|
|
60
|
-
*/
|
|
61
|
-
storyIgnored: string[]
|
|
62
|
-
/**
|
|
63
|
-
* Patterns to match stories to support plugins automatically.
|
|
64
|
-
*/
|
|
65
|
-
supportMatch: SupportMatchPattern[]
|
|
66
|
-
/**
|
|
67
|
-
* How to generate the story tree.
|
|
68
|
-
*/
|
|
69
|
-
tree: {
|
|
70
|
-
/**
|
|
71
|
-
* Use `'title'` to create the path from the title of the story, using `/` as the separator.
|
|
72
|
-
*
|
|
73
|
-
* Use `'path'` use the real folder structure on your computer.
|
|
74
|
-
*/
|
|
75
|
-
file?: 'title' | 'path' | ((file: ServerTreeFile) => string[])
|
|
76
|
-
order?: 'asc' | ((a: string, b: string) => number)
|
|
77
|
-
groups?: TreeGroupConfig[]
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Customize the look of the histoire book.
|
|
81
|
-
*/
|
|
82
|
-
theme: {
|
|
83
|
-
/**
|
|
84
|
-
* Main page title. For example: 'Acme Inc.'
|
|
85
|
-
*/
|
|
86
|
-
title?: string
|
|
87
|
-
/**
|
|
88
|
-
* Custom logo files. Should be import paths (processed by Vite).
|
|
89
|
-
*
|
|
90
|
-
* Example: `'/src/assets/my-logo.svg'`
|
|
91
|
-
*/
|
|
92
|
-
logo?: {
|
|
93
|
-
/**
|
|
94
|
-
* Square logo without text.
|
|
95
|
-
*/
|
|
96
|
-
square?: string
|
|
97
|
-
/**
|
|
98
|
-
* Full logo for light theme.
|
|
99
|
-
*/
|
|
100
|
-
light?: string
|
|
101
|
-
/**
|
|
102
|
-
* Full logo for dark theme.
|
|
103
|
-
*/
|
|
104
|
-
dark?: string
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
|
|
108
|
-
*
|
|
109
|
-
* Example: `'/favicon.ico'`
|
|
110
|
-
*/
|
|
111
|
-
favicon?: string
|
|
112
|
-
/**
|
|
113
|
-
* Customize the colors. Each color should be an object with shades as keys.
|
|
114
|
-
*
|
|
115
|
-
* Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
|
|
116
|
-
*
|
|
117
|
-
* You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
|
|
118
|
-
*/
|
|
119
|
-
colors?: {
|
|
120
|
-
[key in CustomizableColors]?: key extends 'gray' ? {
|
|
121
|
-
[key in GrayColorKeys]?: string
|
|
122
|
-
} :{
|
|
123
|
-
[key in ColorKeys]?: string
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Add a link to the main logo
|
|
128
|
-
*/
|
|
129
|
-
logoHref?: string
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Setup file exporting a default function executed when setting up each story preview.
|
|
133
|
-
*
|
|
134
|
-
* Import custom CSS files from this file.
|
|
135
|
-
*
|
|
136
|
-
* Example: `'/src/histoire-setup.ts'`
|
|
137
|
-
*/
|
|
138
|
-
setupFile?: string
|
|
139
|
-
/**
|
|
140
|
-
* Setup code created by plugins
|
|
141
|
-
*/
|
|
142
|
-
setupCode?: string[]
|
|
143
|
-
/**
|
|
144
|
-
* Predefined responsive sizes for story playgrounds.
|
|
145
|
-
*/
|
|
146
|
-
responsivePresets?: ResponsivePreset[]
|
|
147
|
-
/**
|
|
148
|
-
* Background color of the story preview.
|
|
149
|
-
*/
|
|
150
|
-
backgroundPresets?: BackgroundPreset[]
|
|
151
|
-
/**
|
|
152
|
-
* Class added to the html root of the story preview when dark mode is enabled.
|
|
153
|
-
*/
|
|
154
|
-
sandboxDarkClass?: string
|
|
155
|
-
/**
|
|
156
|
-
* Customize the markdown-it renderer
|
|
157
|
-
*/
|
|
158
|
-
markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
|
|
159
|
-
/**
|
|
160
|
-
* Change the router mode.
|
|
161
|
-
* - history: use HTML history with cleaner URLs
|
|
162
|
-
* - hash: use hashtag hack in the URL to support more hosting services
|
|
163
|
-
*/
|
|
164
|
-
routerMode?: 'history' | 'hash'
|
|
165
|
-
/**
|
|
166
|
-
* Vite config override
|
|
167
|
-
*/
|
|
168
|
-
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
|
|
169
|
-
/**
|
|
170
|
-
* Transpile dependencies when collecting stories on Node.js
|
|
171
|
-
*/
|
|
172
|
-
viteNodeInlineDeps?: RegExp[]
|
|
173
|
-
/**
|
|
174
|
-
* Determine the transform method of modules
|
|
175
|
-
*/
|
|
176
|
-
viteNodeTransformMode?: {
|
|
177
|
-
/**
|
|
178
|
-
* Use SSR transform pipeline for the specified files.
|
|
179
|
-
* Vite plugins will receive `ssr: true` flag when processing those files.
|
|
180
|
-
*
|
|
181
|
-
* @default [/\.([cm]?[jt]sx?|json)$/]
|
|
182
|
-
*/
|
|
183
|
-
ssr?: RegExp[]
|
|
184
|
-
/**
|
|
185
|
-
* First do a normal transform pipeline (targeting browser),
|
|
186
|
-
* then then do a SSR rewrite to run the code in Node.
|
|
187
|
-
* Vite plugins will receive `ssr: false` flag when processing those files.
|
|
188
|
-
*
|
|
189
|
-
* @default other than `ssr`
|
|
190
|
-
*/
|
|
191
|
-
web?: RegExp[]
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export type ConfigMode = 'build' | 'dev'
|
|
196
|
-
|
|
197
22
|
export function getDefaultConfig (): HistoireConfig {
|
|
198
23
|
return {
|
|
199
24
|
plugins: [
|
package/src/node/context.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { resolveConfig as resolveViteConfig } from 'vite'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
ServerStoryFile,
|
|
4
|
+
FinalSupportPlugin,
|
|
5
|
+
ServerMarkdownFile,
|
|
6
|
+
HistoireConfig,
|
|
7
|
+
ConfigMode,
|
|
8
|
+
} from '@histoire/shared'
|
|
9
|
+
import { resolveConfig } from './config.js'
|
|
4
10
|
|
|
5
11
|
export interface Context {
|
|
6
12
|
root: string
|
package/src/node/index.ts
CHANGED
package/src/node/load.ts
CHANGED
|
@@ -3,18 +3,13 @@ import { ViteNodeServer } from 'vite-node/server'
|
|
|
3
3
|
import { ViteNodeRunner } from 'vite-node/client'
|
|
4
4
|
import pc from 'picocolors'
|
|
5
5
|
import { resolve } from 'pathe'
|
|
6
|
+
import type { ModuleLoader } from '@histoire/shared'
|
|
6
7
|
|
|
7
8
|
export interface UseModuleLoaderOptions {
|
|
8
9
|
server: ViteDevServer
|
|
9
10
|
throws?: boolean
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export interface ModuleLoader {
|
|
13
|
-
clearCache: () => void
|
|
14
|
-
loadModule: (file: string) => Promise<any>
|
|
15
|
-
destroy: () => void
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
let _load: ModuleLoader['loadModule']
|
|
19
14
|
|
|
20
15
|
export function useModuleLoader (options: UseModuleLoaderOptions): ModuleLoader {
|
package/src/node/plugin.ts
CHANGED
|
@@ -2,56 +2,20 @@ import chokidar from 'chokidar'
|
|
|
2
2
|
import path from 'pathe'
|
|
3
3
|
import fs from 'fs-extra'
|
|
4
4
|
import pc from 'picocolors'
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
Plugin,
|
|
7
|
+
PluginApiBase,
|
|
8
|
+
PluginApiDev,
|
|
9
|
+
PluginApiBuild,
|
|
10
|
+
BuildEndCallback,
|
|
11
|
+
PreviewStoryCallback,
|
|
12
|
+
ModuleLoader,
|
|
13
|
+
} from '@histoire/shared'
|
|
6
14
|
import { TEMP_PATH } from './alias.js'
|
|
7
|
-
import type { ConfigMode, HistoireConfig } from './config.js'
|
|
8
15
|
import type { Context } from './context.js'
|
|
9
|
-
import type { ModuleLoader } from './load.js'
|
|
10
16
|
import { addStory, removeStory } from './stories.js'
|
|
11
17
|
|
|
12
|
-
export
|
|
13
|
-
/**
|
|
14
|
-
* Name of the plugin
|
|
15
|
-
*/
|
|
16
|
-
name: string
|
|
17
|
-
/**
|
|
18
|
-
* Modify histoire default config. The hook can either mutate the passed config or
|
|
19
|
-
* return a partial config object that will be deeply merged into the existing
|
|
20
|
-
* config. User config will have higher priority than default config.
|
|
21
|
-
*
|
|
22
|
-
* Note: User plugins are resolved before running this hook so injecting other
|
|
23
|
-
* plugins inside the `config` hook will have no effect.
|
|
24
|
-
*/
|
|
25
|
-
defaultConfig?: (defaultConfig: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>
|
|
26
|
-
/**
|
|
27
|
-
* Modify histoire config. The hook can either mutate the passed config or
|
|
28
|
-
* return a partial config object that will be deeply merged into the existing
|
|
29
|
-
* config.
|
|
30
|
-
*
|
|
31
|
-
* Note: User plugins are resolved before running this hook so injecting other
|
|
32
|
-
* plugins inside the `config` hook will have no effect.
|
|
33
|
-
*/
|
|
34
|
-
config?: (config: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>
|
|
35
|
-
/**
|
|
36
|
-
* Use this hook to read and store the final resolved histoire config.
|
|
37
|
-
*/
|
|
38
|
-
configResolved?: (config: HistoireConfig) => void | Promise<void>
|
|
39
|
-
/**
|
|
40
|
-
* Use this hook to do processing during development. The `onCleanup` hook
|
|
41
|
-
* should handle cleanup tasks when development server is closed.
|
|
42
|
-
*/
|
|
43
|
-
onDev?: (api: DevPluginApi, onCleanup: (cb: () => void | Promise<void>) => void) => void | Promise<void>
|
|
44
|
-
/**
|
|
45
|
-
* Use this hook to do processing during production build.
|
|
46
|
-
*/
|
|
47
|
-
onBuild?: (api: BuildPluginApi) => void | Promise<void>
|
|
48
|
-
/**
|
|
49
|
-
* This plugin exposes a support plugin (example: Vue, Svelte, etc.)
|
|
50
|
-
*/
|
|
51
|
-
supportPlugin?: SupportPlugin
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class BasePluginApi {
|
|
18
|
+
export class BasePluginApi implements PluginApiBase {
|
|
55
19
|
colors = pc
|
|
56
20
|
path = path
|
|
57
21
|
fs = fs
|
|
@@ -85,14 +49,11 @@ export class BasePluginApi {
|
|
|
85
49
|
}
|
|
86
50
|
}
|
|
87
51
|
|
|
88
|
-
export class DevPluginApi extends BasePluginApi {
|
|
52
|
+
export class DevPluginApi extends BasePluginApi implements PluginApiDev {
|
|
89
53
|
watcher = chokidar
|
|
90
54
|
}
|
|
91
55
|
|
|
92
|
-
export
|
|
93
|
-
export type PreviewStoryCallback = (payload: { file: string, story: ServerStory, variant: ServerVariant, url: string }) => Promise<void> | void
|
|
94
|
-
|
|
95
|
-
export class BuildPluginApi extends BasePluginApi {
|
|
56
|
+
export class BuildPluginApi extends BasePluginApi implements PluginApiBuild {
|
|
96
57
|
buildEndCallbacks: BuildEndCallback[] = []
|
|
97
58
|
previewStoryCallbacks: PreviewStoryCallback[] = []
|
|
98
59
|
|
package/src/node/tree.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import pc from 'picocolors'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
ServerStoryFile,
|
|
4
|
+
ServerTree,
|
|
5
|
+
ServerTreeFile,
|
|
6
|
+
HistoireConfig,
|
|
7
|
+
TreeGroupConfig,
|
|
8
|
+
} from '@histoire/shared'
|
|
4
9
|
|
|
5
10
|
export function createPath (config: HistoireConfig, file: ServerTreeFile) {
|
|
6
11
|
if (config.tree.file === 'title') {
|
package/src/node/vite.ts
CHANGED
|
@@ -272,7 +272,7 @@ if (import.meta.hot) {
|
|
|
272
272
|
// List
|
|
273
273
|
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
274
274
|
// Setups
|
|
275
|
-
ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
275
|
+
...ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
276
276
|
for (const setup of setupList) {
|
|
277
277
|
if (setup?.${fnName}) {
|
|
278
278
|
await setup.${fnName}(payload)
|