histoire 0.2.3 → 0.3.0
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/client/app/App.vue +9 -4
- package/dist/client/app/codegen/const.d.ts +1 -0
- package/dist/client/app/codegen/const.js +3 -0
- package/dist/client/app/codegen/vue3.js +82 -21
- package/dist/client/app/components/app/AppHeader.vue +2 -2
- package/dist/client/app/components/app/Breadcrumb.vue +1 -1
- package/dist/client/app/components/base/BaseEmpty.vue +17 -1
- package/dist/client/app/components/base/BaseListItemLink.vue +1 -1
- package/dist/client/app/components/base/BaseTab.vue +1 -1
- package/dist/client/app/components/exposed/Story.vue +22 -1
- package/dist/client/app/components/exposed/Variant.vue +13 -1
- package/dist/client/app/components/sandbox/SandboxVue3.vue +6 -4
- package/dist/client/app/components/sandbox/lib.js +2 -1
- package/dist/client/app/components/search/SearchItem.vue +1 -0
- package/dist/client/app/components/search/SearchLoading.vue +16 -0
- package/dist/client/app/components/search/SearchModal.vue +12 -148
- package/dist/client/app/components/search/SearchPane.vue +210 -0
- package/dist/client/app/components/search/search-data.d.ts +2 -0
- package/dist/client/app/components/search/search-data.js +7 -0
- package/dist/client/app/components/story/StoryControls.vue +5 -0
- package/dist/client/app/components/story/StoryDocs.vue +18 -11
- package/dist/client/app/components/story/StoryEvent.vue +53 -0
- package/dist/client/app/components/story/StoryEvents.vue +45 -0
- package/dist/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/dist/client/app/components/story/StorySidePanel.vue +28 -3
- package/dist/client/app/components/story/StorySourceCode.vue +24 -14
- package/dist/client/app/components/story/StoryView.vue +16 -2
- package/dist/client/app/components/story/toolbar/StoryVariantNewTab.vue +1 -1
- package/dist/client/app/components/tree/StoryGroup.vue +75 -0
- package/dist/client/app/components/{story → tree}/StoryList.vue +8 -2
- package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListFolder.vue +10 -8
- package/{src/client/app/components/story → dist/client/app/components/tree}/StoryListItem.vue +7 -4
- package/dist/client/app/router.d.ts +1 -0
- package/dist/client/app/router.js +3 -1
- package/dist/client/app/sandbox.js +11 -1
- package/dist/client/app/stores/events.d.ts +29 -0
- package/dist/client/app/stores/events.js +25 -0
- package/dist/client/app/stores/folder.d.ts +10 -0
- package/dist/client/app/stores/folder.js +47 -0
- package/dist/client/app/stores/story.d.ts +20 -8
- package/dist/client/app/stores/story.js +20 -28
- package/dist/client/app/style/floating-vue.pcss +3 -1
- package/dist/client/app/style/main.pcss +5 -0
- package/dist/client/app/style/sandbox.css +2 -0
- package/dist/client/app/types.d.ts +9 -1
- package/dist/client/app/util/const.d.ts +1 -0
- package/dist/client/app/util/const.js +1 -0
- package/dist/client/app/util/events.d.ts +1 -0
- package/dist/client/app/util/events.js +31 -0
- package/dist/client/app/util/mapping.js +2 -2
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.js +2 -1
- package/dist/client/server/Story.server.vue +21 -4
- package/dist/node/alias.d.ts +2 -1
- package/dist/node/alias.js +3 -2
- package/dist/node/build.js +74 -21
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +5 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +510 -0
- package/dist/node/collect/index.js +5 -3
- package/dist/node/commands/preview.js +4 -25
- package/dist/node/config.d.ts +111 -5
- package/dist/node/config.js +40 -23
- package/dist/node/context.d.ts +3 -3
- package/dist/node/context.js +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/load.d.ts +12 -0
- package/dist/node/load.js +42 -0
- package/dist/node/plugin.d.ts +67 -11
- package/dist/node/plugin.js +42 -245
- package/dist/node/preview.d.ts +8 -0
- package/dist/node/preview.js +41 -0
- package/dist/node/search.d.ts +2 -0
- package/dist/node/search.js +68 -0
- package/dist/node/server.js +43 -21
- package/dist/node/stories.d.ts +2 -0
- package/dist/node/stories.js +9 -4
- package/dist/node/tree.d.ts +16 -12
- package/dist/node/tree.js +45 -5
- package/dist/node/types.d.ts +11 -0
- package/dist/node/util/find-up.d.ts +1 -0
- package/dist/node/util/find-up.js +20 -0
- package/dist/node/vite.d.ts +13 -0
- package/dist/node/vite.js +278 -0
- package/dist/style.css +179 -36
- package/package.json +5 -3
- package/scripts/copy.mjs +2 -1
- package/src/client/app/App.vue +9 -4
- package/src/client/app/codegen/const.ts +3 -0
- package/src/client/app/codegen/vue3.ts +80 -22
- package/src/client/app/components/app/AppHeader.vue +2 -2
- package/src/client/app/components/app/Breadcrumb.vue +1 -1
- package/src/client/app/components/base/BaseEmpty.vue +17 -1
- package/src/client/app/components/base/BaseListItemLink.vue +1 -1
- package/src/client/app/components/base/BaseTab.vue +1 -1
- package/src/client/app/components/exposed/Story.vue +22 -1
- package/src/client/app/components/exposed/Variant.vue +13 -1
- package/src/client/app/components/sandbox/SandboxVue3.vue +6 -4
- package/src/client/app/components/sandbox/lib.ts +3 -1
- package/src/client/app/components/search/SearchItem.vue +1 -0
- package/src/client/app/components/search/SearchLoading.vue +16 -0
- package/src/client/app/components/search/SearchModal.vue +12 -148
- package/src/client/app/components/search/SearchPane.vue +210 -0
- package/src/client/app/components/search/search-data.ts +9 -0
- package/src/client/app/components/story/StoryControls.vue +5 -0
- package/src/client/app/components/story/StoryDocs.vue +18 -11
- package/src/client/app/components/story/StoryEvent.vue +53 -0
- package/src/client/app/components/story/StoryEvents.vue +45 -0
- package/src/client/app/components/story/StoryResponsivePreview.vue +41 -8
- package/src/client/app/components/story/StorySidePanel.vue +28 -3
- package/src/client/app/components/story/StorySourceCode.vue +24 -14
- package/src/client/app/components/story/StoryView.vue +16 -2
- package/src/client/app/components/story/toolbar/StoryVariantNewTab.vue +1 -1
- package/src/client/app/components/tree/StoryGroup.vue +75 -0
- package/src/client/app/components/{story → tree}/StoryList.vue +8 -2
- package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListFolder.vue +10 -8
- package/{dist/client/app/components/story → src/client/app/components/tree}/StoryListItem.vue +7 -4
- package/src/client/app/router.ts +4 -1
- package/src/client/app/sandbox.ts +12 -2
- package/src/client/app/stores/events.ts +36 -0
- package/src/client/app/stores/folder.ts +59 -0
- package/src/client/app/stores/story.ts +20 -35
- package/src/client/app/style/floating-vue.pcss +3 -1
- package/src/client/app/style/main.pcss +5 -0
- package/src/client/app/style/sandbox.css +2 -0
- package/src/client/app/types.ts +10 -1
- package/src/client/app/util/const.ts +1 -0
- package/src/client/app/util/events.ts +30 -0
- package/src/client/app/util/mapping.ts +2 -2
- package/src/client/index.ts +2 -1
- package/src/client/server/Story.server.vue +21 -4
- package/src/node/alias.ts +4 -2
- package/src/node/build.ts +86 -21
- package/src/node/builtin-plugins/tailwind-tokens.ts +521 -0
- package/src/node/collect/index.ts +6 -4
- package/src/node/commands/preview.ts +4 -33
- package/src/node/config.ts +62 -29
- package/src/node/context.ts +3 -3
- package/src/node/index.ts +1 -0
- package/src/node/load.ts +63 -0
- package/src/node/plugin.ts +75 -252
- package/src/node/preview.ts +56 -0
- package/src/node/search.ts +75 -0
- package/src/node/server.ts +49 -23
- package/src/node/stories.ts +9 -4
- package/src/node/tree.spec.ts +35 -17
- package/src/node/tree.ts +64 -10
- package/src/node/types.ts +12 -0
- package/src/node/util/find-up.ts +24 -0
- package/src/node/vite.ts +296 -0
- package/tailwind.config.cjs +1 -0
- package/tsconfig.json +2 -0
- package/dist/client/app/codegen/serialize-js.ts +0 -119
- package/dist/client/app/codegen/util.ts +0 -79
- package/dist/client/app/codegen/vue3.ts +0 -276
- package/dist/client/app/components/sandbox/lib.ts +0 -8
- package/dist/client/app/global-components.ts +0 -13
- package/dist/client/app/index.ts +0 -28
- package/dist/client/app/router.ts +0 -17
- package/dist/client/app/sandbox.ts +0 -94
- package/dist/client/app/stores/preview-settings.ts +0 -17
- package/dist/client/app/stores/story.ts +0 -62
- package/dist/client/app/types.ts +0 -70
- package/dist/client/app/util/config.ts +0 -6
- package/dist/client/app/util/const.ts +0 -3
- package/dist/client/app/util/dark.ts +0 -4
- package/dist/client/app/util/env.ts +0 -1
- package/dist/client/app/util/keyboard.ts +0 -99
- package/dist/client/app/util/mapping.ts +0 -48
- package/dist/client/app/util/preview-settings.ts +0 -8
- package/dist/client/app/util/reactivity.ts +0 -22
- package/dist/client/app/util/responsive.ts +0 -3
- package/dist/client/app/util/scroll.ts +0 -31
- package/dist/client/app/util/tooltip.ts +0 -13
- package/dist/client/app/util/variant.ts +0 -20
- package/dist/client/index.ts +0 -12
- package/dist/client/server/index.ts +0 -32
- package/dist/client/shim.d.ts +0 -5
package/dist/node/types.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import type { TreeFile } from './tree.js';
|
|
1
2
|
export interface StoryFile {
|
|
2
3
|
id: string;
|
|
3
4
|
/**
|
|
4
5
|
* Absolute path
|
|
5
6
|
*/
|
|
6
7
|
path: string;
|
|
8
|
+
/**
|
|
9
|
+
* File name without extension
|
|
10
|
+
*/
|
|
11
|
+
fileName: string;
|
|
7
12
|
/**
|
|
8
13
|
* Generated path for tree UI
|
|
9
14
|
*/
|
|
@@ -16,10 +21,15 @@ export interface StoryFile {
|
|
|
16
21
|
* Resolved story data from story file execution
|
|
17
22
|
*/
|
|
18
23
|
story?: Story;
|
|
24
|
+
/**
|
|
25
|
+
* Data sent to user tree config functions
|
|
26
|
+
*/
|
|
27
|
+
treeFile?: TreeFile;
|
|
19
28
|
}
|
|
20
29
|
export interface Story {
|
|
21
30
|
id: string;
|
|
22
31
|
title: string;
|
|
32
|
+
group?: string;
|
|
23
33
|
variants: Variant[];
|
|
24
34
|
layout?: {
|
|
25
35
|
type: 'single';
|
|
@@ -29,6 +39,7 @@ export interface Story {
|
|
|
29
39
|
};
|
|
30
40
|
icon?: string;
|
|
31
41
|
iconColor?: string;
|
|
42
|
+
docsOnly?: boolean;
|
|
32
43
|
}
|
|
33
44
|
export interface Variant {
|
|
34
45
|
id: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findUp(cwd: string, fileNames: string[]): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import path from 'pathe';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
export function findUp(cwd = process.cwd(), fileNames) {
|
|
4
|
+
let { root } = path.parse(cwd);
|
|
5
|
+
let dir = cwd;
|
|
6
|
+
// Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
|
|
7
|
+
if (root === '' && dir[1] === ':') {
|
|
8
|
+
root = dir.substring(0, 2);
|
|
9
|
+
}
|
|
10
|
+
while (dir !== root) {
|
|
11
|
+
for (const fileName of fileNames) {
|
|
12
|
+
const searchPath = path.join(dir, fileName);
|
|
13
|
+
if (fs.existsSync(searchPath)) {
|
|
14
|
+
return searchPath;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
dir = path.dirname(dir);
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import { Context } from './context.js';
|
|
3
|
+
export declare const STORIES_ID = "$histoire-stories";
|
|
4
|
+
export declare const RESOLVED_STORIES_ID: string;
|
|
5
|
+
export declare const SETUP_ID = "$histoire-setup";
|
|
6
|
+
export declare const NOOP_ID = "/$histoire-noop";
|
|
7
|
+
export declare const CONFIG_ID = "$histoire-config";
|
|
8
|
+
export declare const RESOLVED_CONFIG_ID: string;
|
|
9
|
+
export declare const THEME_ID = "$histoire-theme";
|
|
10
|
+
export declare const RESOLVED_THEME_ID: string;
|
|
11
|
+
export declare const SEARCH_DATA_ID = "$histoire-search-data";
|
|
12
|
+
export declare const RESOLVED_SEARCH_DATA_ID: string;
|
|
13
|
+
export declare function createVitePlugins(ctx: Context): Promise<VitePlugin[]>;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { relative, dirname } from 'pathe';
|
|
3
|
+
import { resolveConfig as resolveViteConfig } from 'vite';
|
|
4
|
+
import { lookup as lookupMime } from 'mrmime';
|
|
5
|
+
import { APP_PATH, DIST_PATH, TEMP_PATH } from './alias.js';
|
|
6
|
+
import { notifyStoryChange } from './stories.js';
|
|
7
|
+
import { makeTree } from './tree.js';
|
|
8
|
+
import { parseColor } from './colors.js';
|
|
9
|
+
import { createMarkdownRenderer } from './markdown.js';
|
|
10
|
+
import { generateSearchData } from './search.js';
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
export const STORIES_ID = '$histoire-stories';
|
|
13
|
+
export const RESOLVED_STORIES_ID = `/${STORIES_ID}-resolved`;
|
|
14
|
+
export const SETUP_ID = '$histoire-setup';
|
|
15
|
+
export const NOOP_ID = '/$histoire-noop';
|
|
16
|
+
export const CONFIG_ID = '$histoire-config';
|
|
17
|
+
export const RESOLVED_CONFIG_ID = `/${CONFIG_ID}-resolved`;
|
|
18
|
+
export const THEME_ID = '$histoire-theme';
|
|
19
|
+
export const RESOLVED_THEME_ID = `/${THEME_ID}-resolved.css`;
|
|
20
|
+
export const SEARCH_DATA_ID = '$histoire-search-data';
|
|
21
|
+
export const RESOLVED_SEARCH_DATA_ID = `/${SEARCH_DATA_ID}-resolved`;
|
|
22
|
+
export async function createVitePlugins(ctx) {
|
|
23
|
+
const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
|
|
24
|
+
const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
|
|
25
|
+
const plugins = [];
|
|
26
|
+
if (!hasVuePlugin) {
|
|
27
|
+
plugins.push((await import('@vitejs/plugin-vue')).default());
|
|
28
|
+
}
|
|
29
|
+
if (ctx.config.vite) {
|
|
30
|
+
plugins.push({
|
|
31
|
+
name: 'histoire-vite-config-override',
|
|
32
|
+
config(config, env) {
|
|
33
|
+
return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
plugins.push({
|
|
38
|
+
name: 'histoire-vite-plugin',
|
|
39
|
+
config() {
|
|
40
|
+
return {
|
|
41
|
+
optimizeDeps: {
|
|
42
|
+
// force include vue to avoid duplicated copies when linked + optimized
|
|
43
|
+
include: [
|
|
44
|
+
'vue',
|
|
45
|
+
dirname(require.resolve('@vue/runtime-core/package.json')),
|
|
46
|
+
dirname(require.resolve('shiki/package.json')),
|
|
47
|
+
dirname(require.resolve('vscode-textmate/package.json')),
|
|
48
|
+
dirname(require.resolve('vscode-oniguruma/package.json')),
|
|
49
|
+
dirname(require.resolve('case/package.json')),
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
server: {
|
|
53
|
+
fs: {
|
|
54
|
+
allow: [DIST_PATH, TEMP_PATH, viteConfig.root, process.cwd()],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
define: {
|
|
58
|
+
// We need to force this to be able to use `devtoolsRawSetupState`
|
|
59
|
+
__VUE_PROD_DEVTOOLS__: 'true',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
async resolveId(id, importer) {
|
|
64
|
+
if (id.startsWith(STORIES_ID)) {
|
|
65
|
+
return RESOLVED_STORIES_ID;
|
|
66
|
+
}
|
|
67
|
+
if (id.startsWith(SETUP_ID)) {
|
|
68
|
+
if (ctx.config.setupFile) {
|
|
69
|
+
return this.resolve(ctx.config.setupFile, importer, {
|
|
70
|
+
skipSelf: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return NOOP_ID;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (id.startsWith(CONFIG_ID)) {
|
|
78
|
+
return RESOLVED_CONFIG_ID;
|
|
79
|
+
}
|
|
80
|
+
if (id.startsWith(THEME_ID)) {
|
|
81
|
+
return RESOLVED_THEME_ID;
|
|
82
|
+
}
|
|
83
|
+
if (id.startsWith(SEARCH_DATA_ID)) {
|
|
84
|
+
return RESOLVED_SEARCH_DATA_ID;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
async load(id) {
|
|
88
|
+
if (id === RESOLVED_STORIES_ID) {
|
|
89
|
+
const resolvedStories = ctx.storyFiles.filter(s => !!s.story);
|
|
90
|
+
const files = resolvedStories.map((file, index) => {
|
|
91
|
+
return {
|
|
92
|
+
id: file.id,
|
|
93
|
+
path: file.treePath,
|
|
94
|
+
story: file.story,
|
|
95
|
+
framework: 'vue3',
|
|
96
|
+
index,
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
return `import { defineAsyncComponent } from 'vue'
|
|
100
|
+
${resolvedStories.map((file, index) => `const Comp${index} = defineAsyncComponent(() => import('${file.path}'))`).join('\n')}
|
|
101
|
+
export let files = [${files.map((file) => `{${JSON.stringify(file).slice(1, -1)}, component: Comp${file.index}}`).join(',\n')}]
|
|
102
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
103
|
+
const handlers = []
|
|
104
|
+
export function onUpdate (cb) {
|
|
105
|
+
handlers.push(cb)
|
|
106
|
+
}
|
|
107
|
+
if (import.meta.hot) {
|
|
108
|
+
import.meta.hot.accept(newModule => {
|
|
109
|
+
files = newModule.files
|
|
110
|
+
tree = newModule.tree
|
|
111
|
+
handlers.forEach(h => {
|
|
112
|
+
h(newModule.files, newModule.tree)
|
|
113
|
+
newModule.onUpdate(h)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
}`;
|
|
117
|
+
}
|
|
118
|
+
if (id === NOOP_ID) {
|
|
119
|
+
return `export default () => {}`;
|
|
120
|
+
}
|
|
121
|
+
if (id === RESOLVED_CONFIG_ID) {
|
|
122
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`;
|
|
123
|
+
if (ctx.config.theme?.logo) {
|
|
124
|
+
for (const key in ctx.config.theme.logo) {
|
|
125
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`;
|
|
129
|
+
return js;
|
|
130
|
+
}
|
|
131
|
+
if (id === RESOLVED_THEME_ID) {
|
|
132
|
+
let css = '*, ::before, ::after {';
|
|
133
|
+
// Colors
|
|
134
|
+
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
135
|
+
for (const key in ctx.config.theme.colors[color]) {
|
|
136
|
+
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
css += '}';
|
|
140
|
+
return css;
|
|
141
|
+
}
|
|
142
|
+
if (id === RESOLVED_SEARCH_DATA_ID) {
|
|
143
|
+
return `export let searchData = ${JSON.stringify(await generateSearchData(ctx))}
|
|
144
|
+
const handlers = []
|
|
145
|
+
export function onUpdate (cb) {
|
|
146
|
+
handlers.push(cb)
|
|
147
|
+
}
|
|
148
|
+
if (import.meta.hot) {
|
|
149
|
+
import.meta.hot.accept(newModule => {
|
|
150
|
+
searchData = newModule.searchData
|
|
151
|
+
handlers.forEach(h => {
|
|
152
|
+
h(newModule.searchData)
|
|
153
|
+
newModule.onUpdate(h)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
}`;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
handleHotUpdate(updateContext) {
|
|
160
|
+
const story = ctx.storyFiles.find(file => file.path === updateContext.file);
|
|
161
|
+
if (story) {
|
|
162
|
+
notifyStoryChange(story);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
configureServer(server) {
|
|
166
|
+
server.middlewares.use(async (req, res, next) => {
|
|
167
|
+
if (req.url.startsWith(`${server.config.base}__sandbox`)) {
|
|
168
|
+
res.statusCode = 200;
|
|
169
|
+
let html = `
|
|
170
|
+
<!DOCTYPE html>
|
|
171
|
+
<html>
|
|
172
|
+
<head>
|
|
173
|
+
<title></title>
|
|
174
|
+
<meta charset="utf-8">
|
|
175
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
176
|
+
<meta name="description" content="">
|
|
177
|
+
</head>
|
|
178
|
+
<body>
|
|
179
|
+
<div id="app"></div>
|
|
180
|
+
<script>
|
|
181
|
+
// Hide spammy vite messages
|
|
182
|
+
const origConsoleLog = console.log
|
|
183
|
+
console.log = (...args) => {
|
|
184
|
+
if (typeof args[0] !== 'string' || !args[0].startsWith('[vite] connect')) {
|
|
185
|
+
origConsoleLog(...args)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
</script>
|
|
189
|
+
<script type="module" src="/@fs/${APP_PATH}/sandbox.js"></script>
|
|
190
|
+
</body>
|
|
191
|
+
</html>`;
|
|
192
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
193
|
+
// also applies HTML transforms from Vite plugins
|
|
194
|
+
html = await server.transformIndexHtml(req.url, html);
|
|
195
|
+
res.end(html);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
next();
|
|
199
|
+
});
|
|
200
|
+
// serve our index.html after vite history fallback
|
|
201
|
+
return () => {
|
|
202
|
+
server.middlewares.use(async (req, res, next) => {
|
|
203
|
+
if (req.url.endsWith('.html')) {
|
|
204
|
+
res.statusCode = 200;
|
|
205
|
+
let html = `
|
|
206
|
+
<!DOCTYPE html>
|
|
207
|
+
<html>
|
|
208
|
+
<head>
|
|
209
|
+
<title></title>
|
|
210
|
+
<link rel="icon" href=""/>
|
|
211
|
+
<meta charset="utf-8">
|
|
212
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
213
|
+
<meta name="description" content="">
|
|
214
|
+
${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${server.config.base}${ctx.config.theme.favicon}"/>` : ''}
|
|
215
|
+
</head>
|
|
216
|
+
<body>
|
|
217
|
+
<div id="app"></div>
|
|
218
|
+
<script type="module" src="/@fs/${APP_PATH}/index.js"></script>
|
|
219
|
+
</body>
|
|
220
|
+
</html>`;
|
|
221
|
+
// Apply Vite HTML transforms. This injects the Vite HMR client, and
|
|
222
|
+
// also applies HTML transforms from Vite plugins
|
|
223
|
+
html = await server.transformIndexHtml(req.url, html);
|
|
224
|
+
res.end(html);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
next();
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
// Custom blocks
|
|
233
|
+
plugins.push(...await createCustomBlocksPlugins(ctx));
|
|
234
|
+
if (ctx.mode === 'build') {
|
|
235
|
+
// Add file name in build mode to have components names instead of <Anonymous>
|
|
236
|
+
const include = [/\.vue$/];
|
|
237
|
+
const exclude = [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/];
|
|
238
|
+
plugins.push({
|
|
239
|
+
name: 'histoire-file-name-plugin',
|
|
240
|
+
enforce: 'post',
|
|
241
|
+
transform(code, id) {
|
|
242
|
+
if (exclude.some(r => r.test(id)))
|
|
243
|
+
return;
|
|
244
|
+
if (include.some(r => r.test(id))) {
|
|
245
|
+
const file = relative(viteConfig.root, id);
|
|
246
|
+
const index = code.indexOf('export default');
|
|
247
|
+
const result = `${code.substring(0, index)}_sfc_main.__file = '${file}'\n${code.substring(index)}`;
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return plugins;
|
|
254
|
+
}
|
|
255
|
+
async function createCustomBlocksPlugins(ctx) {
|
|
256
|
+
const plugins = [];
|
|
257
|
+
let md = await createMarkdownRenderer();
|
|
258
|
+
if (ctx.config.markdown) {
|
|
259
|
+
const result = await ctx.config.markdown(md);
|
|
260
|
+
if (result) {
|
|
261
|
+
md = result;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
plugins.push({
|
|
265
|
+
name: 'histoire-vue-docs-block',
|
|
266
|
+
transform(code, id) {
|
|
267
|
+
if (!id.includes('?vue&type=docs'))
|
|
268
|
+
return;
|
|
269
|
+
if (!id.includes('lang.md'))
|
|
270
|
+
return;
|
|
271
|
+
const html = md.render(code);
|
|
272
|
+
return `export default Comp => {
|
|
273
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
274
|
+
}`;
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
return plugins;
|
|
278
|
+
}
|