histoire 0.9.6 → 0.10.2
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/dist/node/build.js +6 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +3 -7
- package/dist/node/builtin-plugins/vanilla-support/plugin.js +2 -2
- package/dist/node/collect/worker.js +8 -0
- package/dist/node/commands/dev.js +1 -1
- package/dist/node/config.d.ts +1 -0
- package/dist/node/config.js +20 -3
- package/dist/node/context.d.ts +2 -1
- package/dist/node/context.js +1 -0
- package/dist/node/markdown.d.ts +7 -0
- package/dist/node/markdown.js +129 -1
- package/dist/node/plugin.d.ts +9 -0
- package/dist/node/preview.js +1 -1
- package/dist/node/server.js +3 -0
- package/dist/node/stories.d.ts +1 -1
- package/dist/node/stories.js +5 -2
- package/dist/node/util/vendors.d.ts +1 -0
- package/dist/node/util/vendors.js +12 -0
- package/dist/node/vendors/controls.d.ts +1 -0
- package/dist/node/vendors/controls.js +1 -0
- package/dist/node/vendors/vue.d.ts +1 -0
- package/dist/node/vendors/vue.js +1 -0
- package/dist/node/vite.d.ts +2 -0
- package/dist/node/vite.js +32 -30
- package/package.json +9 -8
- package/src/node/build.ts +7 -0
- package/src/node/builtin-plugins/tailwind-tokens.ts +3 -9
- package/src/node/builtin-plugins/vanilla-support/plugin.ts +2 -2
- package/src/node/collect/worker.ts +9 -0
- package/src/node/commands/dev.ts +1 -1
- package/src/node/config.ts +23 -3
- package/src/node/context.ts +3 -1
- package/src/node/markdown.ts +148 -1
- package/src/node/plugin.ts +9 -0
- package/src/node/preview.ts +1 -1
- package/src/node/server.ts +4 -0
- package/src/node/stories.ts +5 -2
- package/src/node/util/vendors.ts +15 -0
- package/src/node/vendors/controls.ts +1 -0
- package/src/node/vendors/vue.ts +1 -0
- package/src/node/vite.ts +34 -31
package/dist/node/build.js
CHANGED
|
@@ -11,6 +11,7 @@ import { useCollectStories } from './collect/index.js';
|
|
|
11
11
|
import { BuildPluginApi } from './plugin.js';
|
|
12
12
|
import { useModuleLoader } from './load.js';
|
|
13
13
|
import { startPreview } from './preview.js';
|
|
14
|
+
import { createMarkdownFilesWatcher } from './markdown.js';
|
|
14
15
|
const PRELOAD_MODULES = [
|
|
15
16
|
'vendor',
|
|
16
17
|
];
|
|
@@ -22,6 +23,11 @@ const PREFETCHED_MODULES = [
|
|
|
22
23
|
export async function build(ctx) {
|
|
23
24
|
const startTime = performance.now();
|
|
24
25
|
await findAllStories(ctx);
|
|
26
|
+
// Scan for markdown files
|
|
27
|
+
{
|
|
28
|
+
const { stop } = await createMarkdownFilesWatcher(ctx);
|
|
29
|
+
await stop();
|
|
30
|
+
}
|
|
25
31
|
const resolvedViteConfig = await resolveViteConfig(ctx);
|
|
26
32
|
const server = await createViteServer(await getViteConfigWithPlugins(true, ctx));
|
|
27
33
|
await server.pluginContainer.buildStart({});
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getInjectedImport } from '../util/vendors.js';
|
|
2
2
|
import { findUp } from '../util/find-up.js';
|
|
3
|
-
const require = createRequire(import.meta.url);
|
|
4
|
-
function resolveImport(request) {
|
|
5
|
-
return JSON.stringify(require.resolve(request));
|
|
6
|
-
}
|
|
7
3
|
export function tailwindTokens(options = {}) {
|
|
8
4
|
const tailwindConfigFile = options.configFile ?? findUp(process.cwd(), [
|
|
9
5
|
'tailwind.config.js',
|
|
@@ -77,7 +73,7 @@ export function tailwindTokens(options = {}) {
|
|
|
77
73
|
}
|
|
78
74
|
const storyTemplate = (tailwindConfig) => `import 'histoire-style'
|
|
79
75
|
import './style.css'
|
|
80
|
-
import { createApp, h, markRaw, ref } from ${
|
|
76
|
+
import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
|
|
81
77
|
import {
|
|
82
78
|
HstColorShades,
|
|
83
79
|
HstTokenList,
|
|
@@ -85,7 +81,7 @@ import {
|
|
|
85
81
|
HstText,
|
|
86
82
|
HstTextarea,
|
|
87
83
|
HstNumber,
|
|
88
|
-
} from ${
|
|
84
|
+
} from ${getInjectedImport('@histoire/controls')}
|
|
89
85
|
|
|
90
86
|
const config = markRaw(${JSON.stringify(tailwindConfig, null, 2)})
|
|
91
87
|
const search = ref('')
|
|
@@ -4,7 +4,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
4
4
|
export function vanillaSupport() {
|
|
5
5
|
return {
|
|
6
6
|
name: 'builtin:vanilla-support',
|
|
7
|
-
|
|
7
|
+
defaultConfig() {
|
|
8
8
|
return {
|
|
9
9
|
supportMatch: [
|
|
10
10
|
{
|
|
@@ -19,7 +19,7 @@ export function vanillaSupport() {
|
|
|
19
19
|
id: 'vanilla',
|
|
20
20
|
moduleName: __dirname,
|
|
21
21
|
setupFn: 'setupVanilla',
|
|
22
|
-
importStoryComponent: (file, index) => `import Comp${index} from
|
|
22
|
+
importStoryComponent: (file, index) => `import Comp${index} from ${JSON.stringify(file.moduleId)}`, // @TODO code-splitting
|
|
23
23
|
},
|
|
24
24
|
// onDev (api) {
|
|
25
25
|
// // Test vanilla story
|
|
@@ -32,6 +32,14 @@ export default async (payload) => {
|
|
|
32
32
|
storyData,
|
|
33
33
|
el,
|
|
34
34
|
});
|
|
35
|
+
if (payload.storyFile.markdownFile) {
|
|
36
|
+
const el = document.createElement('div');
|
|
37
|
+
el.innerHTML = payload.storyFile.markdownFile.html;
|
|
38
|
+
const text = el.textContent;
|
|
39
|
+
storyData.forEach(s => {
|
|
40
|
+
s.docsText = text;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
35
43
|
destroyDomEnv();
|
|
36
44
|
return {
|
|
37
45
|
storyData,
|
|
@@ -9,7 +9,7 @@ export async function devCommand(options) {
|
|
|
9
9
|
const ctx = await createContext({
|
|
10
10
|
mode: 'dev',
|
|
11
11
|
});
|
|
12
|
-
const { server, close } = await createServer(ctx, options.port);
|
|
12
|
+
const { server, close } = await createServer(ctx, options.port ?? 6006);
|
|
13
13
|
server.printUrls();
|
|
14
14
|
// Histoire config watcher
|
|
15
15
|
let watcher;
|
package/dist/node/config.d.ts
CHANGED
|
@@ -274,6 +274,7 @@ export declare const mergeConfig: <Source extends {
|
|
|
274
274
|
} ? any : T_62 | T_60 : T_60 | T_62 : never : never : never : never; } : never : never : T_56 | T_54 : T_54 | T_56 : never : never : never : never; } : never : never : T_50 | T_48 : T_48 | T_50 : never : never : never : never; } : never : never : T_44 | T_42 : T_42 | T_44 : never : never : never : never; } : never : never : T_38 | T_36 : T_36 | T_38 : never : never : never : never; } : never : never : T_32 | T_30 : T_30 | T_32 : never : never : never : never; } : never : never : T_26 | T_24 : T_24 | T_26 : never : never : never : never; } : never : never : T_20 | T_18 : T_18 | T_20 : never : never : never : never; } : never : never : T_14 | T_12 : T_12 | T_14 : never : never : never : never; } : never : never : T_8 | T_6 : T_6 | T_8 : never : never : never : never; } : never : never : T_2 | T : T | T_2 : never : never : never : never; };
|
|
275
275
|
export declare function resolveConfig(cwd: string, mode: ConfigMode): Promise<HistoireConfig>;
|
|
276
276
|
export declare function processConfig(config: HistoireConfig, mode: ConfigMode): Promise<HistoireConfig>;
|
|
277
|
+
export declare function processDefaultConfig(defaultConfig: HistoireConfig, preUserConfig: HistoireConfig, mode: ConfigMode): Promise<HistoireConfig>;
|
|
277
278
|
export declare function defineConfig(config: Partial<HistoireConfig>): Partial<HistoireConfig>;
|
|
278
279
|
declare module 'vite' {
|
|
279
280
|
interface UserConfig {
|
package/dist/node/config.js
CHANGED
|
@@ -15,7 +15,10 @@ export function getDefaultConfig() {
|
|
|
15
15
|
tailwindTokens(),
|
|
16
16
|
],
|
|
17
17
|
outDir: '.histoire/dist',
|
|
18
|
-
storyMatch: [
|
|
18
|
+
storyMatch: [
|
|
19
|
+
'**/*.story.vue',
|
|
20
|
+
'**/*.story.svelte',
|
|
21
|
+
],
|
|
19
22
|
storyIgnored: [
|
|
20
23
|
'**/node_modules/**',
|
|
21
24
|
'**/dist/**',
|
|
@@ -103,7 +106,8 @@ export function getDefaultConfig() {
|
|
|
103
106
|
const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
|
|
104
107
|
typeof plugin[0] === 'object' &&
|
|
105
108
|
!Array.isArray(plugin[0]) &&
|
|
106
|
-
|
|
109
|
+
// @ts-expect-error could have no property 'name'
|
|
110
|
+
plugin[0].name?.startsWith('vite:legacy'));
|
|
107
111
|
if (index !== -1) {
|
|
108
112
|
config.plugins?.splice(index, 1);
|
|
109
113
|
}
|
|
@@ -215,7 +219,9 @@ export async function resolveConfig(cwd = process.cwd(), mode) {
|
|
|
215
219
|
}
|
|
216
220
|
const viteConfig = await resolveViteConfig({}, 'serve');
|
|
217
221
|
const viteHistoireConfig = (viteConfig.histoire ?? {});
|
|
218
|
-
|
|
222
|
+
const preUserConfig = mergeConfig(result, viteHistoireConfig);
|
|
223
|
+
const processedDefaultConfig = await processDefaultConfig(getDefaultConfig(), preUserConfig, mode);
|
|
224
|
+
return processConfig(mergeConfig(preUserConfig, processedDefaultConfig), mode);
|
|
219
225
|
}
|
|
220
226
|
export async function processConfig(config, mode) {
|
|
221
227
|
for (const plugin of config.plugins) {
|
|
@@ -229,6 +235,17 @@ export async function processConfig(config, mode) {
|
|
|
229
235
|
config.outDir = path.resolve(process.cwd(), config.outDir);
|
|
230
236
|
return config;
|
|
231
237
|
}
|
|
238
|
+
export async function processDefaultConfig(defaultConfig, preUserConfig, mode) {
|
|
239
|
+
for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins]) {
|
|
240
|
+
if (plugin.defaultConfig) {
|
|
241
|
+
const result = await plugin.defaultConfig(defaultConfig, mode);
|
|
242
|
+
if (result) {
|
|
243
|
+
defaultConfig = mergeConfig(result, defaultConfig);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return defaultConfig;
|
|
248
|
+
}
|
|
232
249
|
export function defineConfig(config) {
|
|
233
250
|
return config;
|
|
234
251
|
}
|
package/dist/node/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServerStoryFile, FinalSupportPlugin } from '@histoire/shared';
|
|
1
|
+
import type { ServerStoryFile, FinalSupportPlugin, ServerMarkdownFile } from '@histoire/shared';
|
|
2
2
|
import { HistoireConfig, ConfigMode } from './config.js';
|
|
3
3
|
export interface Context {
|
|
4
4
|
root: string;
|
|
@@ -6,6 +6,7 @@ export interface Context {
|
|
|
6
6
|
mode: ConfigMode;
|
|
7
7
|
storyFiles: ServerStoryFile[];
|
|
8
8
|
supportPlugins: FinalSupportPlugin[];
|
|
9
|
+
markdownFiles: ServerMarkdownFile[];
|
|
9
10
|
}
|
|
10
11
|
export interface CreateContextOptions {
|
|
11
12
|
mode: Context['mode'];
|
package/dist/node/context.js
CHANGED
package/dist/node/markdown.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
3
|
+
import type { Context } from './context.js';
|
|
2
4
|
export declare function createMarkdownRenderer(): Promise<MarkdownIt>;
|
|
5
|
+
export declare function createMarkdownPlugins(ctx: Context): Promise<VitePlugin[]>;
|
|
6
|
+
export declare function createMarkdownFilesWatcher(ctx: Context): Promise<{
|
|
7
|
+
stop: () => Promise<void>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare type MarkdownFilesWatcher = ReturnType<typeof createMarkdownFilesWatcher>;
|
package/dist/node/markdown.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import matter from 'gray-matter';
|
|
2
3
|
import shiki from 'shiki';
|
|
3
4
|
import anchor from 'markdown-it-anchor';
|
|
4
5
|
import attrs from 'markdown-it-attrs';
|
|
5
6
|
import emoji from 'markdown-it-emoji';
|
|
7
|
+
import chokidar from 'chokidar';
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import path from 'pathe';
|
|
6
10
|
import { slugify } from './util/slugify.js';
|
|
11
|
+
import { addStory, notifyStoryChange, removeStory } from './stories.js';
|
|
7
12
|
export async function createMarkdownRenderer() {
|
|
8
13
|
const highlighter = await shiki.getHighlighter({
|
|
9
14
|
theme: 'github-dark',
|
|
@@ -30,7 +35,7 @@ export async function createMarkdownRenderer() {
|
|
|
30
35
|
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
|
31
36
|
const hrefIndex = tokens[idx].attrIndex('href');
|
|
32
37
|
const classIndex = tokens[idx].attrIndex('class');
|
|
33
|
-
if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
|
|
38
|
+
if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && !tokens[idx].attrs[hrefIndex][1].startsWith('#') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
|
|
34
39
|
// If you are sure other plugins can't add `target` - drop check below
|
|
35
40
|
const aIndex = tokens[idx].attrIndex('target');
|
|
36
41
|
if (aIndex < 0) {
|
|
@@ -46,3 +51,126 @@ export async function createMarkdownRenderer() {
|
|
|
46
51
|
}
|
|
47
52
|
return md;
|
|
48
53
|
}
|
|
54
|
+
async function createMarkdownRendererWithPlugins(ctx) {
|
|
55
|
+
let md = await createMarkdownRenderer();
|
|
56
|
+
if (ctx.config.markdown) {
|
|
57
|
+
const result = await ctx.config.markdown(md);
|
|
58
|
+
if (result) {
|
|
59
|
+
md = result;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return md;
|
|
63
|
+
}
|
|
64
|
+
export async function createMarkdownPlugins(ctx) {
|
|
65
|
+
const plugins = [];
|
|
66
|
+
const md = await createMarkdownRendererWithPlugins(ctx);
|
|
67
|
+
// @TODO extract
|
|
68
|
+
plugins.push({
|
|
69
|
+
name: 'histoire-vue-docs-block',
|
|
70
|
+
transform(code, id) {
|
|
71
|
+
if (!id.includes('?vue&type=docs'))
|
|
72
|
+
return;
|
|
73
|
+
if (!id.includes('lang.md'))
|
|
74
|
+
return;
|
|
75
|
+
const html = md.render(code);
|
|
76
|
+
return `export default Comp => {
|
|
77
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
78
|
+
}`;
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
plugins.push({
|
|
82
|
+
name: 'histoire-markdown-files',
|
|
83
|
+
transform(code, id) {
|
|
84
|
+
if (id.endsWith('.story.md')) {
|
|
85
|
+
const relativePath = path.relative(ctx.root, id);
|
|
86
|
+
const { content, data: frontmatter } = matter(code);
|
|
87
|
+
const html = md.render(content);
|
|
88
|
+
return `export const html = ${JSON.stringify(html)}
|
|
89
|
+
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
90
|
+
export const relativePath = ${JSON.stringify(relativePath)}
|
|
91
|
+
|
|
92
|
+
if (import.meta.hot) {
|
|
93
|
+
import.meta.hot.accept(newModule => {
|
|
94
|
+
window.__hst_md_hmr(newModule)
|
|
95
|
+
})
|
|
96
|
+
}`;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
return plugins;
|
|
101
|
+
}
|
|
102
|
+
export async function createMarkdownFilesWatcher(ctx) {
|
|
103
|
+
const md = await createMarkdownRendererWithPlugins(ctx);
|
|
104
|
+
const watcher = chokidar.watch(['**/*.story.md'], {
|
|
105
|
+
cwd: ctx.root,
|
|
106
|
+
ignored: ctx.config.storyIgnored,
|
|
107
|
+
});
|
|
108
|
+
async function addFile(relativePath) {
|
|
109
|
+
const absolutePath = path.resolve(ctx.root, relativePath);
|
|
110
|
+
const dirFiles = await fs.readdir(path.dirname(absolutePath));
|
|
111
|
+
const truncatedName = path.basename(absolutePath, '.md');
|
|
112
|
+
const isRelatedToStory = dirFiles.some((file) => !file.endsWith('.md') && file.startsWith(truncatedName));
|
|
113
|
+
const { data: frontmatter, content } = matter(await fs.readFile(absolutePath, 'utf8'));
|
|
114
|
+
const html = md.render(content);
|
|
115
|
+
const file = {
|
|
116
|
+
relativePath,
|
|
117
|
+
absolutePath,
|
|
118
|
+
isRelatedToStory,
|
|
119
|
+
frontmatter,
|
|
120
|
+
html,
|
|
121
|
+
};
|
|
122
|
+
ctx.markdownFiles.push(file);
|
|
123
|
+
if (!isRelatedToStory) {
|
|
124
|
+
const storyRelativePath = relativePath.replace(/\.md$/, '.js');
|
|
125
|
+
const storyFile = addStory(storyRelativePath, `export default ${JSON.stringify({
|
|
126
|
+
id: frontmatter.id,
|
|
127
|
+
title: frontmatter.title,
|
|
128
|
+
icon: frontmatter.icon,
|
|
129
|
+
iconColor: frontmatter.iconColor,
|
|
130
|
+
group: frontmatter.group,
|
|
131
|
+
docsOnly: true,
|
|
132
|
+
variants: [],
|
|
133
|
+
})}`);
|
|
134
|
+
file.storyFile = storyFile;
|
|
135
|
+
storyFile.markdownFile = file;
|
|
136
|
+
notifyStoryChange(storyFile);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const searchPath = path.join(path.dirname(relativePath), truncatedName);
|
|
140
|
+
const storyFile = ctx.storyFiles.find(f => f.relativePath.startsWith(searchPath));
|
|
141
|
+
if (storyFile) {
|
|
142
|
+
file.storyFile = storyFile;
|
|
143
|
+
storyFile.markdownFile = file;
|
|
144
|
+
notifyStoryChange(storyFile);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return file;
|
|
148
|
+
}
|
|
149
|
+
function removeFile(relativePath) {
|
|
150
|
+
const index = ctx.markdownFiles.findIndex((file) => file.relativePath === relativePath);
|
|
151
|
+
if (index !== -1) {
|
|
152
|
+
const file = ctx.markdownFiles[index];
|
|
153
|
+
if (!file.isRelatedToStory) {
|
|
154
|
+
removeStory(file.storyFile.relativePath);
|
|
155
|
+
notifyStoryChange();
|
|
156
|
+
}
|
|
157
|
+
ctx.markdownFiles.splice(index, 1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function stop() {
|
|
161
|
+
await watcher.close();
|
|
162
|
+
}
|
|
163
|
+
watcher
|
|
164
|
+
.on('add', async (relativePath) => {
|
|
165
|
+
await addFile(relativePath);
|
|
166
|
+
})
|
|
167
|
+
.on('unlink', (relativePath) => {
|
|
168
|
+
removeFile(relativePath);
|
|
169
|
+
});
|
|
170
|
+
await new Promise(resolve => {
|
|
171
|
+
watcher.once('ready', resolve);
|
|
172
|
+
});
|
|
173
|
+
return {
|
|
174
|
+
stop,
|
|
175
|
+
};
|
|
176
|
+
}
|
package/dist/node/plugin.d.ts
CHANGED
|
@@ -10,6 +10,15 @@ export interface Plugin {
|
|
|
10
10
|
* Name of the plugin
|
|
11
11
|
*/
|
|
12
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>;
|
|
13
22
|
/**
|
|
14
23
|
* Modify histoire config. The hook can either mutate the passed config or
|
|
15
24
|
* return a partial config object that will be deeply merged into the existing
|
package/dist/node/preview.js
CHANGED
|
@@ -8,7 +8,7 @@ export async function startPreview(viteConfig, port, ctx) {
|
|
|
8
8
|
etag: true,
|
|
9
9
|
single: true,
|
|
10
10
|
}));
|
|
11
|
-
let finalPort = port ??
|
|
11
|
+
let finalPort = port ?? 6006;
|
|
12
12
|
const httpServer = http.createServer(app);
|
|
13
13
|
return new Promise((resolve, reject) => {
|
|
14
14
|
function onError(e) {
|
package/dist/node/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { useCollectStories } from './collect/index.js';
|
|
|
5
5
|
import { DevPluginApi } from './plugin.js';
|
|
6
6
|
import { useModuleLoader } from './load.js';
|
|
7
7
|
import { wrapLogError } from './util/log.js';
|
|
8
|
+
import { createMarkdownFilesWatcher } from './markdown.js';
|
|
8
9
|
export async function createServer(ctx, port) {
|
|
9
10
|
const server = await createViteServer(await getViteConfigWithPlugins(false, ctx));
|
|
10
11
|
await server.pluginContainer.buildStart({});
|
|
@@ -14,6 +15,7 @@ export async function createServer(ctx, port) {
|
|
|
14
15
|
server: nodeServer,
|
|
15
16
|
});
|
|
16
17
|
await watchStories(ctx);
|
|
18
|
+
const { stop: stopMdFileWatcher } = await createMarkdownFilesWatcher(ctx);
|
|
17
19
|
const pluginOnCleanups = [];
|
|
18
20
|
for (const plugin of ctx.config.plugins) {
|
|
19
21
|
if (plugin.onDev) {
|
|
@@ -125,6 +127,7 @@ export async function createServer(ctx, port) {
|
|
|
125
127
|
await wrapLogError('server.close', () => server.close());
|
|
126
128
|
await wrapLogError('nodeServer', () => nodeServer.close());
|
|
127
129
|
await wrapLogError('destroyCollectStories', () => destroyCollectStories());
|
|
130
|
+
await wrapLogError('stopMdFileWatcher', () => stopMdFileWatcher());
|
|
128
131
|
}
|
|
129
132
|
return {
|
|
130
133
|
server,
|
package/dist/node/stories.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare type StoryChangeHandler = (file?: ServerStoryFile) => unknown;
|
|
|
5
5
|
export declare function onStoryChange(handler: StoryChangeHandler): void;
|
|
6
6
|
export declare function watchStories(newContext: Context): Promise<chokidar.FSWatcher>;
|
|
7
7
|
export declare function notifyStoryChange(file?: ServerStoryFile): void;
|
|
8
|
-
export declare function addStory(relativeFilePath: string): ServerStoryFile;
|
|
8
|
+
export declare function addStory(relativeFilePath: string, virtualModuleCode?: string): ServerStoryFile;
|
|
9
9
|
export declare function removeStory(relativeFilePath: string): void;
|
|
10
10
|
export declare function findAllStories(newContext: Context): Promise<void>;
|
|
11
11
|
export {};
|
package/dist/node/stories.js
CHANGED
|
@@ -33,7 +33,7 @@ export function notifyStoryChange(file) {
|
|
|
33
33
|
function getAbsoluteFilePath(relativeFilePath) {
|
|
34
34
|
return resolve(context.root, relativeFilePath);
|
|
35
35
|
}
|
|
36
|
-
export function addStory(relativeFilePath) {
|
|
36
|
+
export function addStory(relativeFilePath, virtualModuleCode) {
|
|
37
37
|
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath);
|
|
38
38
|
const fileId = Case.kebab(relativeFilePath);
|
|
39
39
|
let fileName = basename(relativeFilePath);
|
|
@@ -55,9 +55,12 @@ export function addStory(relativeFilePath) {
|
|
|
55
55
|
const file = {
|
|
56
56
|
id: fileId,
|
|
57
57
|
path: absoluteFilePath,
|
|
58
|
+
relativePath: relativeFilePath,
|
|
58
59
|
fileName,
|
|
59
|
-
moduleId: absoluteFilePath,
|
|
60
|
+
moduleId: virtualModuleCode ? `virtual:story:${absoluteFilePath}` : absoluteFilePath,
|
|
60
61
|
supportPluginId,
|
|
62
|
+
virtual: !!virtualModuleCode,
|
|
63
|
+
moduleCode: virtualModuleCode,
|
|
61
64
|
};
|
|
62
65
|
context.storyFiles.push(file);
|
|
63
66
|
return file;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getInjectedImport(request: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// https://github.com/vitejs/vite/issues/9661
|
|
2
|
+
const alias = {
|
|
3
|
+
'@histoire/vendors/vue': 'histoire/dist/node/vendors/vue.js',
|
|
4
|
+
'@histoire/controls': 'histoire/dist/node/vendors/controls.js',
|
|
5
|
+
};
|
|
6
|
+
export function getInjectedImport(request) {
|
|
7
|
+
let id = request;
|
|
8
|
+
if (alias[id]) {
|
|
9
|
+
id = alias[id];
|
|
10
|
+
}
|
|
11
|
+
return JSON.stringify(id);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/controls';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/controls';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/vendors/vue';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/vendors/vue';
|
package/dist/node/vite.d.ts
CHANGED
|
@@ -20,5 +20,7 @@ export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins
|
|
|
20
20
|
export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
|
|
21
21
|
export declare const SUPPORT_PLUGINS_COLLECT = "virtual:$histoire-support-plugins-collect";
|
|
22
22
|
export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
|
|
23
|
+
export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
|
|
24
|
+
export declare const RESOLVED_MARKDOWN_FILES: string;
|
|
23
25
|
export declare function resolveViteConfig(ctx: Context): Promise<ResolvedConfig>;
|
|
24
26
|
export declare function getViteConfigWithPlugins(isServer: boolean, ctx: Context): Promise<InlineConfig>;
|
package/dist/node/vite.js
CHANGED
|
@@ -6,8 +6,9 @@ import { APP_PATH, TEMP_PATH } from './alias.js';
|
|
|
6
6
|
import { notifyStoryChange } from './stories.js';
|
|
7
7
|
import { makeTree } from './tree.js';
|
|
8
8
|
import { parseColor } from './colors.js';
|
|
9
|
-
import {
|
|
9
|
+
import { createMarkdownPlugins } from './markdown.js';
|
|
10
10
|
import { getSearchDataJS, generateDocSearchData, generateTitleSearchData } from './search.js';
|
|
11
|
+
import { getInjectedImport } from './util/vendors.js';
|
|
11
12
|
const require = createRequire(import.meta.url);
|
|
12
13
|
export const STORIES_ID = '$histoire-stories';
|
|
13
14
|
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
|
|
@@ -29,6 +30,8 @@ export const SUPPORT_PLUGINS_CLIENT = 'virtual:$histoire-support-plugins-client'
|
|
|
29
30
|
export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `\0${SUPPORT_PLUGINS_CLIENT}`;
|
|
30
31
|
export const SUPPORT_PLUGINS_COLLECT = 'virtual:$histoire-support-plugins-collect';
|
|
31
32
|
export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `\0${SUPPORT_PLUGINS_COLLECT}`;
|
|
33
|
+
export const MARKDOWN_FILES = 'virtual:$histoire-markdown-files';
|
|
34
|
+
export const RESOLVED_MARKDOWN_FILES = `\0${MARKDOWN_FILES}`;
|
|
32
35
|
export async function resolveViteConfig(ctx) {
|
|
33
36
|
const command = ctx.mode === 'dev' ? 'serve' : 'build';
|
|
34
37
|
let viteConfig = (await resolveViteConfigInternal({}, command));
|
|
@@ -80,11 +83,9 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
80
83
|
},
|
|
81
84
|
},
|
|
82
85
|
optimizeDeps: {
|
|
83
|
-
disabled: isServer,
|
|
84
86
|
entries: [
|
|
85
87
|
`${APP_PATH}/bundle-main.js`,
|
|
86
88
|
`${APP_PATH}/bundle-sandbox.js`,
|
|
87
|
-
// `${APP_PATH}/server/index.js`,
|
|
88
89
|
],
|
|
89
90
|
include: optimizeDeps([
|
|
90
91
|
'case',
|
|
@@ -96,7 +97,7 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
96
97
|
]),
|
|
97
98
|
exclude: [
|
|
98
99
|
'histoire',
|
|
99
|
-
'@histoire',
|
|
100
|
+
'@histoire/vendors',
|
|
100
101
|
],
|
|
101
102
|
},
|
|
102
103
|
server: {
|
|
@@ -118,6 +119,7 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
118
119
|
// Disable warnings
|
|
119
120
|
'process.env.NODE_ENV': JSON.stringify(isServer ? 'production' : process.env.NODE_ENV ?? 'development'),
|
|
120
121
|
},
|
|
122
|
+
cacheDir: isServer ? 'node_modules/.hst-vite-server' : 'node_modules/.hst-vite',
|
|
121
123
|
};
|
|
122
124
|
},
|
|
123
125
|
async resolveId(id, importer) {
|
|
@@ -159,6 +161,12 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
159
161
|
if (id.startsWith(SUPPORT_PLUGINS_COLLECT)) {
|
|
160
162
|
return RESOLVED_SUPPORT_PLUGINS_COLLECT;
|
|
161
163
|
}
|
|
164
|
+
if (id.startsWith(MARKDOWN_FILES)) {
|
|
165
|
+
return RESOLVED_MARKDOWN_FILES;
|
|
166
|
+
}
|
|
167
|
+
if (id.startsWith('virtual:story:')) {
|
|
168
|
+
return `\0${id}`;
|
|
169
|
+
}
|
|
162
170
|
},
|
|
163
171
|
async load(id) {
|
|
164
172
|
if (id === RESOLVED_STORIES_ID) {
|
|
@@ -167,6 +175,7 @@ export async function getViteConfigWithPlugins(isServer, ctx) {
|
|
|
167
175
|
return {
|
|
168
176
|
id: file.id,
|
|
169
177
|
path: file.treePath,
|
|
178
|
+
filePath: file.relativePath,
|
|
170
179
|
story: {
|
|
171
180
|
...file.story,
|
|
172
181
|
docsText: undefined,
|
|
@@ -271,6 +280,23 @@ if (import.meta.hot) {
|
|
|
271
280
|
${plugins.join(',\n ')}
|
|
272
281
|
}`;
|
|
273
282
|
}
|
|
283
|
+
if (id === RESOLVED_MARKDOWN_FILES) {
|
|
284
|
+
const filesJs = ctx.markdownFiles.map(f => `${JSON.stringify(f.relativePath)}: () => import(${JSON.stringify(`./${f.relativePath}`)})`).join(',');
|
|
285
|
+
return `import { reactive } from ${getInjectedImport('@histoire/vendors/vue')}
|
|
286
|
+
export const markdownFiles = reactive({${filesJs}})
|
|
287
|
+
if (import.meta.hot) {
|
|
288
|
+
window.__hst_md_hmr = (newModule) => {
|
|
289
|
+
markdownFiles[newModule.relativePath] = () => newModule
|
|
290
|
+
}
|
|
291
|
+
}`;
|
|
292
|
+
}
|
|
293
|
+
if (id.startsWith('\0virtual:story:')) {
|
|
294
|
+
const moduleId = id.replace('\0', '');
|
|
295
|
+
const storyFile = ctx.storyFiles.find(f => f.moduleId === moduleId && f.virtual);
|
|
296
|
+
if (storyFile) {
|
|
297
|
+
return storyFile.moduleCode;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
274
300
|
},
|
|
275
301
|
handleHotUpdate(updateContext) {
|
|
276
302
|
const story = ctx.storyFiles.find(file => file.path === updateContext.file);
|
|
@@ -350,8 +376,8 @@ if (import.meta.hot) {
|
|
|
350
376
|
};
|
|
351
377
|
},
|
|
352
378
|
});
|
|
353
|
-
//
|
|
354
|
-
plugins.push(...await
|
|
379
|
+
// Markdown
|
|
380
|
+
plugins.push(...await createMarkdownPlugins(ctx));
|
|
355
381
|
if (ctx.mode === 'build') {
|
|
356
382
|
// Add file name in build mode to have components names instead of <Anonymous>
|
|
357
383
|
const include = [/\.vue$/];
|
|
@@ -376,27 +402,3 @@ if (import.meta.hot) {
|
|
|
376
402
|
plugins,
|
|
377
403
|
});
|
|
378
404
|
}
|
|
379
|
-
async function createCustomBlocksPlugins(ctx) {
|
|
380
|
-
const plugins = [];
|
|
381
|
-
let md = await createMarkdownRenderer();
|
|
382
|
-
if (ctx.config.markdown) {
|
|
383
|
-
const result = await ctx.config.markdown(md);
|
|
384
|
-
if (result) {
|
|
385
|
-
md = result;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
plugins.push({
|
|
389
|
-
name: 'histoire-vue-docs-block',
|
|
390
|
-
transform(code, id) {
|
|
391
|
-
if (!id.includes('?vue&type=docs'))
|
|
392
|
-
return;
|
|
393
|
-
if (!id.includes('lang.md'))
|
|
394
|
-
return;
|
|
395
|
-
const html = md.render(code);
|
|
396
|
-
return `export default Comp => {
|
|
397
|
-
Comp.doc = ${JSON.stringify(html)}
|
|
398
|
-
}`;
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
return plugins;
|
|
402
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.2",
|
|
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.
|
|
33
|
-
"@histoire/controls": "^0.
|
|
34
|
-
"@histoire/shared": "^0.
|
|
35
|
-
"@histoire/vendors": "^0.
|
|
32
|
+
"@histoire/app": "^0.10.2",
|
|
33
|
+
"@histoire/controls": "^0.10.2",
|
|
34
|
+
"@histoire/shared": "^0.10.2",
|
|
35
|
+
"@histoire/vendors": "^0.10.2",
|
|
36
36
|
"@types/flexsearch": "^0.7.3",
|
|
37
37
|
"@types/markdown-it": "^12.2.3",
|
|
38
38
|
"birpc": "^0.1.1",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"flexsearch": "^0.7.21",
|
|
45
45
|
"fs-extra": "^10.0.1",
|
|
46
46
|
"globby": "^13.1.1",
|
|
47
|
+
"gray-matter": "^4.0.3",
|
|
47
48
|
"happy-dom": "^2.55.0",
|
|
48
49
|
"markdown-it": "^12.3.2",
|
|
49
50
|
"markdown-it-anchor": "^8.6.2",
|
|
@@ -57,10 +58,10 @@
|
|
|
57
58
|
"shiki": "0.10.1",
|
|
58
59
|
"sirv": "^2.0.2",
|
|
59
60
|
"tinypool": "^0.1.2",
|
|
60
|
-
"vite-node": "0.
|
|
61
|
+
"vite-node": "0.21.1"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
|
-
"vite": "^2.9.0"
|
|
64
|
+
"vite": "^2.9.0 || ^3.0.0"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@peeky/test": "^0.13.5",
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"@types/node": "^17.0.32",
|
|
71
72
|
"rollup": "^2.59.0",
|
|
72
73
|
"typescript": "^4.7.4",
|
|
73
|
-
"vite": "^
|
|
74
|
+
"vite": "^3.0.5"
|
|
74
75
|
},
|
|
75
76
|
"scripts": {
|
|
76
77
|
"build": "rimraf dist && tsc -d",
|
package/src/node/build.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { useCollectStories } from './collect/index.js'
|
|
|
20
20
|
import { BuildEndCallback, BuildPluginApi, PreviewStoryCallback } from './plugin.js'
|
|
21
21
|
import { useModuleLoader } from './load.js'
|
|
22
22
|
import { startPreview } from './preview.js'
|
|
23
|
+
import { createMarkdownFilesWatcher } from './markdown.js'
|
|
23
24
|
|
|
24
25
|
const PRELOAD_MODULES = [
|
|
25
26
|
'vendor',
|
|
@@ -35,6 +36,12 @@ export async function build (ctx: Context) {
|
|
|
35
36
|
const startTime = performance.now()
|
|
36
37
|
await findAllStories(ctx)
|
|
37
38
|
|
|
39
|
+
// Scan for markdown files
|
|
40
|
+
{
|
|
41
|
+
const { stop } = await createMarkdownFilesWatcher(ctx)
|
|
42
|
+
await stop()
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
const resolvedViteConfig = await resolveViteConfig(ctx)
|
|
39
46
|
|
|
40
47
|
const server = await createViteServer(await getViteConfigWithPlugins(true, ctx))
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { createRequire } from 'module'
|
|
2
1
|
import { BasePluginApi, Plugin } from '../plugin.js'
|
|
2
|
+
import { getInjectedImport } from '../util/vendors.js'
|
|
3
3
|
import { findUp } from '../util/find-up.js'
|
|
4
4
|
|
|
5
|
-
const require = createRequire(import.meta.url)
|
|
6
|
-
|
|
7
|
-
function resolveImport (request) {
|
|
8
|
-
return JSON.stringify(require.resolve(request))
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
export interface TailwindTokensOptions {
|
|
12
6
|
configFile?: string
|
|
13
7
|
}
|
|
@@ -90,7 +84,7 @@ export function tailwindTokens (options: TailwindTokensOptions = {}): Plugin {
|
|
|
90
84
|
|
|
91
85
|
const storyTemplate = (tailwindConfig: any) => `import 'histoire-style'
|
|
92
86
|
import './style.css'
|
|
93
|
-
import { createApp, h, markRaw, ref } from ${
|
|
87
|
+
import { createApp, h, markRaw, ref } from ${getInjectedImport('@histoire/vendors/vue')}
|
|
94
88
|
import {
|
|
95
89
|
HstColorShades,
|
|
96
90
|
HstTokenList,
|
|
@@ -98,7 +92,7 @@ import {
|
|
|
98
92
|
HstText,
|
|
99
93
|
HstTextarea,
|
|
100
94
|
HstNumber,
|
|
101
|
-
} from ${
|
|
95
|
+
} from ${getInjectedImport('@histoire/controls')}
|
|
102
96
|
|
|
103
97
|
const config = markRaw(${JSON.stringify(tailwindConfig, null, 2)})
|
|
104
98
|
const search = ref('')
|
|
@@ -8,7 +8,7 @@ export function vanillaSupport (): Plugin {
|
|
|
8
8
|
return {
|
|
9
9
|
name: 'builtin:vanilla-support',
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
defaultConfig () {
|
|
12
12
|
return {
|
|
13
13
|
supportMatch: [
|
|
14
14
|
{
|
|
@@ -24,7 +24,7 @@ export function vanillaSupport (): Plugin {
|
|
|
24
24
|
id: 'vanilla',
|
|
25
25
|
moduleName: __dirname,
|
|
26
26
|
setupFn: 'setupVanilla',
|
|
27
|
-
importStoryComponent: (file, index) => `import Comp${index} from
|
|
27
|
+
importStoryComponent: (file, index) => `import Comp${index} from ${JSON.stringify(file.moduleId)}`, // @TODO code-splitting
|
|
28
28
|
},
|
|
29
29
|
|
|
30
30
|
// onDev (api) {
|
|
@@ -56,6 +56,15 @@ export default async (payload: Payload): Promise<ReturnData> => {
|
|
|
56
56
|
el,
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
+
if (payload.storyFile.markdownFile) {
|
|
60
|
+
const el = document.createElement('div')
|
|
61
|
+
el.innerHTML = payload.storyFile.markdownFile.html
|
|
62
|
+
const text = el.textContent
|
|
63
|
+
storyData.forEach(s => {
|
|
64
|
+
s.docsText = text
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
59
68
|
destroyDomEnv()
|
|
60
69
|
|
|
61
70
|
return {
|
package/src/node/commands/dev.ts
CHANGED
|
@@ -15,7 +15,7 @@ export async function devCommand (options: DevOptions) {
|
|
|
15
15
|
const ctx = await createContext({
|
|
16
16
|
mode: 'dev',
|
|
17
17
|
})
|
|
18
|
-
const { server, close } = await createServer(ctx, options.port)
|
|
18
|
+
const { server, close } = await createServer(ctx, options.port ?? 6006)
|
|
19
19
|
server.printUrls()
|
|
20
20
|
|
|
21
21
|
// Histoire config watcher
|
package/src/node/config.ts
CHANGED
|
@@ -201,7 +201,10 @@ export function getDefaultConfig (): HistoireConfig {
|
|
|
201
201
|
tailwindTokens(),
|
|
202
202
|
],
|
|
203
203
|
outDir: '.histoire/dist',
|
|
204
|
-
storyMatch: [
|
|
204
|
+
storyMatch: [
|
|
205
|
+
'**/*.story.vue',
|
|
206
|
+
'**/*.story.svelte',
|
|
207
|
+
],
|
|
205
208
|
storyIgnored: [
|
|
206
209
|
'**/node_modules/**',
|
|
207
210
|
'**/dist/**',
|
|
@@ -289,7 +292,8 @@ export function getDefaultConfig (): HistoireConfig {
|
|
|
289
292
|
const index = config.plugins?.findIndex(plugin => Array.isArray(plugin) &&
|
|
290
293
|
typeof plugin[0] === 'object' &&
|
|
291
294
|
!Array.isArray(plugin[0]) &&
|
|
292
|
-
|
|
295
|
+
// @ts-expect-error could have no property 'name'
|
|
296
|
+
plugin[0].name?.startsWith('vite:legacy'))
|
|
293
297
|
if (index !== -1) {
|
|
294
298
|
config.plugins?.splice(index, 1)
|
|
295
299
|
}
|
|
@@ -408,7 +412,11 @@ export async function resolveConfig (cwd: string = process.cwd(), mode: ConfigMo
|
|
|
408
412
|
}
|
|
409
413
|
const viteConfig = await resolveViteConfig({}, 'serve')
|
|
410
414
|
const viteHistoireConfig = (viteConfig.histoire ?? {}) as HistoireConfig
|
|
411
|
-
|
|
415
|
+
|
|
416
|
+
const preUserConfig = mergeConfig(result, viteHistoireConfig)
|
|
417
|
+
const processedDefaultConfig = await processDefaultConfig(getDefaultConfig(), preUserConfig, mode)
|
|
418
|
+
|
|
419
|
+
return processConfig(mergeConfig(preUserConfig, processedDefaultConfig), mode)
|
|
412
420
|
}
|
|
413
421
|
|
|
414
422
|
export async function processConfig (config: HistoireConfig, mode: ConfigMode): Promise<HistoireConfig> {
|
|
@@ -424,6 +432,18 @@ export async function processConfig (config: HistoireConfig, mode: ConfigMode):
|
|
|
424
432
|
return config
|
|
425
433
|
}
|
|
426
434
|
|
|
435
|
+
export async function processDefaultConfig (defaultConfig: HistoireConfig, preUserConfig: HistoireConfig, mode: ConfigMode): Promise<HistoireConfig> {
|
|
436
|
+
for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins]) {
|
|
437
|
+
if (plugin.defaultConfig) {
|
|
438
|
+
const result = await plugin.defaultConfig(defaultConfig, mode)
|
|
439
|
+
if (result) {
|
|
440
|
+
defaultConfig = mergeConfig(result, defaultConfig)
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return defaultConfig
|
|
445
|
+
}
|
|
446
|
+
|
|
427
447
|
export function defineConfig (config: Partial<HistoireConfig>) {
|
|
428
448
|
return config
|
|
429
449
|
}
|
package/src/node/context.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveConfig as resolveViteConfig } from 'vite'
|
|
2
|
-
import type { ServerStoryFile, FinalSupportPlugin } from '@histoire/shared'
|
|
2
|
+
import type { ServerStoryFile, FinalSupportPlugin, ServerMarkdownFile } from '@histoire/shared'
|
|
3
3
|
import { resolveConfig, HistoireConfig, ConfigMode } from './config.js'
|
|
4
4
|
|
|
5
5
|
export interface Context {
|
|
@@ -8,6 +8,7 @@ export interface Context {
|
|
|
8
8
|
mode: ConfigMode
|
|
9
9
|
storyFiles: ServerStoryFile[]
|
|
10
10
|
supportPlugins: FinalSupportPlugin[]
|
|
11
|
+
markdownFiles: ServerMarkdownFile[]
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export interface CreateContextOptions {
|
|
@@ -26,5 +27,6 @@ export async function createContext (options: CreateContextOptions): Promise<Con
|
|
|
26
27
|
mode: options.mode,
|
|
27
28
|
storyFiles: [],
|
|
28
29
|
supportPlugins,
|
|
30
|
+
markdownFiles: [],
|
|
29
31
|
}
|
|
30
32
|
}
|
package/src/node/markdown.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it'
|
|
2
|
+
import matter from 'gray-matter'
|
|
2
3
|
import shiki from 'shiki'
|
|
3
4
|
import anchor from 'markdown-it-anchor'
|
|
4
5
|
import attrs from 'markdown-it-attrs'
|
|
5
6
|
import emoji from 'markdown-it-emoji'
|
|
7
|
+
import type { Plugin as VitePlugin } from 'vite'
|
|
8
|
+
import chokidar from 'chokidar'
|
|
9
|
+
import fs from 'fs-extra'
|
|
10
|
+
import path from 'pathe'
|
|
11
|
+
import type { ServerMarkdownFile } from '@histoire/shared'
|
|
6
12
|
import { slugify } from './util/slugify.js'
|
|
13
|
+
import type { Context } from './context.js'
|
|
14
|
+
import { addStory, notifyStoryChange, removeStory } from './stories.js'
|
|
7
15
|
|
|
8
16
|
export async function createMarkdownRenderer () {
|
|
9
17
|
const highlighter = await shiki.getHighlighter({
|
|
@@ -36,7 +44,7 @@ export async function createMarkdownRenderer () {
|
|
|
36
44
|
const hrefIndex = tokens[idx].attrIndex('href')
|
|
37
45
|
const classIndex = tokens[idx].attrIndex('class')
|
|
38
46
|
|
|
39
|
-
if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
|
|
47
|
+
if (hrefIndex >= 0 && !tokens[idx].attrs[hrefIndex][1].startsWith('/') && !tokens[idx].attrs[hrefIndex][1].startsWith('#') && (classIndex < 0 || !tokens[idx].attrs[classIndex][1].includes('header-anchor'))) {
|
|
40
48
|
// If you are sure other plugins can't add `target` - drop check below
|
|
41
49
|
const aIndex = tokens[idx].attrIndex('target')
|
|
42
50
|
|
|
@@ -54,3 +62,142 @@ export async function createMarkdownRenderer () {
|
|
|
54
62
|
|
|
55
63
|
return md
|
|
56
64
|
}
|
|
65
|
+
|
|
66
|
+
async function createMarkdownRendererWithPlugins (ctx: Context) {
|
|
67
|
+
let md = await createMarkdownRenderer()
|
|
68
|
+
if (ctx.config.markdown) {
|
|
69
|
+
const result = await ctx.config.markdown(md)
|
|
70
|
+
if (result) {
|
|
71
|
+
md = result
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return md
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function createMarkdownPlugins (ctx: Context) {
|
|
78
|
+
const plugins: VitePlugin[] = []
|
|
79
|
+
const md = await createMarkdownRendererWithPlugins(ctx)
|
|
80
|
+
|
|
81
|
+
// @TODO extract
|
|
82
|
+
plugins.push({
|
|
83
|
+
name: 'histoire-vue-docs-block',
|
|
84
|
+
transform (code, id) {
|
|
85
|
+
if (!id.includes('?vue&type=docs')) return
|
|
86
|
+
if (!id.includes('lang.md')) return
|
|
87
|
+
const html = md.render(code)
|
|
88
|
+
return `export default Comp => {
|
|
89
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
90
|
+
}`
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
plugins.push({
|
|
95
|
+
name: 'histoire-markdown-files',
|
|
96
|
+
transform (code, id) {
|
|
97
|
+
if (id.endsWith('.story.md')) {
|
|
98
|
+
const relativePath = path.relative(ctx.root, id)
|
|
99
|
+
const { content, data: frontmatter } = matter(code)
|
|
100
|
+
const html = md.render(content)
|
|
101
|
+
return `export const html = ${JSON.stringify(html)}
|
|
102
|
+
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
103
|
+
export const relativePath = ${JSON.stringify(relativePath)}
|
|
104
|
+
|
|
105
|
+
if (import.meta.hot) {
|
|
106
|
+
import.meta.hot.accept(newModule => {
|
|
107
|
+
window.__hst_md_hmr(newModule)
|
|
108
|
+
})
|
|
109
|
+
}`
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
return plugins
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function createMarkdownFilesWatcher (ctx: Context) {
|
|
118
|
+
const md = await createMarkdownRendererWithPlugins(ctx)
|
|
119
|
+
|
|
120
|
+
const watcher = chokidar.watch(['**/*.story.md'], {
|
|
121
|
+
cwd: ctx.root,
|
|
122
|
+
ignored: ctx.config.storyIgnored,
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
async function addFile (relativePath: string) {
|
|
126
|
+
const absolutePath = path.resolve(ctx.root, relativePath)
|
|
127
|
+
const dirFiles = await fs.readdir(path.dirname(absolutePath))
|
|
128
|
+
const truncatedName = path.basename(absolutePath, '.md')
|
|
129
|
+
const isRelatedToStory = dirFiles.some((file) => !file.endsWith('.md') && file.startsWith(truncatedName))
|
|
130
|
+
|
|
131
|
+
const { data: frontmatter, content } = matter(await fs.readFile(absolutePath, 'utf8'))
|
|
132
|
+
const html = md.render(content)
|
|
133
|
+
|
|
134
|
+
const file: ServerMarkdownFile = {
|
|
135
|
+
relativePath,
|
|
136
|
+
absolutePath,
|
|
137
|
+
isRelatedToStory,
|
|
138
|
+
frontmatter,
|
|
139
|
+
html,
|
|
140
|
+
}
|
|
141
|
+
ctx.markdownFiles.push(file)
|
|
142
|
+
|
|
143
|
+
if (!isRelatedToStory) {
|
|
144
|
+
const storyRelativePath = relativePath.replace(/\.md$/, '.js')
|
|
145
|
+
const storyFile = addStory(storyRelativePath, `export default ${JSON.stringify({
|
|
146
|
+
id: frontmatter.id,
|
|
147
|
+
title: frontmatter.title,
|
|
148
|
+
icon: frontmatter.icon,
|
|
149
|
+
iconColor: frontmatter.iconColor,
|
|
150
|
+
group: frontmatter.group,
|
|
151
|
+
docsOnly: true,
|
|
152
|
+
variants: [],
|
|
153
|
+
})}`)
|
|
154
|
+
file.storyFile = storyFile
|
|
155
|
+
storyFile.markdownFile = file
|
|
156
|
+
notifyStoryChange(storyFile)
|
|
157
|
+
} else {
|
|
158
|
+
const searchPath = path.join(path.dirname(relativePath), truncatedName)
|
|
159
|
+
const storyFile = ctx.storyFiles.find(f => f.relativePath.startsWith(searchPath))
|
|
160
|
+
if (storyFile) {
|
|
161
|
+
file.storyFile = storyFile
|
|
162
|
+
storyFile.markdownFile = file
|
|
163
|
+
notifyStoryChange(storyFile)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return file
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function removeFile (relativePath: string) {
|
|
171
|
+
const index = ctx.markdownFiles.findIndex((file) => file.relativePath === relativePath)
|
|
172
|
+
if (index !== -1) {
|
|
173
|
+
const file = ctx.markdownFiles[index]
|
|
174
|
+
if (!file.isRelatedToStory) {
|
|
175
|
+
removeStory(file.storyFile.relativePath)
|
|
176
|
+
notifyStoryChange()
|
|
177
|
+
}
|
|
178
|
+
ctx.markdownFiles.splice(index, 1)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function stop () {
|
|
183
|
+
await watcher.close()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
watcher
|
|
187
|
+
.on('add', async (relativePath) => {
|
|
188
|
+
await addFile(relativePath)
|
|
189
|
+
})
|
|
190
|
+
.on('unlink', (relativePath) => {
|
|
191
|
+
removeFile(relativePath)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
await new Promise(resolve => {
|
|
195
|
+
watcher.once('ready', resolve)
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
stop,
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type MarkdownFilesWatcher = ReturnType<typeof createMarkdownFilesWatcher>
|
package/src/node/plugin.ts
CHANGED
|
@@ -14,6 +14,15 @@ export interface Plugin {
|
|
|
14
14
|
* Name of the plugin
|
|
15
15
|
*/
|
|
16
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>
|
|
17
26
|
/**
|
|
18
27
|
* Modify histoire config. The hook can either mutate the passed config or
|
|
19
28
|
* return a partial config object that will be deeply merged into the existing
|
package/src/node/preview.ts
CHANGED
package/src/node/server.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { useCollectStories } from './collect/index.js'
|
|
|
7
7
|
import { DevPluginApi } from './plugin.js'
|
|
8
8
|
import { useModuleLoader } from './load.js'
|
|
9
9
|
import { wrapLogError } from './util/log.js'
|
|
10
|
+
import { createMarkdownFilesWatcher } from './markdown.js'
|
|
10
11
|
|
|
11
12
|
export async function createServer (ctx: Context, port: number) {
|
|
12
13
|
const server = await createViteServer(await getViteConfigWithPlugins(false, ctx))
|
|
@@ -21,6 +22,8 @@ export async function createServer (ctx: Context, port: number) {
|
|
|
21
22
|
|
|
22
23
|
await watchStories(ctx)
|
|
23
24
|
|
|
25
|
+
const { stop: stopMdFileWatcher } = await createMarkdownFilesWatcher(ctx)
|
|
26
|
+
|
|
24
27
|
const pluginOnCleanups: (() => void | Promise<void>)[] = []
|
|
25
28
|
for (const plugin of ctx.config.plugins) {
|
|
26
29
|
if (plugin.onDev) {
|
|
@@ -149,6 +152,7 @@ export async function createServer (ctx: Context, port: number) {
|
|
|
149
152
|
await wrapLogError('server.close', () => server.close())
|
|
150
153
|
await wrapLogError('nodeServer', () => nodeServer.close())
|
|
151
154
|
await wrapLogError('destroyCollectStories', () => destroyCollectStories())
|
|
155
|
+
await wrapLogError('stopMdFileWatcher', () => stopMdFileWatcher())
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
return {
|
package/src/node/stories.ts
CHANGED
|
@@ -45,7 +45,7 @@ function getAbsoluteFilePath (relativeFilePath: string) {
|
|
|
45
45
|
return resolve(context.root, relativeFilePath)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export function addStory (relativeFilePath: string) {
|
|
48
|
+
export function addStory (relativeFilePath: string, virtualModuleCode?: string) {
|
|
49
49
|
const absoluteFilePath = getAbsoluteFilePath(relativeFilePath)
|
|
50
50
|
const fileId = Case.kebab(relativeFilePath)
|
|
51
51
|
let fileName = basename(relativeFilePath)
|
|
@@ -71,9 +71,12 @@ export function addStory (relativeFilePath: string) {
|
|
|
71
71
|
const file: ServerStoryFile = {
|
|
72
72
|
id: fileId, // The file id will be changed by the story id after it is collected
|
|
73
73
|
path: absoluteFilePath,
|
|
74
|
+
relativePath: relativeFilePath,
|
|
74
75
|
fileName,
|
|
75
|
-
moduleId: absoluteFilePath,
|
|
76
|
+
moduleId: virtualModuleCode ? `virtual:story:${absoluteFilePath}` : absoluteFilePath,
|
|
76
77
|
supportPluginId,
|
|
78
|
+
virtual: !!virtualModuleCode,
|
|
79
|
+
moduleCode: virtualModuleCode,
|
|
77
80
|
}
|
|
78
81
|
context.storyFiles.push(file)
|
|
79
82
|
return file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// https://github.com/vitejs/vite/issues/9661
|
|
2
|
+
const alias = {
|
|
3
|
+
'@histoire/vendors/vue': 'histoire/dist/node/vendors/vue.js',
|
|
4
|
+
'@histoire/controls': 'histoire/dist/node/vendors/controls.js',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getInjectedImport (request: string) {
|
|
8
|
+
let id: string = request
|
|
9
|
+
|
|
10
|
+
if (alias[id]) {
|
|
11
|
+
id = alias[id]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return JSON.stringify(id)
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/controls'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@histoire/vendors/vue'
|
package/src/node/vite.ts
CHANGED
|
@@ -15,8 +15,9 @@ import { Context } from './context.js'
|
|
|
15
15
|
import { notifyStoryChange } from './stories.js'
|
|
16
16
|
import { makeTree } from './tree.js'
|
|
17
17
|
import { parseColor } from './colors.js'
|
|
18
|
-
import {
|
|
18
|
+
import { createMarkdownPlugins } from './markdown.js'
|
|
19
19
|
import { getSearchDataJS, generateDocSearchData, generateTitleSearchData } from './search.js'
|
|
20
|
+
import { getInjectedImport } from './util/vendors.js'
|
|
20
21
|
|
|
21
22
|
const require = createRequire(import.meta.url)
|
|
22
23
|
|
|
@@ -40,6 +41,8 @@ export const SUPPORT_PLUGINS_CLIENT = 'virtual:$histoire-support-plugins-client'
|
|
|
40
41
|
export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `\0${SUPPORT_PLUGINS_CLIENT}`
|
|
41
42
|
export const SUPPORT_PLUGINS_COLLECT = 'virtual:$histoire-support-plugins-collect'
|
|
42
43
|
export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `\0${SUPPORT_PLUGINS_COLLECT}`
|
|
44
|
+
export const MARKDOWN_FILES = 'virtual:$histoire-markdown-files'
|
|
45
|
+
export const RESOLVED_MARKDOWN_FILES = `\0${MARKDOWN_FILES}`
|
|
43
46
|
|
|
44
47
|
export async function resolveViteConfig (ctx: Context): Promise<ResolvedConfig> {
|
|
45
48
|
const command = ctx.mode === 'dev' ? 'serve' : 'build'
|
|
@@ -98,11 +101,9 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
98
101
|
},
|
|
99
102
|
},
|
|
100
103
|
optimizeDeps: {
|
|
101
|
-
disabled: isServer,
|
|
102
104
|
entries: [
|
|
103
105
|
`${APP_PATH}/bundle-main.js`,
|
|
104
106
|
`${APP_PATH}/bundle-sandbox.js`,
|
|
105
|
-
// `${APP_PATH}/server/index.js`,
|
|
106
107
|
],
|
|
107
108
|
include: optimizeDeps([
|
|
108
109
|
'case',
|
|
@@ -114,7 +115,7 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
114
115
|
]),
|
|
115
116
|
exclude: [
|
|
116
117
|
'histoire',
|
|
117
|
-
'@histoire',
|
|
118
|
+
'@histoire/vendors',
|
|
118
119
|
],
|
|
119
120
|
},
|
|
120
121
|
server: {
|
|
@@ -136,6 +137,7 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
136
137
|
// Disable warnings
|
|
137
138
|
'process.env.NODE_ENV': JSON.stringify(isServer ? 'production' : process.env.NODE_ENV ?? 'development'),
|
|
138
139
|
},
|
|
140
|
+
cacheDir: isServer ? 'node_modules/.hst-vite-server' : 'node_modules/.hst-vite',
|
|
139
141
|
}
|
|
140
142
|
},
|
|
141
143
|
|
|
@@ -177,6 +179,12 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
177
179
|
if (id.startsWith(SUPPORT_PLUGINS_COLLECT)) {
|
|
178
180
|
return RESOLVED_SUPPORT_PLUGINS_COLLECT
|
|
179
181
|
}
|
|
182
|
+
if (id.startsWith(MARKDOWN_FILES)) {
|
|
183
|
+
return RESOLVED_MARKDOWN_FILES
|
|
184
|
+
}
|
|
185
|
+
if (id.startsWith('virtual:story:')) {
|
|
186
|
+
return `\0${id}`
|
|
187
|
+
}
|
|
180
188
|
},
|
|
181
189
|
|
|
182
190
|
async load (id) {
|
|
@@ -186,6 +194,7 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context)
|
|
|
186
194
|
return {
|
|
187
195
|
id: file.id,
|
|
188
196
|
path: file.treePath,
|
|
197
|
+
filePath: file.relativePath,
|
|
189
198
|
story: {
|
|
190
199
|
...file.story,
|
|
191
200
|
docsText: undefined,
|
|
@@ -298,6 +307,25 @@ if (import.meta.hot) {
|
|
|
298
307
|
${plugins.join(',\n ')}
|
|
299
308
|
}`
|
|
300
309
|
}
|
|
310
|
+
|
|
311
|
+
if (id === RESOLVED_MARKDOWN_FILES) {
|
|
312
|
+
const filesJs = ctx.markdownFiles.map(f => `${JSON.stringify(f.relativePath)}: () => import(${JSON.stringify(`./${f.relativePath}`)})`).join(',')
|
|
313
|
+
return `import { reactive } from ${getInjectedImport('@histoire/vendors/vue')}
|
|
314
|
+
export const markdownFiles = reactive({${filesJs}})
|
|
315
|
+
if (import.meta.hot) {
|
|
316
|
+
window.__hst_md_hmr = (newModule) => {
|
|
317
|
+
markdownFiles[newModule.relativePath] = () => newModule
|
|
318
|
+
}
|
|
319
|
+
}`
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (id.startsWith('\0virtual:story:')) {
|
|
323
|
+
const moduleId = id.replace('\0', '')
|
|
324
|
+
const storyFile = ctx.storyFiles.find(f => f.moduleId === moduleId && f.virtual)
|
|
325
|
+
if (storyFile) {
|
|
326
|
+
return storyFile.moduleCode
|
|
327
|
+
}
|
|
328
|
+
}
|
|
301
329
|
},
|
|
302
330
|
|
|
303
331
|
handleHotUpdate (updateContext) {
|
|
@@ -383,8 +411,8 @@ if (import.meta.hot) {
|
|
|
383
411
|
},
|
|
384
412
|
})
|
|
385
413
|
|
|
386
|
-
//
|
|
387
|
-
plugins.push(...await
|
|
414
|
+
// Markdown
|
|
415
|
+
plugins.push(...await createMarkdownPlugins(ctx))
|
|
388
416
|
|
|
389
417
|
if (ctx.mode === 'build') {
|
|
390
418
|
// Add file name in build mode to have components names instead of <Anonymous>
|
|
@@ -411,28 +439,3 @@ if (import.meta.hot) {
|
|
|
411
439
|
plugins,
|
|
412
440
|
}) as InlineConfig
|
|
413
441
|
}
|
|
414
|
-
|
|
415
|
-
async function createCustomBlocksPlugins (ctx) {
|
|
416
|
-
const plugins: VitePlugin[] = []
|
|
417
|
-
|
|
418
|
-
let md = await createMarkdownRenderer()
|
|
419
|
-
if (ctx.config.markdown) {
|
|
420
|
-
const result = await ctx.config.markdown(md)
|
|
421
|
-
if (result) {
|
|
422
|
-
md = result
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
plugins.push({
|
|
426
|
-
name: 'histoire-vue-docs-block',
|
|
427
|
-
transform (code, id) {
|
|
428
|
-
if (!id.includes('?vue&type=docs')) return
|
|
429
|
-
if (!id.includes('lang.md')) return
|
|
430
|
-
const html = md.render(code)
|
|
431
|
-
return `export default Comp => {
|
|
432
|
-
Comp.doc = ${JSON.stringify(html)}
|
|
433
|
-
}`
|
|
434
|
-
},
|
|
435
|
-
})
|
|
436
|
-
|
|
437
|
-
return plugins
|
|
438
|
-
}
|