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,385 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConfigMode,
|
|
3
|
+
Plugin,
|
|
4
|
+
PovesteConfig,
|
|
5
|
+
SupportMatchPattern,
|
|
6
|
+
} from '@poveste/shared'
|
|
7
|
+
import type { Context } from './context.js'
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import { fileURLToPath } from 'node:url'
|
|
10
|
+
import { createDefu } from 'defu'
|
|
11
|
+
import { createJiti } from 'jiti'
|
|
12
|
+
import path from 'pathe'
|
|
13
|
+
import pc from 'picocolors'
|
|
14
|
+
import {
|
|
15
|
+
mergeConfig as mergeViteConfig,
|
|
16
|
+
resolveConfig as resolveViteConfig,
|
|
17
|
+
} from 'vite'
|
|
18
|
+
import { tailwindTokens } from './builtin-plugins/tailwind-tokens.js'
|
|
19
|
+
import { vanillaSupport } from './builtin-plugins/vanilla-support/plugin.js'
|
|
20
|
+
import { defaultColors } from './colors.js'
|
|
21
|
+
import { findUp } from './util/find-up.js'
|
|
22
|
+
|
|
23
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
24
|
+
|
|
25
|
+
export function getDefaultConfig(): PovesteConfig {
|
|
26
|
+
return {
|
|
27
|
+
plugins: [
|
|
28
|
+
vanillaSupport(),
|
|
29
|
+
tailwindTokens(),
|
|
30
|
+
],
|
|
31
|
+
outDir: '.histoire/dist',
|
|
32
|
+
storyMatch: [
|
|
33
|
+
'**/*.story.vue',
|
|
34
|
+
'**/*.story.svelte',
|
|
35
|
+
],
|
|
36
|
+
storyIgnored: [
|
|
37
|
+
'**/node_modules/**',
|
|
38
|
+
'**/dist/**',
|
|
39
|
+
],
|
|
40
|
+
supportMatch: [],
|
|
41
|
+
tree: {
|
|
42
|
+
file: 'title',
|
|
43
|
+
order: 'asc',
|
|
44
|
+
},
|
|
45
|
+
theme: {
|
|
46
|
+
title: 'Poveste',
|
|
47
|
+
colors: {
|
|
48
|
+
primary: defaultColors.emerald,
|
|
49
|
+
gray: defaultColors.zinc,
|
|
50
|
+
},
|
|
51
|
+
defaultColorScheme: 'auto',
|
|
52
|
+
storeColorScheme: true,
|
|
53
|
+
darkClass: 'dark',
|
|
54
|
+
},
|
|
55
|
+
responsivePresets: [
|
|
56
|
+
{
|
|
57
|
+
label: 'Mobile (Small)',
|
|
58
|
+
width: 320,
|
|
59
|
+
height: 560,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: 'Mobile (Medium)',
|
|
63
|
+
width: 360,
|
|
64
|
+
height: 640,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: 'Mobile (Large)',
|
|
68
|
+
width: 414,
|
|
69
|
+
height: 896,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
label: 'Tablet',
|
|
73
|
+
width: 768,
|
|
74
|
+
height: 1024,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
label: 'Laptop (Small)',
|
|
78
|
+
width: 1024,
|
|
79
|
+
height: null,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
label: 'Laptop (Large)',
|
|
83
|
+
width: 1366,
|
|
84
|
+
height: null,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
label: 'Desktop',
|
|
88
|
+
width: 1920,
|
|
89
|
+
height: null,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: '4K',
|
|
93
|
+
width: 3840,
|
|
94
|
+
height: null,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
backgroundPresets: [
|
|
98
|
+
{
|
|
99
|
+
label: 'Transparent',
|
|
100
|
+
color: 'transparent',
|
|
101
|
+
contrastColor: '#333',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
label: 'White',
|
|
105
|
+
color: '#fff',
|
|
106
|
+
contrastColor: '#333',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
label: 'Light gray',
|
|
110
|
+
color: '#aaa',
|
|
111
|
+
contrastColor: '#000',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
label: 'Dark gray',
|
|
115
|
+
color: '#333',
|
|
116
|
+
contrastColor: '#fff',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
label: 'Black',
|
|
120
|
+
color: '#000',
|
|
121
|
+
contrastColor: '#eee',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
sandboxDarkClass: 'dark',
|
|
125
|
+
routerMode: 'history',
|
|
126
|
+
build: {
|
|
127
|
+
excludeFromVendorsChunk: [],
|
|
128
|
+
},
|
|
129
|
+
vite: (config) => {
|
|
130
|
+
// Remove vite:legacy plugins https://github.com/histoire-dev/histoire/issues/156
|
|
131
|
+
const index = config.plugins?.findIndex(plugin => Array.isArray(plugin)
|
|
132
|
+
&& typeof plugin[0] === 'object'
|
|
133
|
+
&& !Array.isArray(plugin[0])
|
|
134
|
+
// @ts-expect-error could have no property 'name'
|
|
135
|
+
&& plugin[0].name?.startsWith('vite:legacy'))
|
|
136
|
+
if (index !== -1) {
|
|
137
|
+
config.plugins?.splice(index, 1)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
build: {
|
|
142
|
+
lib: false,
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
viteIgnorePlugins: [],
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const configFileNames = [
|
|
151
|
+
'poveste.config.ts',
|
|
152
|
+
'poveste.config.js',
|
|
153
|
+
'.poveste.ts',
|
|
154
|
+
'.poveste.js',
|
|
155
|
+
// Back-compat with histoire — existing projects keep working as a drop-in.
|
|
156
|
+
'histoire.config.ts',
|
|
157
|
+
'histoire.config.js',
|
|
158
|
+
'.histoire.ts',
|
|
159
|
+
'.histoire.js',
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
export function resolveConfigFile(cwd: string = process.cwd(), configFile?: string): string {
|
|
163
|
+
if (configFile) {
|
|
164
|
+
// explicit config path is always resolved from cwd
|
|
165
|
+
return path.resolve(configFile)
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return findUp(cwd, configFileNames)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function loadConfigFile(configFile: string): Promise<Partial<PovesteConfig>> {
|
|
173
|
+
try {
|
|
174
|
+
const jiti = createJiti(__filename, {
|
|
175
|
+
moduleCache: false,
|
|
176
|
+
})
|
|
177
|
+
const result = await jiti.import(configFile, { default: true }) as Partial<PovesteConfig>
|
|
178
|
+
if (!result) {
|
|
179
|
+
throw new Error(`Expected default export in ${configFile}`)
|
|
180
|
+
}
|
|
181
|
+
return result
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
console.error(pc.red(`Error while loading ${configFile}`))
|
|
185
|
+
throw e
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export const mergeBuildConfig = createDefu((obj: any, key, value) => {
|
|
190
|
+
if (obj[key] && key === 'excludeFromVendorsChunk') {
|
|
191
|
+
obj[key] = [...obj[key], ...value]
|
|
192
|
+
return true
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
export const mergeConfig = createDefu((obj: any, key, value) => {
|
|
197
|
+
if (obj[key] && key === 'vite') {
|
|
198
|
+
const initialValue = obj[key]
|
|
199
|
+
|
|
200
|
+
// Convert to functions
|
|
201
|
+
const initialFn: (...args: any[]) => Promise<any> = typeof initialValue === 'function' ? initialValue : async () => initialValue
|
|
202
|
+
const valueFn: (...args: any[]) => Promise<any> = typeof value === 'function' ? value : async () => value
|
|
203
|
+
|
|
204
|
+
obj[key] = async (...args) => {
|
|
205
|
+
// `mergeViteConfig` doesn't accept functions so we need to call them
|
|
206
|
+
const initialResult = await initialFn(...args)
|
|
207
|
+
const valueResult = await valueFn(...args)
|
|
208
|
+
return mergeViteConfig(initialResult, valueResult)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return true
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (obj[key] && key === 'plugins') {
|
|
215
|
+
const initialValue = obj[key] as Plugin[]
|
|
216
|
+
const newValue = obj[key] = [...value]
|
|
217
|
+
const nameMap = newValue.reduce((map, plugin) => {
|
|
218
|
+
map[plugin.name] = true
|
|
219
|
+
return map
|
|
220
|
+
}, {})
|
|
221
|
+
for (const plugin of initialValue) {
|
|
222
|
+
if (!nameMap[plugin.name]) {
|
|
223
|
+
newValue.unshift(plugin)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return true
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (obj[key] && key === 'setupCode') {
|
|
230
|
+
obj[key] = [...obj[key], ...value]
|
|
231
|
+
return true
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (obj[key] && key === 'supportMatch') {
|
|
235
|
+
for (const item of value as SupportMatchPattern[]) {
|
|
236
|
+
const existing: SupportMatchPattern = obj[key].find(p => p.id === item.id)
|
|
237
|
+
if (existing) {
|
|
238
|
+
existing.patterns = [...existing.patterns, ...item.patterns]
|
|
239
|
+
existing.pluginIds = [...existing.pluginIds, ...item.pluginIds]
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
obj[key].push(item)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return true
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (obj[key] && key === 'build') {
|
|
249
|
+
obj[key] = mergeBuildConfig(obj[key], value)
|
|
250
|
+
return true
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// By default, arrays should be replaced
|
|
254
|
+
if (obj[key] && Array.isArray(obj[key])) {
|
|
255
|
+
obj[key] = value
|
|
256
|
+
return true
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
export async function resolveConfig(cwd: string = process.cwd(), mode: ConfigMode, configFile: string): Promise<PovesteConfig> {
|
|
261
|
+
let result: Partial<PovesteConfig>
|
|
262
|
+
const resolvedConfigFile = resolveConfigFile(cwd, configFile)
|
|
263
|
+
if (resolvedConfigFile) {
|
|
264
|
+
result = await loadConfigFile(resolvedConfigFile)
|
|
265
|
+
}
|
|
266
|
+
const viteConfig = await resolveViteConfig({}, 'serve')
|
|
267
|
+
const vitePovesteConfig = (viteConfig.poveste ?? viteConfig.histoire ?? {}) as PovesteConfig
|
|
268
|
+
|
|
269
|
+
const preUserConfig = mergeConfig(result, vitePovesteConfig)
|
|
270
|
+
const processedDefaultConfig = await processDefaultConfig(getDefaultConfig(), preUserConfig, mode, cwd)
|
|
271
|
+
|
|
272
|
+
return resolveConfigPlugins(mergeConfig(preUserConfig, processedDefaultConfig), mode)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function resolveConfigPlugins(config: PovesteConfig, mode: ConfigMode): Promise<PovesteConfig> {
|
|
276
|
+
for (const plugin of config.plugins) {
|
|
277
|
+
if (plugin.config) {
|
|
278
|
+
const result = await plugin.config(config, mode)
|
|
279
|
+
if (result) {
|
|
280
|
+
config = mergeConfig(result, config)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return config
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async function processDefaultConfig(defaultConfig: PovesteConfig, preUserConfig: PovesteConfig, mode: ConfigMode, _cwd: string): Promise<PovesteConfig> {
|
|
288
|
+
// Apply plugins
|
|
289
|
+
for (const plugin of [...defaultConfig.plugins, ...preUserConfig.plugins ?? []]) {
|
|
290
|
+
if (plugin.defaultConfig) {
|
|
291
|
+
const result = await plugin.defaultConfig(defaultConfig, mode)
|
|
292
|
+
if (result) {
|
|
293
|
+
defaultConfig = mergeConfig(result, defaultConfig)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return defaultConfig
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export async function processConfig(ctx: Context) {
|
|
301
|
+
const { config, root } = ctx
|
|
302
|
+
|
|
303
|
+
// Resolve files paths
|
|
304
|
+
|
|
305
|
+
const resolveFsPath = (file: string, force = false) => {
|
|
306
|
+
if (force || file.startsWith('./') || file.startsWith('../')) {
|
|
307
|
+
return path.resolve(root, file)
|
|
308
|
+
}
|
|
309
|
+
return file
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const fileCheck = (file: string, resolvedFile: string, configPathForError: string) => {
|
|
313
|
+
if (!file.startsWith('http') && !file.startsWith('@') && !fs.existsSync(resolvedFile)) {
|
|
314
|
+
console.warn(pc.yellow(`Poveste config: ${configPathForError} file ${file} does not exist (resolved to ${resolvedFile}), check for typos in the path`))
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
config.outDir = resolveFsPath(config.outDir, true)
|
|
319
|
+
|
|
320
|
+
// Theme
|
|
321
|
+
|
|
322
|
+
if (config.theme?.logo?.square) {
|
|
323
|
+
const file = config.theme.logo.square
|
|
324
|
+
config.theme.logo.square = resolveFsPath(file)
|
|
325
|
+
fileCheck(file, config.theme.logo.square, 'theme.logo.square')
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (config.theme?.logo?.light) {
|
|
329
|
+
const file = config.theme.logo.light
|
|
330
|
+
config.theme.logo.light = resolveFsPath(file)
|
|
331
|
+
fileCheck(file, config.theme.logo.light, 'theme.logo.light')
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (config.theme?.logo?.dark) {
|
|
335
|
+
const file = config.theme.logo.dark
|
|
336
|
+
config.theme.logo.dark = resolveFsPath(file)
|
|
337
|
+
fileCheck(file, config.theme.logo.dark, 'theme.logo.dark')
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (config.theme?.favicon) {
|
|
341
|
+
let file = config.theme.favicon
|
|
342
|
+
if (file.startsWith('/')) {
|
|
343
|
+
file = file.slice(1)
|
|
344
|
+
}
|
|
345
|
+
if (!file.startsWith('http')) {
|
|
346
|
+
const publicDir = path.resolve(ctx.resolvedViteConfig.root, ctx.resolvedViteConfig.publicDir)
|
|
347
|
+
// Resolve URL path
|
|
348
|
+
if (file.startsWith('./') || file.startsWith('../')) {
|
|
349
|
+
const resolvedFile = resolveFsPath(file, true)
|
|
350
|
+
const relativeFile = path.relative(publicDir, resolvedFile)
|
|
351
|
+
if (relativeFile.startsWith('..')) {
|
|
352
|
+
throw new Error(pc.red(`Poveste config: theme.favicon seems to target a file that is not in the vite 'public' directory: ${file} (resolved as ${resolvedFile})`))
|
|
353
|
+
}
|
|
354
|
+
if (!fs.existsSync(resolvedFile)) {
|
|
355
|
+
throw new Error(pc.red(`Poveste config: theme.favicon seems to target a file that does not exist: ${file} (resolved as ${resolvedFile})`))
|
|
356
|
+
}
|
|
357
|
+
config.theme.favicon = relativeFile
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
// Check if URL path is valid
|
|
361
|
+
const resolvedFile = path.resolve(publicDir, file)
|
|
362
|
+
if (!fs.existsSync(resolvedFile)) {
|
|
363
|
+
throw new Error(pc.red(`Poveste config: theme.favicon seems to target a file that does not exist: ${file} (resolved as ${resolvedFile}).\nThe favicon file should be placed in the vite 'public' directory.\nExample: if the file is in <project>/public/img/favicon.ico, you can put 'img/favicon.ico' or './public/img/favicon.ico'.`))
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export function defineConfig(config: Partial<PovesteConfig>) {
|
|
371
|
+
return config
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
declare module 'vite' {
|
|
375
|
+
interface UserConfig {
|
|
376
|
+
/**
|
|
377
|
+
* Poveste configuration
|
|
378
|
+
*/
|
|
379
|
+
poveste?: Partial<PovesteConfig>
|
|
380
|
+
/**
|
|
381
|
+
* @deprecated Use `poveste` instead. Kept for drop-in compat with histoire.
|
|
382
|
+
*/
|
|
383
|
+
histoire?: Partial<PovesteConfig>
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConfigMode,
|
|
3
|
+
FinalSupportPlugin,
|
|
4
|
+
PluginCommand,
|
|
5
|
+
PovesteConfig,
|
|
6
|
+
ServerMarkdownFile,
|
|
7
|
+
ServerStoryFile,
|
|
8
|
+
} from '@poveste/shared'
|
|
9
|
+
import type { ResolvedConfig } from 'vite'
|
|
10
|
+
import { resolveConfig as resolveViteConfig } from 'vite'
|
|
11
|
+
import { processConfig, resolveConfig } from './config.js'
|
|
12
|
+
import { mergeHistoireViteConfig } from './vite.js'
|
|
13
|
+
|
|
14
|
+
export interface Context {
|
|
15
|
+
root: string
|
|
16
|
+
config: PovesteConfig
|
|
17
|
+
resolvedViteConfig: ResolvedConfig
|
|
18
|
+
mode: ConfigMode
|
|
19
|
+
storyFiles: ServerStoryFile[]
|
|
20
|
+
supportPlugins: FinalSupportPlugin[]
|
|
21
|
+
markdownFiles: ServerMarkdownFile[]
|
|
22
|
+
registeredCommands?: PluginCommand[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CreateContextOptions {
|
|
26
|
+
mode: Context['mode']
|
|
27
|
+
configFile?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function createContext(options: CreateContextOptions): Promise<Context> {
|
|
31
|
+
const config = await resolveConfig(process.cwd(), options.mode, options.configFile)
|
|
32
|
+
const command = options.mode === 'dev' ? 'serve' : 'build'
|
|
33
|
+
const viteConfig = await resolveViteConfig({}, command)
|
|
34
|
+
|
|
35
|
+
const supportPlugins = config.plugins.map(p => p.supportPlugin).filter(Boolean)
|
|
36
|
+
|
|
37
|
+
const ctx = {
|
|
38
|
+
root: viteConfig.root,
|
|
39
|
+
config,
|
|
40
|
+
resolvedViteConfig: null,
|
|
41
|
+
mode: options.mode,
|
|
42
|
+
storyFiles: [],
|
|
43
|
+
supportPlugins,
|
|
44
|
+
markdownFiles: [],
|
|
45
|
+
registeredCommands: [],
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
ctx.resolvedViteConfig = await mergeHistoireViteConfig(viteConfig as unknown, ctx)
|
|
49
|
+
|
|
50
|
+
await processConfig(ctx)
|
|
51
|
+
|
|
52
|
+
// List commands
|
|
53
|
+
for (const plugin of ctx.config.plugins) {
|
|
54
|
+
if (plugin.commands?.length) {
|
|
55
|
+
ctx.registeredCommands.push(...plugin.commands)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return ctx
|
|
60
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code from vitest https://github.com/antfu-sponsors/vitest/blob/6066fdbf3b1d17021aac20591b5ef3603056fa5f/src/integrations/dom/keys.ts by @antfu and @patak
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
|
|
6
|
+
|
|
7
|
+
const LIVING_KEYS = [
|
|
8
|
+
'DOMException',
|
|
9
|
+
'URL',
|
|
10
|
+
'URLSearchParams',
|
|
11
|
+
'EventTarget',
|
|
12
|
+
'NamedNodeMap',
|
|
13
|
+
'Node',
|
|
14
|
+
'Attr',
|
|
15
|
+
'Element',
|
|
16
|
+
'DocumentFragment',
|
|
17
|
+
'DOMImplementation',
|
|
18
|
+
'Document',
|
|
19
|
+
'XMLDocument',
|
|
20
|
+
'CharacterData',
|
|
21
|
+
'Text',
|
|
22
|
+
'CDATASection',
|
|
23
|
+
'ProcessingInstruction',
|
|
24
|
+
'Comment',
|
|
25
|
+
'DocumentType',
|
|
26
|
+
'NodeList',
|
|
27
|
+
'RadioNodeList',
|
|
28
|
+
'HTMLCollection',
|
|
29
|
+
'HTMLOptionsCollection',
|
|
30
|
+
'DOMStringMap',
|
|
31
|
+
'DOMTokenList',
|
|
32
|
+
'StyleSheetList',
|
|
33
|
+
'HTMLElement',
|
|
34
|
+
'HTMLHeadElement',
|
|
35
|
+
'HTMLTitleElement',
|
|
36
|
+
'HTMLBaseElement',
|
|
37
|
+
'HTMLLinkElement',
|
|
38
|
+
'HTMLMetaElement',
|
|
39
|
+
'HTMLStyleElement',
|
|
40
|
+
'HTMLBodyElement',
|
|
41
|
+
'HTMLHeadingElement',
|
|
42
|
+
'HTMLParagraphElement',
|
|
43
|
+
'HTMLHRElement',
|
|
44
|
+
'HTMLPreElement',
|
|
45
|
+
'HTMLUListElement',
|
|
46
|
+
'HTMLOListElement',
|
|
47
|
+
'HTMLLIElement',
|
|
48
|
+
'HTMLMenuElement',
|
|
49
|
+
'HTMLDListElement',
|
|
50
|
+
'HTMLDivElement',
|
|
51
|
+
'HTMLAnchorElement',
|
|
52
|
+
'HTMLAreaElement',
|
|
53
|
+
'HTMLBRElement',
|
|
54
|
+
'HTMLButtonElement',
|
|
55
|
+
'HTMLCanvasElement',
|
|
56
|
+
'HTMLDataElement',
|
|
57
|
+
'HTMLDataListElement',
|
|
58
|
+
'HTMLDetailsElement',
|
|
59
|
+
'HTMLDialogElement',
|
|
60
|
+
'HTMLDirectoryElement',
|
|
61
|
+
'HTMLFieldSetElement',
|
|
62
|
+
'HTMLFontElement',
|
|
63
|
+
'HTMLFormElement',
|
|
64
|
+
'HTMLHtmlElement',
|
|
65
|
+
'HTMLImageElement',
|
|
66
|
+
'HTMLInputElement',
|
|
67
|
+
'HTMLLabelElement',
|
|
68
|
+
'HTMLLegendElement',
|
|
69
|
+
'HTMLMapElement',
|
|
70
|
+
'HTMLMarqueeElement',
|
|
71
|
+
'HTMLMediaElement',
|
|
72
|
+
'HTMLMeterElement',
|
|
73
|
+
'HTMLModElement',
|
|
74
|
+
'HTMLOptGroupElement',
|
|
75
|
+
'HTMLOptionElement',
|
|
76
|
+
'HTMLOutputElement',
|
|
77
|
+
'HTMLPictureElement',
|
|
78
|
+
'HTMLProgressElement',
|
|
79
|
+
'HTMLQuoteElement',
|
|
80
|
+
'HTMLScriptElement',
|
|
81
|
+
'HTMLSelectElement',
|
|
82
|
+
'HTMLSlotElement',
|
|
83
|
+
'HTMLSourceElement',
|
|
84
|
+
'HTMLSpanElement',
|
|
85
|
+
'HTMLTableCaptionElement',
|
|
86
|
+
'HTMLTableCellElement',
|
|
87
|
+
'HTMLTableColElement',
|
|
88
|
+
'HTMLTableElement',
|
|
89
|
+
'HTMLTimeElement',
|
|
90
|
+
'HTMLTableRowElement',
|
|
91
|
+
'HTMLTableSectionElement',
|
|
92
|
+
'HTMLTemplateElement',
|
|
93
|
+
'HTMLTextAreaElement',
|
|
94
|
+
'HTMLUnknownElement',
|
|
95
|
+
'HTMLFrameElement',
|
|
96
|
+
'HTMLFrameSetElement',
|
|
97
|
+
'HTMLIFrameElement',
|
|
98
|
+
'HTMLEmbedElement',
|
|
99
|
+
'HTMLObjectElement',
|
|
100
|
+
'HTMLParamElement',
|
|
101
|
+
'HTMLVideoElement',
|
|
102
|
+
'HTMLAudioElement',
|
|
103
|
+
'HTMLTrackElement',
|
|
104
|
+
'HTMLFormControlsCollection',
|
|
105
|
+
'SVGElement',
|
|
106
|
+
'SVGGraphicsElement',
|
|
107
|
+
'SVGSVGElement',
|
|
108
|
+
'SVGTitleElement',
|
|
109
|
+
'SVGAnimatedString',
|
|
110
|
+
'SVGNumber',
|
|
111
|
+
'SVGStringList',
|
|
112
|
+
'Event',
|
|
113
|
+
'CloseEvent',
|
|
114
|
+
'CustomEvent',
|
|
115
|
+
'MessageEvent',
|
|
116
|
+
'ErrorEvent',
|
|
117
|
+
'HashChangeEvent',
|
|
118
|
+
'PopStateEvent',
|
|
119
|
+
'StorageEvent',
|
|
120
|
+
'ProgressEvent',
|
|
121
|
+
'PageTransitionEvent',
|
|
122
|
+
'UIEvent',
|
|
123
|
+
'FocusEvent',
|
|
124
|
+
'InputEvent',
|
|
125
|
+
'MouseEvent',
|
|
126
|
+
'KeyboardEvent',
|
|
127
|
+
'TouchEvent',
|
|
128
|
+
'CompositionEvent',
|
|
129
|
+
'WheelEvent',
|
|
130
|
+
'BarProp',
|
|
131
|
+
'External',
|
|
132
|
+
'Location',
|
|
133
|
+
'History',
|
|
134
|
+
'Screen',
|
|
135
|
+
'Crypto',
|
|
136
|
+
'Performance',
|
|
137
|
+
'Navigator',
|
|
138
|
+
'PluginArray',
|
|
139
|
+
'MimeTypeArray',
|
|
140
|
+
'Plugin',
|
|
141
|
+
'MimeType',
|
|
142
|
+
'FileReader',
|
|
143
|
+
'Blob',
|
|
144
|
+
'File',
|
|
145
|
+
'FileList',
|
|
146
|
+
'ValidityState',
|
|
147
|
+
'DOMParser',
|
|
148
|
+
'XMLSerializer',
|
|
149
|
+
'FormData',
|
|
150
|
+
'XMLHttpRequestEventTarget',
|
|
151
|
+
'XMLHttpRequestUpload',
|
|
152
|
+
'XMLHttpRequest',
|
|
153
|
+
'WebSocket',
|
|
154
|
+
'NodeFilter',
|
|
155
|
+
'NodeIterator',
|
|
156
|
+
'TreeWalker',
|
|
157
|
+
'AbstractRange',
|
|
158
|
+
'Range',
|
|
159
|
+
'StaticRange',
|
|
160
|
+
'Selection',
|
|
161
|
+
'Storage',
|
|
162
|
+
'CustomElementRegistry',
|
|
163
|
+
'ShadowRoot',
|
|
164
|
+
'MutationObserver',
|
|
165
|
+
'MutationRecord',
|
|
166
|
+
'Headers',
|
|
167
|
+
'AbortController',
|
|
168
|
+
'AbortSignal',
|
|
169
|
+
'ArrayBuffer',
|
|
170
|
+
|
|
171
|
+
// not specified in docs, but is available
|
|
172
|
+
'Image',
|
|
173
|
+
'Audio',
|
|
174
|
+
'Option',
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
const OTHER_KEYS = [
|
|
178
|
+
'addEventListener',
|
|
179
|
+
'alert',
|
|
180
|
+
'blur',
|
|
181
|
+
'cancelAnimationFrame',
|
|
182
|
+
/* 'clearInterval', */
|
|
183
|
+
/* 'clearTimeout', */
|
|
184
|
+
'close',
|
|
185
|
+
'confirm',
|
|
186
|
+
/* 'console', */
|
|
187
|
+
'createPopup',
|
|
188
|
+
'dispatchEvent',
|
|
189
|
+
'document',
|
|
190
|
+
'focus',
|
|
191
|
+
'frames',
|
|
192
|
+
'getComputedStyle',
|
|
193
|
+
'history',
|
|
194
|
+
'innerHeight',
|
|
195
|
+
'innerWidth',
|
|
196
|
+
'length',
|
|
197
|
+
'location',
|
|
198
|
+
'matchMedia',
|
|
199
|
+
'moveBy',
|
|
200
|
+
'moveTo',
|
|
201
|
+
'name',
|
|
202
|
+
'navigator',
|
|
203
|
+
'open',
|
|
204
|
+
'outerHeight',
|
|
205
|
+
'outerWidth',
|
|
206
|
+
'pageXOffset',
|
|
207
|
+
'pageYOffset',
|
|
208
|
+
'parent',
|
|
209
|
+
'postMessage',
|
|
210
|
+
'print',
|
|
211
|
+
'prompt',
|
|
212
|
+
'removeEventListener',
|
|
213
|
+
'requestAnimationFrame',
|
|
214
|
+
'resizeBy',
|
|
215
|
+
'resizeTo',
|
|
216
|
+
'screen',
|
|
217
|
+
'screenLeft',
|
|
218
|
+
'screenTop',
|
|
219
|
+
'screenX',
|
|
220
|
+
'screenY',
|
|
221
|
+
'scroll',
|
|
222
|
+
'scrollBy',
|
|
223
|
+
'scrollLeft',
|
|
224
|
+
'scrollTo',
|
|
225
|
+
'scrollTop',
|
|
226
|
+
'scrollX',
|
|
227
|
+
'scrollY',
|
|
228
|
+
'self',
|
|
229
|
+
/* 'setInterval', */
|
|
230
|
+
/* 'setTimeout', */
|
|
231
|
+
'stop',
|
|
232
|
+
/* 'toString', */
|
|
233
|
+
'top',
|
|
234
|
+
'Window',
|
|
235
|
+
'window',
|
|
236
|
+
]
|
|
237
|
+
|
|
238
|
+
export const KEYS = LIVING_KEYS.concat(OTHER_KEYS)
|