poveste 0.1.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/LICENSE +22 -0
- package/README.md +11 -0
- package/bin.mjs +4 -0
- package/client.d.ts +19 -0
- package/client.js +15 -0
- package/dist/controls.d.ts +2 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +1 -0
- package/dist/node/alias.d.ts +3 -0
- package/dist/node/alias.d.ts.map +1 -0
- package/dist/node/alias.js +5 -0
- package/dist/node/bin.d.ts +2 -0
- package/dist/node/bin.d.ts.map +1 -0
- package/dist/node/bin.js +35 -0
- package/dist/node/build-serialize.d.ts +22 -0
- package/dist/node/build-serialize.d.ts.map +1 -0
- package/dist/node/build-serialize.js +36 -0
- package/dist/node/build.d.ts +3 -0
- package/dist/node/build.d.ts.map +1 -0
- package/dist/node/build.js +228 -0
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts +7 -0
- package/dist/node/builtin-plugins/pinceau-tokens.d.ts.map +1 -0
- package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts +6 -0
- package/dist/node/builtin-plugins/tailwind-tokens.d.ts.map +1 -0
- package/dist/node/builtin-plugins/tailwind-tokens.js +523 -0
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +15 -0
- package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/MountStory.js +39 -0
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +39 -0
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +129 -0
- package/dist/node/builtin-plugins/vanilla-support/client.d.ts +4 -0
- package/dist/node/builtin-plugins/vanilla-support/client.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/client.js +5 -0
- package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +3 -0
- package/dist/node/builtin-plugins/vanilla-support/collect.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/collect.js +33 -0
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +3 -0
- package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/plugin.js +29 -0
- package/dist/node/builtin-plugins/vanilla-support/types.d.ts +36 -0
- package/dist/node/builtin-plugins/vanilla-support/types.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/types.js +3 -0
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +4 -0
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts.map +1 -0
- package/dist/node/builtin-plugins/vanilla-support/vanilla.story.js +55 -0
- package/dist/node/collect/index.d.ts +14 -0
- package/dist/node/collect/index.d.ts.map +1 -0
- package/dist/node/collect/index.js +129 -0
- package/dist/node/collect/run.d.ts +3 -0
- package/dist/node/collect/run.d.ts.map +1 -0
- package/dist/node/collect/run.js +7 -0
- package/dist/node/collect/worker.d.ts +14 -0
- package/dist/node/collect/worker.d.ts.map +1 -0
- package/dist/node/collect/worker.js +64 -0
- package/dist/node/colors.d.ts +287 -0
- package/dist/node/colors.d.ts.map +1 -0
- package/dist/node/colors.js +324 -0
- package/dist/node/commands/build.d.ts +5 -0
- package/dist/node/commands/build.d.ts.map +1 -0
- package/dist/node/commands/build.js +9 -0
- package/dist/node/commands/dev.d.ts +8 -0
- package/dist/node/commands/dev.d.ts.map +1 -0
- package/dist/node/commands/dev.js +52 -0
- package/dist/node/commands/preview.d.ts +5 -0
- package/dist/node/commands/preview.d.ts.map +1 -0
- package/dist/node/commands/preview.js +15 -0
- package/dist/node/config.d.ts +40 -0
- package/dist/node/config.d.ts.map +1 -0
- package/dist/node/config.js +330 -0
- package/dist/node/context.d.ts +18 -0
- package/dist/node/context.d.ts.map +1 -0
- package/dist/node/context.js +28 -0
- package/dist/node/dom/dom-keys.d.ts +5 -0
- package/dist/node/dom/dom-keys.d.ts.map +1 -0
- package/dist/node/dom/dom-keys.js +233 -0
- package/dist/node/dom/env.d.ts +5 -0
- package/dist/node/dom/env.d.ts.map +1 -0
- package/dist/node/dom/env.js +47 -0
- package/dist/node/dom/util.d.ts +11 -0
- package/dist/node/dom/util.d.ts.map +1 -0
- package/dist/node/dom/util.js +65 -0
- package/dist/node/index.d.ts +12 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +4 -0
- package/dist/node/load.d.ts +9 -0
- package/dist/node/load.d.ts.map +1 -0
- package/dist/node/load.js +42 -0
- package/dist/node/markdown.d.ts +11 -0
- package/dist/node/markdown.d.ts.map +1 -0
- package/dist/node/markdown.js +228 -0
- package/dist/node/plugin.d.ts +42 -0
- package/dist/node/plugin.d.ts.map +1 -0
- package/dist/node/plugin.js +67 -0
- package/dist/node/preview.d.ts +8 -0
- package/dist/node/preview.d.ts.map +1 -0
- package/dist/node/preview.js +41 -0
- package/dist/node/search.d.ts +17 -0
- package/dist/node/search.d.ts.map +1 -0
- package/dist/node/search.js +72 -0
- package/dist/node/server.d.ts +12 -0
- package/dist/node/server.d.ts.map +1 -0
- package/dist/node/server.js +189 -0
- package/dist/node/stories.d.ts +22 -0
- package/dist/node/stories.d.ts.map +1 -0
- package/dist/node/stories.js +125 -0
- package/dist/node/tree.d.ts +4 -0
- package/dist/node/tree.d.ts.map +1 -0
- package/dist/node/tree.js +117 -0
- package/dist/node/util/find-up.d.ts +2 -0
- package/dist/node/util/find-up.d.ts.map +1 -0
- package/dist/node/util/find-up.js +20 -0
- package/dist/node/util/fs.d.ts +2 -0
- package/dist/node/util/fs.d.ts.map +1 -0
- package/dist/node/util/fs.js +1 -0
- package/dist/node/util/log.d.ts +2 -0
- package/dist/node/util/log.d.ts.map +1 -0
- package/dist/node/util/log.js +9 -0
- package/dist/node/util/slugify.d.ts +2 -0
- package/dist/node/util/slugify.d.ts.map +1 -0
- package/dist/node/util/slugify.js +22 -0
- package/dist/node/util/vendors.d.ts +3 -0
- package/dist/node/util/vendors.d.ts.map +1 -0
- package/dist/node/util/vendors.js +22 -0
- package/dist/node/vendors/controls.d.ts +2 -0
- package/dist/node/vendors/controls.d.ts.map +1 -0
- package/dist/node/vendors/controls.js +1 -0
- package/dist/node/vendors/vue.d.ts +2 -0
- package/dist/node/vendors/vue.d.ts.map +1 -0
- package/dist/node/vendors/vue.js +1 -0
- package/dist/node/virtual/index.d.ts +38 -0
- package/dist/node/virtual/index.d.ts.map +1 -0
- package/dist/node/virtual/index.js +49 -0
- package/dist/node/virtual/markdown.d.ts +3 -0
- package/dist/node/virtual/markdown.d.ts.map +1 -0
- package/dist/node/virtual/markdown.js +19 -0
- package/dist/node/virtual/noop.d.ts +2 -0
- package/dist/node/virtual/noop.d.ts.map +1 -0
- package/dist/node/virtual/noop.js +1 -0
- package/dist/node/virtual/resolved-commands.d.ts +3 -0
- package/dist/node/virtual/resolved-commands.d.ts.map +1 -0
- package/dist/node/virtual/resolved-commands.js +32 -0
- package/dist/node/virtual/resolved-config.d.ts +3 -0
- package/dist/node/virtual/resolved-config.d.ts.map +1 -0
- package/dist/node/virtual/resolved-config.js +10 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts +3 -0
- package/dist/node/virtual/resolved-generated-global-setup.d.ts.map +1 -0
- package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts +3 -0
- package/dist/node/virtual/resolved-generated-setup-code.d.ts.map +1 -0
- package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts +3 -0
- package/dist/node/virtual/resolved-markdown-files.d.ts.map +1 -0
- package/dist/node/virtual/resolved-markdown-files.js +17 -0
- package/dist/node/virtual/resolved-stories.d.ts +3 -0
- package/dist/node/virtual/resolved-stories.d.ts.map +1 -0
- package/dist/node/virtual/resolved-stories.js +42 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts +3 -0
- package/dist/node/virtual/resolved-support-plugins-client.d.ts.map +1 -0
- package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts +3 -0
- package/dist/node/virtual/resolved-support-plugins-collect.d.ts.map +1 -0
- package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
- package/dist/node/virtual/resolved-theme.d.ts +3 -0
- package/dist/node/virtual/resolved-theme.d.ts.map +1 -0
- package/dist/node/virtual/resolved-theme.js +12 -0
- package/dist/node/virtual/story-source.d.ts +3 -0
- package/dist/node/virtual/story-source.d.ts.map +1 -0
- package/dist/node/virtual/story-source.js +16 -0
- package/dist/node/virtual/story.d.ts +3 -0
- package/dist/node/virtual/story.d.ts.map +1 -0
- package/dist/node/virtual/story.js +7 -0
- package/dist/node/virtual/util.d.ts +3 -0
- package/dist/node/virtual/util.d.ts.map +1 -0
- package/dist/node/virtual/util.js +4 -0
- package/dist/node/virtual/vite-plugin.d.ts +4 -0
- package/dist/node/virtual/vite-plugin.d.ts.map +1 -0
- package/dist/node/virtual/vite-plugin.js +126 -0
- package/dist/node/vite.d.ts +9 -0
- package/dist/node/vite.d.ts.map +1 -0
- package/dist/node/vite.js +337 -0
- package/index.d.ts +1 -0
- package/package.json +89 -0
- package/plugin.d.ts +3 -0
- package/plugin.js +11 -0
- package/src/controls.ts +1 -0
- package/src/node/__tests__/markdown/test1.story.md +7 -0
- package/src/node/__tests__/markdown/test2.story.md +5 -0
- package/src/node/__tests__/markdown.spec.ts +61 -0
- package/src/node/__tests__/tree.spec.ts +109 -0
- package/src/node/alias.ts +8 -0
- package/src/node/bin.ts +43 -0
- package/src/node/build-serialize.ts +62 -0
- package/src/node/build.ts +283 -0
- package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
- package/src/node/builtin-plugins/tailwind-tokens.ts +536 -0
- package/src/node/builtin-plugins/vanilla-support/MountStory.ts +49 -0
- package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +164 -0
- package/src/node/builtin-plugins/vanilla-support/client.ts +6 -0
- package/src/node/builtin-plugins/vanilla-support/collect.ts +43 -0
- package/src/node/builtin-plugins/vanilla-support/plugin.ts +35 -0
- package/src/node/builtin-plugins/vanilla-support/types.ts +40 -0
- package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +63 -0
- package/src/node/collect/index.ts +160 -0
- package/src/node/collect/run.ts +9 -0
- package/src/node/collect/worker.ts +97 -0
- package/src/node/colors.ts +340 -0
- package/src/node/commands/build.ts +14 -0
- package/src/node/commands/dev.ts +67 -0
- package/src/node/commands/preview.ts +22 -0
- package/src/node/config.ts +385 -0
- package/src/node/context.ts +60 -0
- package/src/node/dom/dom-keys.ts +238 -0
- package/src/node/dom/env.ts +60 -0
- package/src/node/dom/util.ts +83 -0
- package/src/node/index.ts +12 -0
- package/src/node/load.ts +59 -0
- package/src/node/markdown.ts +267 -0
- package/src/node/plugin.ts +95 -0
- package/src/node/preview.ts +57 -0
- package/src/node/search.ts +84 -0
- package/src/node/server.ts +235 -0
- package/src/node/stories.ts +154 -0
- package/src/node/tree.ts +158 -0
- package/src/node/util/find-up.ts +24 -0
- package/src/node/util/fs.ts +1 -0
- package/src/node/util/log.ts +10 -0
- package/src/node/util/slugify.ts +26 -0
- package/src/node/util/vendors.ts +27 -0
- package/src/node/vendors/controls.ts +1 -0
- package/src/node/vendors/vue.ts +1 -0
- package/src/node/virtual/index.ts +50 -0
- package/src/node/virtual/markdown.ts +21 -0
- package/src/node/virtual/noop.ts +1 -0
- package/src/node/virtual/resolved-commands.ts +42 -0
- package/src/node/virtual/resolved-config.ts +12 -0
- package/src/node/virtual/resolved-generated-global-setup.ts +25 -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 +44 -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 +18 -0
- package/src/node/virtual/story.ts +9 -0
- package/src/node/virtual/util.ts +5 -0
- package/src/node/virtual/vite-plugin.ts +146 -0
- package/src/node/vite.ts +379 -0
- package/tsconfig.json +44 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
3
|
+
|
|
4
|
+
// Resolve an absolute path to e.g. node_modules/.pnpm/histoire@0.11.7_vite@3.2.4/node_modules/histoire/dist/node/vendors/controls.js
|
|
5
|
+
// https://github.com/histoire-dev/histoire/issues/282
|
|
6
|
+
export const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
|
|
8
|
+
// https://github.com/vitejs/vite/issues/9661
|
|
9
|
+
const alias = {
|
|
10
|
+
'@poveste/vendors/vue': path.resolve(__dirname, '../vendors/vue.js'),
|
|
11
|
+
'@poveste/controls': path.resolve(__dirname, '../vendors/controls.js'),
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getInjectedImport(request: string) {
|
|
15
|
+
let id: string = request
|
|
16
|
+
|
|
17
|
+
if (alias[id]) {
|
|
18
|
+
id = alias[id]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (path.isAbsolute(id)) {
|
|
22
|
+
return JSON.stringify(pathToFileURL(id).href)
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return JSON.stringify(id)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@poveste/controls'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@poveste/vendors/vue'
|
|
@@ -0,0 +1,50 @@
|
|
|
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 const COMMANDS = 'virtual:$histoire-commands'
|
|
36
|
+
export const RESOLVED_COMMANDS = `/__resolved__${COMMANDS}`
|
|
37
|
+
|
|
38
|
+
export * from './markdown.js'
|
|
39
|
+
export * from './noop.js'
|
|
40
|
+
export * from './resolved-commands.js'
|
|
41
|
+
export * from './resolved-config.js'
|
|
42
|
+
export * from './resolved-generated-global-setup.js'
|
|
43
|
+
export * from './resolved-generated-setup-code.js'
|
|
44
|
+
export * from './resolved-markdown-files.js'
|
|
45
|
+
export * from './resolved-stories.js'
|
|
46
|
+
export * from './resolved-support-plugins-client.js'
|
|
47
|
+
export * from './resolved-support-plugins-collect.js'
|
|
48
|
+
export * from './resolved-theme.js'
|
|
49
|
+
export * from './story-source.js'
|
|
50
|
+
export * from './story.js'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
|
|
3
|
+
export function markdown(ctx: Context, id: string) {
|
|
4
|
+
const fileId = id.slice('/__resolved__virtual:md:'.length)
|
|
5
|
+
const file = ctx.markdownFiles.find(f => f.id === fileId)
|
|
6
|
+
if (!file) {
|
|
7
|
+
throw new Error(`Markdown file not found: ${fileId}`)
|
|
8
|
+
}
|
|
9
|
+
const { html, frontmatter, relativePath } = file
|
|
10
|
+
return `export const html = ${JSON.stringify(html)}
|
|
11
|
+
export const frontmatter = ${JSON.stringify(frontmatter)}
|
|
12
|
+
export const relativePath = ${JSON.stringify(relativePath)}
|
|
13
|
+
|
|
14
|
+
if (import.meta.hot) {
|
|
15
|
+
import.meta.hot.accept(newModule => {
|
|
16
|
+
if (newModule) {
|
|
17
|
+
window.__hst_md_hmr(newModule)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
}`
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noop = () => `export default () => {}`
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PluginCommand } from '@poveste/shared'
|
|
2
|
+
import type { Context } from '../context.js'
|
|
3
|
+
|
|
4
|
+
const serializedFields: Readonly<(keyof PluginCommand)[]> = ['id', 'label', 'prompts', 'icon', 'searchText'] as const
|
|
5
|
+
|
|
6
|
+
export function resolvedCommands(ctx: Context) {
|
|
7
|
+
const imports: string[] = []
|
|
8
|
+
const commands: string[] = []
|
|
9
|
+
|
|
10
|
+
for (const command of ctx.registeredCommands) {
|
|
11
|
+
const fields = getCommandFields(command, imports)
|
|
12
|
+
commands.push(`{ ${fields.join(', ')} }`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return `${imports.join('\n')}
|
|
16
|
+
export const registeredCommands = [${commands.join(', ')}]
|
|
17
|
+
`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getCommandFields(command: PluginCommand, imports: string[]) {
|
|
21
|
+
const fields: string[] = []
|
|
22
|
+
|
|
23
|
+
for (const field of serializedFields) {
|
|
24
|
+
if (command[field] != null) {
|
|
25
|
+
fields.push(`${field}: ${JSON.stringify(command[field])}`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Add client-side data
|
|
30
|
+
if (command.clientSetupFile) {
|
|
31
|
+
const importedVar = `__setup${imports.length}__`
|
|
32
|
+
if (typeof command.clientSetupFile === 'string') {
|
|
33
|
+
imports.push(`import ${importedVar} from '${command.clientSetupFile}'`)
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
imports.push(`import { ${command.clientSetupFile.importName} as ${importedVar} } from '${command.clientSetupFile.file}'`)
|
|
37
|
+
}
|
|
38
|
+
fields.push(`...${importedVar}`)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return fields
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
|
|
3
|
+
export function resolvedConfig(ctx: Context) {
|
|
4
|
+
let js = `export const config = ${JSON.stringify(ctx.config)}\n`
|
|
5
|
+
if (ctx.config.theme?.logo) {
|
|
6
|
+
for (const key in ctx.config.theme.logo) {
|
|
7
|
+
js += `import Logo_${key} from '${ctx.config.theme.logo[key]}'\n`
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
js += `export const logos = {${Object.keys(ctx.config.theme?.logo ?? {}).map(key => `${key}: Logo_${key}`).join(', ')}}\n`
|
|
11
|
+
return js
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import { GENERATED_SETUP_CODE } from './index.js'
|
|
3
|
+
import { ID_SEPARATOR } from './util.js'
|
|
4
|
+
|
|
5
|
+
export function resolvedGeneratedGlobalSetup(ctx: Context) {
|
|
6
|
+
if (ctx.config.setupCode) {
|
|
7
|
+
return [
|
|
8
|
+
// Import
|
|
9
|
+
`${ctx.config.setupCode.map((c, index) => `import * as setup_${index} from '${GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}'`).join('\n')}`,
|
|
10
|
+
// List
|
|
11
|
+
`const setupList = [${ctx.config.setupCode.map((c, index) => `setup_${index}`).join(', ')}]`,
|
|
12
|
+
// Setups
|
|
13
|
+
...ctx.supportPlugins.map(p => p.setupFn).flat().map(fnName => `export async function ${fnName} (payload) {
|
|
14
|
+
for (const setup of setupList) {
|
|
15
|
+
if (setup?.${fnName}) {
|
|
16
|
+
await setup.${fnName}(payload)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}`),
|
|
20
|
+
].join('\n')
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return ''
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import { getInjectedImport } from '../util/vendors.js'
|
|
3
|
+
|
|
4
|
+
export function resolvedMarkdownFiles(ctx: Context) {
|
|
5
|
+
const filesJs = ctx.markdownFiles.map(f => `${JSON.stringify(f.relativePath)}: () => import(${JSON.stringify(`virtual:md:${f.id}`)})`).join(',')
|
|
6
|
+
return `import { reactive } from ${process.env.HISTOIRE_DEV ? `'vue'` : getInjectedImport('@poveste/vendors/vue')}
|
|
7
|
+
export const markdownFiles = reactive({${filesJs}})
|
|
8
|
+
if (import.meta.hot) {
|
|
9
|
+
if (!window.__hst_md_hmr) {
|
|
10
|
+
window.__hst_md_hmr = (newModule) => {
|
|
11
|
+
markdownFiles[newModule.relativePath] = () => newModule
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
import.meta.hot.accept(newModule => {
|
|
16
|
+
Object.assign(markdownFiles, newModule.markdownFiles)
|
|
17
|
+
})
|
|
18
|
+
}`
|
|
19
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import { makeTree } from '../tree.js'
|
|
3
|
+
|
|
4
|
+
export function resolvedStories(ctx: Context) {
|
|
5
|
+
const resolvedStories = ctx.storyFiles.filter(s => !!s.story)
|
|
6
|
+
const files = resolvedStories.map((file, index) => {
|
|
7
|
+
return {
|
|
8
|
+
id: file.id,
|
|
9
|
+
path: file.treePath,
|
|
10
|
+
filePath: file.relativePath,
|
|
11
|
+
story: {
|
|
12
|
+
...file.story,
|
|
13
|
+
docsText: undefined,
|
|
14
|
+
},
|
|
15
|
+
supportPluginId: file.supportPluginId,
|
|
16
|
+
docsFilePath: file.markdownFile?.relativePath,
|
|
17
|
+
index,
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
return `${ctx.supportPlugins.map(p => p.importStoriesPrepend).filter(Boolean).join('\n')}
|
|
21
|
+
${resolvedStories.map((file, index) => {
|
|
22
|
+
const supportPlugin = ctx.supportPlugins.find(p => p.id === file.supportPluginId)
|
|
23
|
+
if (!supportPlugin) {
|
|
24
|
+
throw new Error(`Could not find support plugin for story ${file.path}: ${file.supportPluginId}`)
|
|
25
|
+
}
|
|
26
|
+
return supportPlugin.importStoryComponent(file, index)
|
|
27
|
+
}).filter(Boolean).join('\n')}
|
|
28
|
+
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')}]
|
|
29
|
+
export let tree = ${JSON.stringify(makeTree(ctx.config, resolvedStories))}
|
|
30
|
+
const handlers = []
|
|
31
|
+
export function onUpdate (cb) {
|
|
32
|
+
handlers.push(cb)
|
|
33
|
+
}
|
|
34
|
+
if (import.meta.hot) {
|
|
35
|
+
import.meta.hot.accept(newModule => {
|
|
36
|
+
files = newModule.files
|
|
37
|
+
tree = newModule.tree
|
|
38
|
+
handlers.forEach(h => {
|
|
39
|
+
h(newModule.files, newModule.tree)
|
|
40
|
+
newModule.onUpdate(h)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
}`
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { PLUGINS_HAVE_DEV } from './util.js'
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url)
|
|
6
|
+
|
|
7
|
+
export function resolvedSupportPluginsClient(ctx: Context) {
|
|
8
|
+
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' : ''}`, {
|
|
9
|
+
paths: [ctx.root, import.meta.url],
|
|
10
|
+
}))})`)
|
|
11
|
+
return `export const clientSupportPlugins = {
|
|
12
|
+
${plugins.join(',\n ')}
|
|
13
|
+
}`
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { PLUGINS_HAVE_DEV } from './util.js'
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url)
|
|
6
|
+
|
|
7
|
+
export function resolvedSupportPluginsCollect(ctx: Context) {
|
|
8
|
+
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' : ''}`, {
|
|
9
|
+
paths: [ctx.root, import.meta.url],
|
|
10
|
+
}))})`)
|
|
11
|
+
return `export const collectSupportPlugins = {
|
|
12
|
+
${plugins.join(',\n ')}
|
|
13
|
+
}`
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import { parseColor } from '../colors.js'
|
|
3
|
+
|
|
4
|
+
export function resolvedTheme(ctx: Context) {
|
|
5
|
+
let css = '*, ::before, ::after {'
|
|
6
|
+
// Colors
|
|
7
|
+
for (const color in ctx.config.theme?.colors ?? {}) {
|
|
8
|
+
for (const key in ctx.config.theme.colors[color]) {
|
|
9
|
+
css += `--_histoire-color-${color}-${key}: ${parseColor(ctx.config.theme.colors[color][key]).color.join(' ')};`
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
css += '}'
|
|
13
|
+
return css
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
import fs from 'fs-extra'
|
|
3
|
+
import { resolve } from 'pathe'
|
|
4
|
+
|
|
5
|
+
export async function storySource(ctx: Context, id: string) {
|
|
6
|
+
const storyId = id.slice('/__resolved__virtual:story-source:'.length)
|
|
7
|
+
const storyFile = ctx.storyFiles.find(f => f.story?.id === storyId)
|
|
8
|
+
if (storyFile) {
|
|
9
|
+
let source: string
|
|
10
|
+
if (storyFile.virtual) {
|
|
11
|
+
source = storyFile.moduleCode
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
source = await fs.readFile(resolve(ctx.root, storyFile.relativePath), 'utf-8')
|
|
15
|
+
}
|
|
16
|
+
return `export default ${JSON.stringify(source)}`
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from '../context.js'
|
|
2
|
+
|
|
3
|
+
export function story(ctx: Context, id: string) {
|
|
4
|
+
const moduleId = id.replace('\0', '')
|
|
5
|
+
const storyFile = ctx.storyFiles.find(f => f.moduleId === moduleId && f.virtual)
|
|
6
|
+
if (storyFile) {
|
|
7
|
+
return storyFile.moduleCode
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite'
|
|
2
|
+
import type { Context } from '../context.js'
|
|
3
|
+
import { resolve } from 'pathe'
|
|
4
|
+
import { generateDocSearchData, generateTitleSearchData, getSearchDataJS } from '../search.js'
|
|
5
|
+
import * as VirtualFiles from './index.js'
|
|
6
|
+
import { ID_SEPARATOR } from './util.js'
|
|
7
|
+
|
|
8
|
+
export function createVirtualFilesPlugin(ctx: Context, isServer: boolean) {
|
|
9
|
+
return {
|
|
10
|
+
name: 'histoire-virtual-files',
|
|
11
|
+
|
|
12
|
+
async resolveId(id, importer) {
|
|
13
|
+
if (id.startsWith(VirtualFiles.STORIES_ID)) {
|
|
14
|
+
return VirtualFiles.RESOLVED_STORIES_ID
|
|
15
|
+
}
|
|
16
|
+
if (id.startsWith(VirtualFiles.SETUP_ID)) {
|
|
17
|
+
const setupFileConfig = ctx.config.setupFile
|
|
18
|
+
if (setupFileConfig) {
|
|
19
|
+
let file: string
|
|
20
|
+
if (typeof setupFileConfig === 'string') {
|
|
21
|
+
file = setupFileConfig
|
|
22
|
+
}
|
|
23
|
+
else if (isServer && 'server' in setupFileConfig) {
|
|
24
|
+
file = setupFileConfig.server
|
|
25
|
+
}
|
|
26
|
+
else if (!isServer && 'browser' in setupFileConfig) {
|
|
27
|
+
file = setupFileConfig.browser
|
|
28
|
+
}
|
|
29
|
+
if (file) {
|
|
30
|
+
return this.resolve(resolve(ctx.root, file), importer, {
|
|
31
|
+
skipSelf: true,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return VirtualFiles.NOOP_ID
|
|
36
|
+
}
|
|
37
|
+
if (id.startsWith(VirtualFiles.CONFIG_ID)) {
|
|
38
|
+
return VirtualFiles.RESOLVED_CONFIG_ID
|
|
39
|
+
}
|
|
40
|
+
if (id.startsWith(VirtualFiles.THEME_ID)) {
|
|
41
|
+
return VirtualFiles.RESOLVED_THEME_ID
|
|
42
|
+
}
|
|
43
|
+
if (id.startsWith(VirtualFiles.SEARCH_TITLE_DATA_ID)) {
|
|
44
|
+
return VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID
|
|
45
|
+
}
|
|
46
|
+
if (id.startsWith(VirtualFiles.SEARCH_DOCS_DATA_ID)) {
|
|
47
|
+
return VirtualFiles.RESOLVED_SEARCH_DOCS_DATA_ID
|
|
48
|
+
}
|
|
49
|
+
if (id.startsWith(VirtualFiles.GENERATED_GLOBAL_SETUP)) {
|
|
50
|
+
return VirtualFiles.RESOLVED_GENERATED_GLOBAL_SETUP
|
|
51
|
+
}
|
|
52
|
+
if (id.startsWith(VirtualFiles.GENERATED_SETUP_CODE)) {
|
|
53
|
+
const [, index] = id.split(ID_SEPARATOR)
|
|
54
|
+
return `${VirtualFiles.RESOLVED_GENERATED_SETUP_CODE}${ID_SEPARATOR}${index}`
|
|
55
|
+
}
|
|
56
|
+
if (id.startsWith(VirtualFiles.SUPPORT_PLUGINS_CLIENT)) {
|
|
57
|
+
return VirtualFiles.RESOLVED_SUPPORT_PLUGINS_CLIENT
|
|
58
|
+
}
|
|
59
|
+
if (id.startsWith(VirtualFiles.SUPPORT_PLUGINS_COLLECT)) {
|
|
60
|
+
return VirtualFiles.RESOLVED_SUPPORT_PLUGINS_COLLECT
|
|
61
|
+
}
|
|
62
|
+
if (id.startsWith(VirtualFiles.MARKDOWN_FILES)) {
|
|
63
|
+
return VirtualFiles.RESOLVED_MARKDOWN_FILES
|
|
64
|
+
}
|
|
65
|
+
if (id.startsWith(VirtualFiles.COMMANDS)) {
|
|
66
|
+
return VirtualFiles.RESOLVED_COMMANDS
|
|
67
|
+
}
|
|
68
|
+
if (id.startsWith('virtual:story:')) {
|
|
69
|
+
return `\0${id}`
|
|
70
|
+
}
|
|
71
|
+
if (id.startsWith('virtual:story-source:')) {
|
|
72
|
+
return `/__resolved__${id}`
|
|
73
|
+
// @TODO
|
|
74
|
+
// return `\0${id}`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (id.startsWith('virtual:md:')) {
|
|
78
|
+
return `/__resolved__${id}`
|
|
79
|
+
// @TODO
|
|
80
|
+
// return `\0${id}`
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
async load(id) {
|
|
85
|
+
if (id === VirtualFiles.RESOLVED_STORIES_ID) {
|
|
86
|
+
return VirtualFiles.resolvedStories(ctx)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (id === VirtualFiles.NOOP_ID) {
|
|
90
|
+
return VirtualFiles.noop()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (id === VirtualFiles.RESOLVED_CONFIG_ID) {
|
|
94
|
+
return VirtualFiles.resolvedConfig(ctx)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (id === VirtualFiles.RESOLVED_THEME_ID) {
|
|
98
|
+
return VirtualFiles.resolvedTheme(ctx)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (id === VirtualFiles.RESOLVED_SEARCH_TITLE_DATA_ID) {
|
|
102
|
+
return getSearchDataJS(await generateTitleSearchData(ctx))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (id === VirtualFiles.RESOLVED_SEARCH_DOCS_DATA_ID) {
|
|
106
|
+
return getSearchDataJS(await generateDocSearchData(ctx))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (id === VirtualFiles.RESOLVED_GENERATED_GLOBAL_SETUP) {
|
|
110
|
+
return VirtualFiles.resolvedGeneratedGlobalSetup(ctx)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (id.startsWith(VirtualFiles.RESOLVED_GENERATED_SETUP_CODE)) {
|
|
114
|
+
return VirtualFiles.resolvedGeneratedSetupCode(ctx, id)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (id === VirtualFiles.RESOLVED_SUPPORT_PLUGINS_CLIENT) {
|
|
118
|
+
return VirtualFiles.resolvedSupportPluginsClient(ctx)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (id === VirtualFiles.RESOLVED_SUPPORT_PLUGINS_COLLECT) {
|
|
122
|
+
return VirtualFiles.resolvedSupportPluginsCollect(ctx)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (id === VirtualFiles.RESOLVED_MARKDOWN_FILES) {
|
|
126
|
+
return VirtualFiles.resolvedMarkdownFiles(ctx)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (id === VirtualFiles.RESOLVED_COMMANDS) {
|
|
130
|
+
return VirtualFiles.resolvedCommands(ctx)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (id.startsWith('\0virtual:story:')) {
|
|
134
|
+
return VirtualFiles.story(ctx, id)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (id.startsWith('/__resolved__virtual:story-source:')) {
|
|
138
|
+
return VirtualFiles.storySource(ctx, id)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (id.startsWith('/__resolved__virtual:md:')) {
|
|
142
|
+
return VirtualFiles.markdown(ctx, id)
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
} as VitePlugin
|
|
146
|
+
}
|