histoire 0.13.0 → 0.13.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/client.d.ts +3 -0
- package/dist/node/bin.js +1 -0
- package/dist/node/build-serialize.d.ts +21 -0
- package/dist/node/build-serialize.js +36 -0
- package/dist/node/build.js +19 -11
- package/dist/node/commands/dev.d.ts +1 -0
- package/dist/node/commands/dev.js +4 -1
- package/dist/node/config.js +2 -0
- package/dist/node/server.d.ts +1 -0
- package/dist/node/server.js +10 -6
- package/dist/node/virtual/index.d.ts +34 -0
- package/dist/node/virtual/index.js +46 -0
- package/dist/node/virtual/markdown.d.ts +2 -0
- package/dist/node/virtual/markdown.js +19 -0
- package/dist/node/virtual/noop.d.ts +1 -0
- package/dist/node/virtual/noop.js +1 -0
- package/dist/node/virtual/resolved-config.d.ts +2 -0
- package/dist/node/virtual/resolved-config.js +10 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +2 -0
- package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts +2 -0
- package/dist/node/virtual/resolved-markdown-files.js +17 -0
- package/dist/node/virtual/resolved-stories.d.ts +2 -0
- package/dist/node/virtual/resolved-stories.js +41 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +2 -0
- package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
- package/dist/node/virtual/resolved-theme.d.ts +2 -0
- package/dist/node/virtual/resolved-theme.js +12 -0
- package/dist/node/virtual/story-source.d.ts +2 -0
- package/dist/node/virtual/story-source.js +16 -0
- package/dist/node/virtual/story.d.ts +2 -0
- package/dist/node/virtual/story.js +7 -0
- package/dist/node/virtual/util.d.ts +2 -0
- package/dist/node/virtual/util.js +4 -0
- package/dist/node/virtual/vite-plugin.d.ts +3 -0
- package/dist/node/virtual/vite-plugin.js +118 -0
- package/dist/node/vite.d.ts +0 -22
- package/dist/node/vite.js +8 -280
- package/package.json +6 -6
- package/src/node/bin.ts +1 -0
- package/src/node/build-serialize.ts +62 -0
- package/src/node/build.ts +22 -11
- package/src/node/commands/dev.ts +5 -1
- package/src/node/config.ts +2 -0
- package/src/node/server.ts +13 -6
- package/src/node/virtual/index.ts +47 -0
- package/src/node/virtual/markdown.ts +21 -0
- package/src/node/virtual/noop.ts +1 -0
- package/src/node/virtual/resolved-config.ts +12 -0
- package/src/node/virtual/resolved-generated-global-setup.ts +24 -0
- package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
- package/src/node/virtual/resolved-markdown-files.ts +19 -0
- package/src/node/virtual/resolved-stories.ts +43 -0
- package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
- package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
- package/src/node/virtual/resolved-theme.ts +14 -0
- package/src/node/virtual/story-source.ts +17 -0
- package/src/node/virtual/story.ts +9 -0
- package/src/node/virtual/util.ts +5 -0
- package/src/node/virtual/vite-plugin.ts +135 -0
- package/src/node/vite.ts +9 -295
package/client.d.ts
CHANGED
|
@@ -14,3 +14,6 @@ export function logEvent (name: string, argument): void
|
|
|
14
14
|
* Returns `true` when in the NodeJS server while collecting stories.
|
|
15
15
|
*/
|
|
16
16
|
export function isCollecting (): boolean
|
|
17
|
+
|
|
18
|
+
export function toggleDark (value?: boolean): boolean
|
|
19
|
+
export function isDark (): boolean
|
package/dist/node/bin.js
CHANGED
|
@@ -11,6 +11,7 @@ program.version(version);
|
|
|
11
11
|
program.command('dev')
|
|
12
12
|
.describe('open the stories in your browser for development')
|
|
13
13
|
.option('-p, --port <port>', 'Listening port of the server')
|
|
14
|
+
.option('--open', 'Open in your default browser')
|
|
14
15
|
.action(async (options) => {
|
|
15
16
|
const { devCommand } = await import('./commands/dev.js');
|
|
16
17
|
return devCommand(options);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from './context.js';
|
|
2
|
+
import type { ServerStory } from '@histoire/shared';
|
|
3
|
+
interface SerializedStory extends Omit<ServerStory, 'docsText'> {
|
|
4
|
+
relativePath: string;
|
|
5
|
+
supportPluginId: string;
|
|
6
|
+
treePath?: string[];
|
|
7
|
+
virtual?: boolean;
|
|
8
|
+
markdownFile?: SerializedMarkdownFile;
|
|
9
|
+
}
|
|
10
|
+
interface SerializedMarkdownFile {
|
|
11
|
+
id: string;
|
|
12
|
+
relativePath: string;
|
|
13
|
+
isRelatedToStory: boolean;
|
|
14
|
+
frontmatter?: any;
|
|
15
|
+
}
|
|
16
|
+
interface SerializedStoryData {
|
|
17
|
+
stories: SerializedStory[];
|
|
18
|
+
markdownFiles: SerializedMarkdownFile[];
|
|
19
|
+
}
|
|
20
|
+
export declare function getSerializedStoryData(ctx: Context): SerializedStoryData;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function getSerializedStoryData(ctx) {
|
|
2
|
+
const data = {
|
|
3
|
+
stories: [],
|
|
4
|
+
markdownFiles: [],
|
|
5
|
+
};
|
|
6
|
+
for (const storyFile of ctx.storyFiles) {
|
|
7
|
+
if (storyFile.story) {
|
|
8
|
+
data.stories.push({
|
|
9
|
+
...Object.assign({}, storyFile.story, {
|
|
10
|
+
docsText: undefined,
|
|
11
|
+
}),
|
|
12
|
+
relativePath: storyFile.relativePath,
|
|
13
|
+
supportPluginId: storyFile.supportPluginId,
|
|
14
|
+
treePath: storyFile.treePath,
|
|
15
|
+
virtual: storyFile.virtual,
|
|
16
|
+
markdownFile: storyFile.markdownFile
|
|
17
|
+
? {
|
|
18
|
+
id: storyFile.markdownFile.id,
|
|
19
|
+
relativePath: storyFile.markdownFile.relativePath,
|
|
20
|
+
isRelatedToStory: storyFile.markdownFile.isRelatedToStory,
|
|
21
|
+
frontmatter: storyFile.markdownFile.frontmatter,
|
|
22
|
+
}
|
|
23
|
+
: null,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const markdownFile of ctx.markdownFiles) {
|
|
28
|
+
data.markdownFiles.push({
|
|
29
|
+
id: markdownFile.id,
|
|
30
|
+
relativePath: markdownFile.relativePath,
|
|
31
|
+
isRelatedToStory: markdownFile.isRelatedToStory,
|
|
32
|
+
frontmatter: markdownFile.frontmatter,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return data;
|
|
36
|
+
}
|
package/dist/node/build.js
CHANGED
|
@@ -12,6 +12,7 @@ import { BuildPluginApi } from './plugin.js';
|
|
|
12
12
|
import { useModuleLoader } from './load.js';
|
|
13
13
|
import { startPreview } from './preview.js';
|
|
14
14
|
import { createMarkdownFilesWatcher } from './markdown.js';
|
|
15
|
+
import { getSerializedStoryData } from './build-serialize.js';
|
|
15
16
|
const PRELOAD_MODULES = [
|
|
16
17
|
'vendor',
|
|
17
18
|
];
|
|
@@ -65,13 +66,6 @@ export async function build(ctx) {
|
|
|
65
66
|
join(APP_PATH, 'bundle-main.js'),
|
|
66
67
|
join(APP_PATH, 'bundle-sandbox.js'),
|
|
67
68
|
],
|
|
68
|
-
output: {
|
|
69
|
-
manualChunks(id) {
|
|
70
|
-
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
71
|
-
return 'vendor';
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
69
|
plugins: [
|
|
76
70
|
{
|
|
77
71
|
name: 'histoire-build-rollup-options-override',
|
|
@@ -83,10 +77,6 @@ export async function build(ctx) {
|
|
|
83
77
|
},
|
|
84
78
|
],
|
|
85
79
|
},
|
|
86
|
-
outDir: ctx.config.outDir,
|
|
87
|
-
emptyOutDir: true,
|
|
88
|
-
cssCodeSplit: false,
|
|
89
|
-
minify: false,
|
|
90
80
|
},
|
|
91
81
|
});
|
|
92
82
|
// For @vite/plugin-vue: Always put our vite server
|
|
@@ -122,6 +112,23 @@ export async function build(ctx) {
|
|
|
122
112
|
config(config) {
|
|
123
113
|
// Don't externalize
|
|
124
114
|
config.build.rollupOptions.external = [];
|
|
115
|
+
// Force chunk strategy
|
|
116
|
+
config.build.rollupOptions.output = {
|
|
117
|
+
manualChunks(id) {
|
|
118
|
+
if (!id.includes('@histoire/app') && id.includes('node_modules')) {
|
|
119
|
+
return 'vendor';
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
// Force vite build options
|
|
124
|
+
Object.assign(config.build, {
|
|
125
|
+
outDir: ctx.config.outDir,
|
|
126
|
+
emptyOutDir: true,
|
|
127
|
+
cssCodeSplit: false,
|
|
128
|
+
minify: false,
|
|
129
|
+
// Don't build in SSR mode
|
|
130
|
+
ssr: false,
|
|
131
|
+
});
|
|
125
132
|
},
|
|
126
133
|
});
|
|
127
134
|
const results = await viteBuild(buildViteConfig);
|
|
@@ -143,6 +150,7 @@ export async function build(ctx) {
|
|
|
143
150
|
const sandboxOutput = result.output.find(o => o.name === 'bundle-sandbox' && o.type === 'chunk');
|
|
144
151
|
const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx);
|
|
145
152
|
await writeFile('__sandbox.html', sandboxHtml, ctx);
|
|
153
|
+
await writeFile('histoire.json', JSON.stringify(getSerializedStoryData(ctx), null, 2), ctx);
|
|
146
154
|
const duration = performance.now() - startTime;
|
|
147
155
|
if (emptyStoryCount) {
|
|
148
156
|
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
|
|
@@ -9,7 +9,10 @@ export async function devCommand(options) {
|
|
|
9
9
|
const ctx = await createContext({
|
|
10
10
|
mode: 'dev',
|
|
11
11
|
});
|
|
12
|
-
const { server, viteConfigFile, close } = await createServer(ctx, {
|
|
12
|
+
const { server, viteConfigFile, close } = await createServer(ctx, {
|
|
13
|
+
port: options.port,
|
|
14
|
+
open: options.open,
|
|
15
|
+
});
|
|
13
16
|
server.printUrls();
|
|
14
17
|
// Histoire config watcher
|
|
15
18
|
let watcher;
|
package/dist/node/config.js
CHANGED
package/dist/node/server.d.ts
CHANGED
package/dist/node/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { createServer as createViteServer } from 'vite';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
|
-
import { getViteConfigWithPlugins
|
|
4
|
+
import { getViteConfigWithPlugins } from './vite.js';
|
|
5
|
+
import * as VirtualFiles from './virtual/index.js';
|
|
5
6
|
import { onStoryChange, onStoryListChange, watchStories } from './stories.js';
|
|
6
7
|
import { useCollectStories } from './collect/index.js';
|
|
7
8
|
import { DevPluginApi } from './plugin.js';
|
|
@@ -11,6 +12,9 @@ import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js'
|
|
|
11
12
|
export async function createServer(ctx, options = {}) {
|
|
12
13
|
const getViteServer = async (collecting) => {
|
|
13
14
|
const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx);
|
|
15
|
+
if (!collecting && options.open) {
|
|
16
|
+
viteConfig.server.open = true;
|
|
17
|
+
}
|
|
14
18
|
const server = await createViteServer(viteConfig);
|
|
15
19
|
await server.pluginContainer.buildStart({});
|
|
16
20
|
return {
|
|
@@ -135,19 +139,19 @@ export async function createServer(ctx, options = {}) {
|
|
|
135
139
|
}
|
|
136
140
|
console.log(`Collect stories end ${pc.bold(pc.blue(Math.round(performance.now() - time)))}ms`);
|
|
137
141
|
clearInvalidates();
|
|
138
|
-
invalidateModule(RESOLVED_STORIES_ID);
|
|
139
|
-
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
142
|
+
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
|
|
143
|
+
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
140
144
|
collecting = false;
|
|
141
145
|
if (queued) {
|
|
142
146
|
await collect();
|
|
143
147
|
}
|
|
144
148
|
}
|
|
145
149
|
onStoryListChange(() => {
|
|
146
|
-
invalidateModule(RESOLVED_STORIES_ID);
|
|
147
|
-
invalidateModule(RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
150
|
+
invalidateModule(VirtualFiles.RESOLVED_STORIES_ID);
|
|
151
|
+
invalidateModule(VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID);
|
|
148
152
|
});
|
|
149
153
|
onMarkdownListChange(() => {
|
|
150
|
-
invalidateModule(RESOLVED_MARKDOWN_FILES);
|
|
154
|
+
invalidateModule(VirtualFiles.RESOLVED_MARKDOWN_FILES);
|
|
151
155
|
});
|
|
152
156
|
async function close() {
|
|
153
157
|
for (const cb of pluginOnCleanups) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const STORIES_ID = "virtual:$histoire-stories";
|
|
2
|
+
export declare const RESOLVED_STORIES_ID: string;
|
|
3
|
+
export declare const SETUP_ID = "virtual:$histoire-setup";
|
|
4
|
+
export declare const NOOP_ID = "virtual:$histoire-noop";
|
|
5
|
+
export declare const CONFIG_ID = "virtual:$histoire-config";
|
|
6
|
+
export declare const RESOLVED_CONFIG_ID: string;
|
|
7
|
+
export declare const THEME_ID = "virtual:$histoire-theme";
|
|
8
|
+
export declare const RESOLVED_THEME_ID: string;
|
|
9
|
+
export declare const SEARCH_TITLE_DATA_ID = "virtual:$histoire-search-title-data";
|
|
10
|
+
export declare const RESOLVED_SEARCH_TITLE_DATA_ID: string;
|
|
11
|
+
export declare const SEARCH_DOCS_DATA_ID = "virtual:$histoire-search-docs-data";
|
|
12
|
+
export declare const RESOLVED_SEARCH_DOCS_DATA_ID: string;
|
|
13
|
+
export declare const GENERATED_GLOBAL_SETUP = "virtual:$histoire-generated-global-setup";
|
|
14
|
+
export declare const RESOLVED_GENERATED_GLOBAL_SETUP: string;
|
|
15
|
+
export declare const GENERATED_SETUP_CODE = "virtual:$histoire-generated-setup-code";
|
|
16
|
+
export declare const RESOLVED_GENERATED_SETUP_CODE: string;
|
|
17
|
+
export declare const SUPPORT_PLUGINS_CLIENT = "virtual:$histoire-support-plugins-client";
|
|
18
|
+
export declare const RESOLVED_SUPPORT_PLUGINS_CLIENT: string;
|
|
19
|
+
export declare const SUPPORT_PLUGINS_COLLECT = "virtual:$histoire-support-plugins-collect";
|
|
20
|
+
export declare const RESOLVED_SUPPORT_PLUGINS_COLLECT: string;
|
|
21
|
+
export declare const MARKDOWN_FILES = "virtual:$histoire-markdown-files";
|
|
22
|
+
export declare const RESOLVED_MARKDOWN_FILES: string;
|
|
23
|
+
export * from './markdown.js';
|
|
24
|
+
export * from './noop.js';
|
|
25
|
+
export * from './resolved-config.js';
|
|
26
|
+
export * from './resolved-generated-global-setup.js';
|
|
27
|
+
export * from './resolved-generated-setup-code.js';
|
|
28
|
+
export * from './resolved-markdown-files.js';
|
|
29
|
+
export * from './resolved-stories.js';
|
|
30
|
+
export * from './resolved-support-plugins-client.js';
|
|
31
|
+
export * from './resolved-support-plugins-collect.js';
|
|
32
|
+
export * from './resolved-theme.js';
|
|
33
|
+
export * from './story.js';
|
|
34
|
+
export * from './story-source.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// @TODO wait for virtual modules HMR to work in vite to use `virtual:` and `\0` prefix
|
|
2
|
+
// https://github.com/vitejs/vite/pull/10313
|
|
3
|
+
export const STORIES_ID = 'virtual:$histoire-stories';
|
|
4
|
+
export const RESOLVED_STORIES_ID = `/__resolved__${STORIES_ID}`;
|
|
5
|
+
// export const RESOLVED_STORIES_ID = `\0${STORIES_ID}`
|
|
6
|
+
export const SETUP_ID = 'virtual:$histoire-setup';
|
|
7
|
+
export const NOOP_ID = 'virtual:$histoire-noop';
|
|
8
|
+
export const CONFIG_ID = 'virtual:$histoire-config';
|
|
9
|
+
export const RESOLVED_CONFIG_ID = `/__resolved__${CONFIG_ID}`;
|
|
10
|
+
// export const RESOLVED_CONFIG_ID = `\0${CONFIG_ID}`
|
|
11
|
+
export const THEME_ID = 'virtual:$histoire-theme';
|
|
12
|
+
export const RESOLVED_THEME_ID = `/__resolved__${THEME_ID}.css`;
|
|
13
|
+
// export const RESOLVED_THEME_ID = `\0${THEME_ID}.css`
|
|
14
|
+
export const SEARCH_TITLE_DATA_ID = 'virtual:$histoire-search-title-data';
|
|
15
|
+
export const RESOLVED_SEARCH_TITLE_DATA_ID = `/__resolved__${SEARCH_TITLE_DATA_ID}`;
|
|
16
|
+
// export const RESOLVED_SEARCH_TITLE_DATA_ID = `\0${SEARCH_TITLE_DATA_ID}`
|
|
17
|
+
export const SEARCH_DOCS_DATA_ID = 'virtual:$histoire-search-docs-data';
|
|
18
|
+
export const RESOLVED_SEARCH_DOCS_DATA_ID = `/__resolved__${SEARCH_DOCS_DATA_ID}`;
|
|
19
|
+
// export const RESOLVED_SEARCH_DOCS_DATA_ID = `\0${SEARCH_DOCS_DATA_ID}`
|
|
20
|
+
export const GENERATED_GLOBAL_SETUP = 'virtual:$histoire-generated-global-setup';
|
|
21
|
+
export const RESOLVED_GENERATED_GLOBAL_SETUP = `/__resolved__${GENERATED_GLOBAL_SETUP}`;
|
|
22
|
+
// export const RESOLVED_GENERATED_GLOBAL_SETUP = `\0${GENERATED_GLOBAL_SETUP}`
|
|
23
|
+
export const GENERATED_SETUP_CODE = 'virtual:$histoire-generated-setup-code';
|
|
24
|
+
export const RESOLVED_GENERATED_SETUP_CODE = `/__resolved__${GENERATED_SETUP_CODE}`;
|
|
25
|
+
// export const RESOLVED_GENERATED_SETUP_CODE = `\0${GENERATED_SETUP_CODE}`
|
|
26
|
+
export const SUPPORT_PLUGINS_CLIENT = 'virtual:$histoire-support-plugins-client';
|
|
27
|
+
export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `/__resolved__${SUPPORT_PLUGINS_CLIENT}`;
|
|
28
|
+
// export const RESOLVED_SUPPORT_PLUGINS_CLIENT = `\0${SUPPORT_PLUGINS_CLIENT}`
|
|
29
|
+
export const SUPPORT_PLUGINS_COLLECT = 'virtual:$histoire-support-plugins-collect';
|
|
30
|
+
export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `/__resolved__${SUPPORT_PLUGINS_COLLECT}`;
|
|
31
|
+
// export const RESOLVED_SUPPORT_PLUGINS_COLLECT = `\0${SUPPORT_PLUGINS_COLLECT}`
|
|
32
|
+
export const MARKDOWN_FILES = 'virtual:$histoire-markdown-files';
|
|
33
|
+
export const RESOLVED_MARKDOWN_FILES = `/__resolved__${MARKDOWN_FILES}`;
|
|
34
|
+
// export const RESOLVED_MARKDOWN_FILES = `\0${MARKDOWN_FILES}`
|
|
35
|
+
export * from './markdown.js';
|
|
36
|
+
export * from './noop.js';
|
|
37
|
+
export * from './resolved-config.js';
|
|
38
|
+
export * from './resolved-generated-global-setup.js';
|
|
39
|
+
export * from './resolved-generated-setup-code.js';
|
|
40
|
+
export * from './resolved-markdown-files.js';
|
|
41
|
+
export * from './resolved-stories.js';
|
|
42
|
+
export * from './resolved-support-plugins-client.js';
|
|
43
|
+
export * from './resolved-support-plugins-collect.js';
|
|
44
|
+
export * from './resolved-theme.js';
|
|
45
|
+
export * from './story.js';
|
|
46
|
+
export * from './story-source.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const markdown = (ctx, id) => {
|
|
2
|
+
const fileId = id.slice('/__resolved__virtual:md:'.length);
|
|
3
|
+
const file = ctx.markdownFiles.find(f => f.id === fileId);
|
|
4
|
+
if (!file) {
|
|
5
|
+
throw new Error(`Markdown file not found: ${fileId}`);
|
|
6
|
+
}
|
|
7
|
+
const { html, frontmatter, relativePath } = file;
|
|
8
|
+
return `export const html = ${JSON.stringify(html)}
|
|
9
|
+
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
10
|
+
export const relativePath = ${JSON.stringify(relativePath)}
|
|
11
|
+
|
|
12
|
+
if (import.meta.hot) {
|
|
13
|
+
import.meta.hot.accept(newModule => {
|
|
14
|
+
if (newModule) {
|
|
15
|
+
window.__hst_md_hmr(newModule)
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
}`;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noop: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noop = () => `export default () => {}`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const resolvedConfig = (ctx) => {
|
|
2
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
|
|
3
|
+
if (ctx.config.theme?.logo) {
|
|
4
|
+
for (const key in ctx.config.theme.logo) {
|
|
5
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
|
|
9
|
+
return js;
|
|
10
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GENERATED_SETUP_CODE } from './index.js';
|
|
2
|
+
import { ID_SEPARATOR } from './util.js';
|
|
3
|
+
export const resolvedGeneratedGlobalSetup = (ctx) => {
|
|
4
|
+
if (ctx.config.setupCode) {
|
|
5
|
+
return [
|
|
6
|
+
// Import
|
|
7
|
+
`${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}'`).join('\n')}`,
|
|
8
|
+
// List
|
|
9
|
+
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
10
|
+
// Setups
|
|
11
|
+
...ctx.supportPlugins.map(p => p.setupFn).map(fnName => `export async function ${fnName} (payload) {
|
|
12
|
+
for (const setup of setupList) {
|
|
13
|
+
if (setup?.${fnName}) {
|
|
14
|
+
await setup.${fnName}(payload)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}`),
|
|
18
|
+
].join('\n');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getInjectedImport } from '../util/vendors.js';
|
|
2
|
+
export const resolvedMarkdownFiles = (ctx) => {
|
|
3
|
+
const filesJs = ctx.markdownFiles.map(f => `${JSON.stringify(f.relativePath)}: () => import(${JSON.stringify(`virtual:md:${f.id}`)})`).join(',');
|
|
4
|
+
return `import { reactive } from ${process.env.HISTOIRE_DEV ? `'vue'` : getInjectedImport('@histoire/vendors/vue')}
|
|
5
|
+
export const markdownFiles = reactive({${filesJs}})
|
|
6
|
+
if (import.meta.hot) {
|
|
7
|
+
if (!window.__hst_md_hmr) {
|
|
8
|
+
window.__hst_md_hmr = (newModule) => {
|
|
9
|
+
markdownFiles[newModule.relativePath] = () => newModule
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
import.meta.hot.accept(newModule => {
|
|
14
|
+
Object.assign(markdownFiles, newModule.markdownFiles)
|
|
15
|
+
})
|
|
16
|
+
}`;
|
|
17
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { makeTree } from '../tree.js';
|
|
2
|
+
export const resolvedStories = (ctx) => {
|
|
3
|
+
const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
|
|
4
|
+
const files = resolvedStories.map((file, index) => {
|
|
5
|
+
return {
|
|
6
|
+
id: file.id,
|
|
7
|
+
path: file.treePath,
|
|
8
|
+
filePath: file.relativePath,
|
|
9
|
+
story: {
|
|
10
|
+
...file.story,
|
|
11
|
+
docsText: undefined,
|
|
12
|
+
},
|
|
13
|
+
supportPluginId: file.supportPluginId,
|
|
14
|
+
index,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
return `${ctx.supportPlugins.map(p => p.importStoriesPrepend).filter(Boolean).join('\n')}
|
|
18
|
+
${resolvedStories.map((file, index) => {
|
|
19
|
+
const supportPlugin = ctx.supportPlugins.find(p => p.id === file.supportPluginId);
|
|
20
|
+
if (!supportPlugin) {
|
|
21
|
+
throw new Error(`Could not find support plugin for story ${file.path}: ${file.supportPluginId}`);
|
|
22
|
+
}
|
|
23
|
+
return supportPlugin.importStoryComponent(file, index);
|
|
24
|
+
}).filter(Boolean).join('\n')}
|
|
25
|
+
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}, source: () => import('virtual:story-source:${file.story.id}')}`).join(',\n')}]
|
|
26
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
27
|
+
const handlers = []
|
|
28
|
+
export function onUpdate (cb) {
|
|
29
|
+
handlers.push(cb)
|
|
30
|
+
}
|
|
31
|
+
if (import.meta.hot) {
|
|
32
|
+
import.meta.hot.accept(newModule => {
|
|
33
|
+
files = newModule.files
|
|
34
|
+
tree = newModule.tree
|
|
35
|
+
handlers.forEach(h => {
|
|
36
|
+
h(newModule.files, newModule.tree)
|
|
37
|
+
newModule.onUpdate(h)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
}`;
|
|
41
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { PLUGINS_HAVE_DEV } from './util.js';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
export const resolvedSupportPluginsClient = (ctx) => {
|
|
5
|
+
const plugins = ctx.supportPlugins.map(p => `'${p.id}': () => import(${JSON.stringify(require.resolve(`${p.moduleName}/client${process.env.HISTOIRE_DEV && PLUGINS_HAVE_DEV.includes(p.moduleName) ? '-dev' : ''}`, {
|
|
6
|
+
paths: [ctx.root, import.meta.url],
|
|
7
|
+
}))})`);
|
|
8
|
+
return `export const clientSupportPlugins = {
|
|
9
|
+
${plugins.join(',\n ')}
|
|
10
|
+
}`;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { PLUGINS_HAVE_DEV } from './util.js';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
export const resolvedSupportPluginsCollect = (ctx) => {
|
|
5
|
+
const plugins = ctx.supportPlugins.map(p => `'${p.id}': () => import(${JSON.stringify(require.resolve(`${p.moduleName}/collect${process.env.HISTOIRE_DEV && PLUGINS_HAVE_DEV.includes(p.moduleName) ? '-dev' : ''}`, {
|
|
6
|
+
paths: [ctx.root, import.meta.url],
|
|
7
|
+
}))})`);
|
|
8
|
+
return `export const collectSupportPlugins = {
|
|
9
|
+
${plugins.join(',\n ')}
|
|
10
|
+
}`;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseColor } from '../colors.js';
|
|
2
|
+
export const resolvedTheme = (ctx) => {
|
|
3
|
+
let css = '*, ::before, ::after {';
|
|
4
|
+
// Colors
|
|
5
|
+
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
6
|
+
for (const key in ctx.config.theme.colors[color]) {
|
|
7
|
+
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
css += '}';
|
|
11
|
+
return css;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
export const storySource = async (ctx, id) => {
|
|
4
|
+
const storyId = id.slice('/__resolved__virtual:story-source:'.length);
|
|
5
|
+
const storyFile = ctx.storyFiles.find(f => f.story?.id === storyId);
|
|
6
|
+
if (storyFile) {
|
|
7
|
+
let source;
|
|
8
|
+
if (storyFile.virtual) {
|
|
9
|
+
source = storyFile.moduleCode;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
source = await fs.readFile(resolve(ctx.root, storyFile.relativePath), 'utf-8');
|
|
13
|
+
}
|
|
14
|
+
return `export default ${JSON.stringify(source)}`;
|
|
15
|
+
}
|
|
16
|
+
};
|