histoire 0.1.4 → 0.2.1
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 +1 -1
- package/dist/client/app/components/app/AppHeader.vue +1 -0
- package/dist/client/app/components/base/BaseCheckbox.vue +76 -0
- package/dist/client/app/components/sandbox/lib.d.ts +2 -0
- package/dist/client/app/components/sandbox/lib.js +6 -0
- package/dist/client/app/components/sandbox/lib.ts +8 -0
- package/dist/client/app/components/search/SearchItem.vue +4 -1
- package/dist/client/app/components/search/SearchModal.vue +4 -4
- package/dist/client/app/components/story/StoryControls.vue +1 -1
- package/dist/client/app/components/story/StoryDocs.vue +1 -0
- package/dist/client/app/components/story/StoryListFolder.vue +1 -1
- package/dist/client/app/components/story/StoryListItem.vue +4 -1
- package/dist/client/app/components/story/StoryResponsivePreview.vue +3 -4
- package/dist/client/app/components/story/StorySidePanel.vue +1 -0
- package/dist/client/app/components/story/StorySourceCode.vue +4 -1
- package/dist/client/app/components/story/StoryVariantListItem.vue +4 -1
- package/dist/client/app/components/story/StoryVariantSingleView.vue +20 -160
- package/dist/client/app/components/story/StoryViewer.vue +19 -1
- package/dist/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
- package/dist/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
- package/dist/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
- package/dist/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
- package/dist/client/app/stores/story.d.ts +6 -6
- package/dist/client/app/stores/story.js +2 -1
- package/dist/client/app/stores/story.ts +5 -1
- package/dist/client/app/style/main.pcss +5 -5
- package/dist/client/app/types.d.ts +1 -1
- package/dist/client/app/types.ts +1 -1
- package/dist/node/bin.js +7 -0
- package/dist/node/build.js +1 -1
- package/dist/node/{collect.d.ts → collect/index.d.ts} +2 -2
- package/dist/node/{collect.js → collect/index.js} +37 -27
- package/dist/node/collect/worker.d.ts +14 -0
- package/dist/node/collect/worker.js +36 -0
- package/dist/node/commands/preview.d.ts +4 -0
- package/dist/node/commands/preview.js +36 -0
- package/dist/node/server.js +1 -1
- package/dist/node/tree.js +24 -4
- package/dist/node/types.d.ts +1 -1
- package/dist/style.css +97 -53
- package/package.json +7 -3
- package/src/client/app/App.vue +1 -1
- package/src/client/app/components/app/AppHeader.vue +1 -0
- package/src/client/app/components/base/BaseCheckbox.vue +76 -0
- package/src/client/app/components/sandbox/lib.ts +8 -0
- package/src/client/app/components/search/SearchItem.vue +4 -1
- package/src/client/app/components/search/SearchModal.vue +4 -4
- package/src/client/app/components/story/StoryControls.vue +1 -1
- package/src/client/app/components/story/StoryDocs.vue +1 -0
- package/src/client/app/components/story/StoryListFolder.vue +1 -1
- package/src/client/app/components/story/StoryListItem.vue +4 -1
- package/src/client/app/components/story/StoryResponsivePreview.vue +3 -4
- package/src/client/app/components/story/StorySidePanel.vue +1 -0
- package/src/client/app/components/story/StorySourceCode.vue +4 -1
- package/src/client/app/components/story/StoryVariantListItem.vue +4 -1
- package/src/client/app/components/story/StoryVariantSingleView.vue +20 -160
- package/src/client/app/components/story/StoryViewer.vue +19 -1
- package/src/client/app/components/story/variant/StoryVariantBackground.vue +67 -0
- package/src/client/app/components/story/variant/StoryVariantNewTab.vue +29 -0
- package/src/client/app/components/story/variant/StoryVariantResponsiveSize.vue +82 -0
- package/src/client/app/components/story/variant/StoryVariantTitle.vue +21 -0
- package/src/client/app/stores/story.ts +5 -1
- package/src/client/app/style/main.pcss +5 -5
- package/src/client/app/types.ts +1 -1
- package/src/node/bin.ts +8 -0
- package/src/node/build.ts +1 -1
- package/src/node/{collect.ts → collect/index.ts} +48 -30
- package/src/node/collect/worker.ts +61 -0
- package/src/node/commands/preview.ts +50 -0
- package/src/node/server.ts +1 -1
- package/src/node/tree.spec.ts +61 -0
- package/src/node/tree.ts +29 -5
- package/src/node/types.ts +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import { histoireConfig } from '../../../util/config'
|
|
4
|
+
import { usePreviewSettings } from '../../../util/preview-settings'
|
|
5
|
+
import BaseCheckbox from '../../base/BaseCheckbox.vue'
|
|
6
|
+
|
|
7
|
+
const settings = usePreviewSettings()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<!-- Responsive size -->
|
|
12
|
+
<VDropdown
|
|
13
|
+
placement="bottom-end"
|
|
14
|
+
:skidding="6"
|
|
15
|
+
:disabled="!histoireConfig.responsivePresets?.length"
|
|
16
|
+
class="htw-h-full htw-flex-none"
|
|
17
|
+
>
|
|
18
|
+
<div
|
|
19
|
+
v-tooltip="'Responsive sizes'"
|
|
20
|
+
class="htw-flex htw-items-center htw-gap-1 htw-h-full htw-px-2"
|
|
21
|
+
:class="{
|
|
22
|
+
'htw-cursor-pointer hover:htw-text-primary-500': histoireConfig.responsivePresets?.length,
|
|
23
|
+
}"
|
|
24
|
+
>
|
|
25
|
+
<Icon
|
|
26
|
+
icon="carbon:devices"
|
|
27
|
+
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
28
|
+
/>
|
|
29
|
+
<Icon
|
|
30
|
+
icon="carbon:caret-down"
|
|
31
|
+
class="htw-w-4 htw-h-4 htw-opacity-50"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<template #popper="{ hide }">
|
|
36
|
+
<div class="htw-flex htw-flex-col htw-items-stretch">
|
|
37
|
+
<BaseCheckbox v-model="settings.rotate">
|
|
38
|
+
Rotate
|
|
39
|
+
</BaseCheckbox>
|
|
40
|
+
|
|
41
|
+
<div class="htw-flex htw-gap-2 htw-px-4 htw-py-3">
|
|
42
|
+
<input
|
|
43
|
+
v-model.number="settings.responsiveWidth"
|
|
44
|
+
v-tooltip="'Responsive width (px)'"
|
|
45
|
+
type="number"
|
|
46
|
+
class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
|
|
47
|
+
step="16"
|
|
48
|
+
placeholder="Auto"
|
|
49
|
+
>
|
|
50
|
+
<span class="htw-opacity-50">x</span>
|
|
51
|
+
<input
|
|
52
|
+
v-model.number="settings.responsiveHeight"
|
|
53
|
+
v-tooltip="'Responsive height (px)'"
|
|
54
|
+
type="number"
|
|
55
|
+
class="htw-bg-transparent htw-border htw-border-gray-200 dark:htw-border-gray-850 htw-rounded htw-w-20 htw-opacity-50 focus:htw-opacity-100 htw-flex-1 htw-min-w-0"
|
|
56
|
+
step="16"
|
|
57
|
+
placeholder="Auto"
|
|
58
|
+
>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<button
|
|
62
|
+
v-for="(preset, index) in histoireConfig.responsivePresets"
|
|
63
|
+
:key="index"
|
|
64
|
+
class="htw-px-4 htw-py-3 htw-cursor-pointer htw-text-left htw-flex htw-gap-4"
|
|
65
|
+
:class="[
|
|
66
|
+
settings.responsiveWidth === preset.width && settings.responsiveHeight === preset.height
|
|
67
|
+
? 'htw-bg-primary-500 hover:htw-bg-primary-600 htw-text-white dark:htw-text-black'
|
|
68
|
+
: 'htw-bg-transparent hover:htw-bg-primary-100 dark:hover:htw-bg-primary-700',
|
|
69
|
+
]"
|
|
70
|
+
@click="settings.responsiveWidth = preset.width;settings.responsiveHeight = preset.height;hide()"
|
|
71
|
+
>
|
|
72
|
+
{{ preset.label }}
|
|
73
|
+
<span class="htw-ml-auto htw-opacity-70 htw-flex htw-gap-1">
|
|
74
|
+
<span v-if="preset.width">{{ preset.width }}<span v-if="!preset.height">px</span></span>
|
|
75
|
+
<span v-if="preset.width && preset.height">x</span>
|
|
76
|
+
<span v-if="preset.height">{{ preset.height }}<span v-if="!preset.width">px</span></span>
|
|
77
|
+
</span>
|
|
78
|
+
</button>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
81
|
+
</VDropdown>
|
|
82
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { Icon } from '@iconify/vue'
|
|
3
|
+
import type { Variant } from '../../../types'
|
|
4
|
+
|
|
5
|
+
defineProps<{
|
|
6
|
+
variant: Variant
|
|
7
|
+
}>()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div class="htw-flex htw-items-center htw-gap-1 htw-text-gray-500 htw-flex-1 htw-truncate htw-min-w-0">
|
|
12
|
+
<Icon
|
|
13
|
+
:icon="variant.icon ?? 'carbon:cube'"
|
|
14
|
+
class="base-list-item-link-icon htw-w-4 htw-h-4 htw-opacity-50"
|
|
15
|
+
:class="[
|
|
16
|
+
variant.iconColor ? 'bind-icon-color' : 'htw-text-gray-500',
|
|
17
|
+
]"
|
|
18
|
+
/>
|
|
19
|
+
<span>{{ variant.title }}</span>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
@@ -18,7 +18,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
|
|
|
18
18
|
type: "single";
|
|
19
19
|
} | {
|
|
20
20
|
type: "grid";
|
|
21
|
-
width
|
|
21
|
+
width?: string | number;
|
|
22
22
|
};
|
|
23
23
|
icon?: string;
|
|
24
24
|
iconColor?: string;
|
|
@@ -60,7 +60,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
|
|
|
60
60
|
type: "single";
|
|
61
61
|
} | {
|
|
62
62
|
type: "grid";
|
|
63
|
-
width
|
|
63
|
+
width?: string | number;
|
|
64
64
|
};
|
|
65
65
|
icon?: string;
|
|
66
66
|
iconColor?: string;
|
|
@@ -115,7 +115,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
|
|
|
115
115
|
type: "single";
|
|
116
116
|
} | {
|
|
117
117
|
type: "grid";
|
|
118
|
-
width
|
|
118
|
+
width?: string | number;
|
|
119
119
|
};
|
|
120
120
|
icon?: string;
|
|
121
121
|
iconColor?: string;
|
|
@@ -157,7 +157,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
|
|
|
157
157
|
type: "single";
|
|
158
158
|
} | {
|
|
159
159
|
type: "grid";
|
|
160
|
-
width
|
|
160
|
+
width?: string | number;
|
|
161
161
|
};
|
|
162
162
|
icon?: string;
|
|
163
163
|
iconColor?: string;
|
|
@@ -212,7 +212,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
|
|
|
212
212
|
type: "single";
|
|
213
213
|
} | {
|
|
214
214
|
type: "grid";
|
|
215
|
-
width
|
|
215
|
+
width?: string | number;
|
|
216
216
|
};
|
|
217
217
|
icon?: string;
|
|
218
218
|
iconColor?: string;
|
|
@@ -254,7 +254,7 @@ export declare const useStoryStore: import("pinia").StoreDefinition<"story", imp
|
|
|
254
254
|
type: "single";
|
|
255
255
|
} | {
|
|
256
256
|
type: "grid";
|
|
257
|
-
width
|
|
257
|
+
width?: string | number;
|
|
258
258
|
};
|
|
259
259
|
icon?: string;
|
|
260
260
|
iconColor?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineStore } from 'pinia';
|
|
2
2
|
import { computed, ref, watch } from 'vue';
|
|
3
3
|
import { router } from '../router';
|
|
4
|
+
import { useStorage } from '@vueuse/core';
|
|
4
5
|
export const useStoryStore = defineStore('story', () => {
|
|
5
6
|
const stories = ref([]);
|
|
6
7
|
function setStories(value) {
|
|
@@ -8,7 +9,7 @@ export const useStoryStore = defineStore('story', () => {
|
|
|
8
9
|
}
|
|
9
10
|
const currentStory = computed(() => stories.value.find(s => s.id === router.currentRoute.value.params.storyId));
|
|
10
11
|
const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId));
|
|
11
|
-
const openedFolders =
|
|
12
|
+
const openedFolders = useStorage('_histoire-tree-state', new Map());
|
|
12
13
|
function getStringPath(path) {
|
|
13
14
|
return path.join('␜');
|
|
14
15
|
}
|
|
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
|
|
|
2
2
|
import { computed, ref, watch } from 'vue'
|
|
3
3
|
import { router } from '../router'
|
|
4
4
|
import { Story } from '../types'
|
|
5
|
+
import { useStorage } from '@vueuse/core'
|
|
5
6
|
|
|
6
7
|
export const useStoryStore = defineStore('story', () => {
|
|
7
8
|
const stories = ref<Story[]>([])
|
|
@@ -13,7 +14,10 @@ export const useStoryStore = defineStore('story', () => {
|
|
|
13
14
|
|
|
14
15
|
const currentVariant = computed(() => currentStory.value?.variants.find(v => v.id === router.currentRoute.value.query.variantId))
|
|
15
16
|
|
|
16
|
-
const openedFolders =
|
|
17
|
+
const openedFolders = useStorage<Map<string, boolean>>(
|
|
18
|
+
'_histoire-tree-state',
|
|
19
|
+
new Map(),
|
|
20
|
+
)
|
|
17
21
|
|
|
18
22
|
function getStringPath (path: Array<string>) {
|
|
19
23
|
return path.join('␜')
|
|
@@ -48,14 +48,14 @@ body,
|
|
|
48
48
|
font-family: 'Lato', sans-serif;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
body {
|
|
52
|
+
font-size: 18px;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
@media (min-width: 640px) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
body {
|
|
57
|
+
font-size: 14px;
|
|
58
|
+
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
.__histoire-sandbox {
|
package/dist/client/app/types.ts
CHANGED
package/dist/node/bin.js
CHANGED
|
@@ -19,4 +19,11 @@ program.command('build')
|
|
|
19
19
|
const { buildCommand } = await import('./commands/build.js');
|
|
20
20
|
return buildCommand();
|
|
21
21
|
});
|
|
22
|
+
program.command('preview')
|
|
23
|
+
.describe('preview the built directory')
|
|
24
|
+
.option('-p, --port <port>', 'Listening port of the server')
|
|
25
|
+
.action(async (options) => {
|
|
26
|
+
const { previewCommand } = await import('./commands/preview.js');
|
|
27
|
+
return previewCommand(options);
|
|
28
|
+
});
|
|
22
29
|
program.parse(process.argv);
|
package/dist/node/build.js
CHANGED
|
@@ -7,7 +7,7 @@ import { performance } from 'perf_hooks';
|
|
|
7
7
|
import { APP_PATH } from './alias.js';
|
|
8
8
|
import { createVitePlugins } from './plugin.js';
|
|
9
9
|
import { findAllStories } from './stories.js';
|
|
10
|
-
import { useCollectStories } from './collect.js';
|
|
10
|
+
import { useCollectStories } from './collect/index.js';
|
|
11
11
|
const PRELOAD_MODULES = [
|
|
12
12
|
'vendor',
|
|
13
13
|
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ViteDevServer } from 'vite';
|
|
2
|
-
import type { StoryFile } from '
|
|
3
|
-
import type { Context } from '
|
|
2
|
+
import type { StoryFile } from '../types.js';
|
|
3
|
+
import type { Context } from '../context.js';
|
|
4
4
|
export interface UseCollectStoriesOptions {
|
|
5
5
|
server: ViteDevServer;
|
|
6
6
|
throws?: boolean;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MessageChannel } from 'worker_threads';
|
|
2
2
|
import { ViteNodeServer } from 'vite-node/server';
|
|
3
|
-
import {
|
|
4
|
-
import { dirname, resolve, relative } from 'pathe';
|
|
3
|
+
import { relative } from 'pathe';
|
|
5
4
|
import pc from 'picocolors';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import Tinypool from 'tinypool';
|
|
6
|
+
import { createBirpc } from 'birpc';
|
|
7
|
+
import { createPath } from '../tree.js';
|
|
9
8
|
export function useCollectStories(options, ctx) {
|
|
10
9
|
const { server } = options;
|
|
11
|
-
const { destroy: destroyDomEnv } = createDomEnv();
|
|
12
10
|
const node = new ViteNodeServer(server, {
|
|
13
11
|
deps: {
|
|
14
12
|
inline: [
|
|
@@ -16,31 +14,43 @@ export function useCollectStories(options, ctx) {
|
|
|
16
14
|
],
|
|
17
15
|
},
|
|
18
16
|
});
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Alias
|
|
24
|
-
if (id.endsWith('vue.runtime.esm-bundler.js')) {
|
|
25
|
-
id = 'vue';
|
|
26
|
-
}
|
|
27
|
-
return node.fetchModule(id);
|
|
28
|
-
},
|
|
29
|
-
resolveId(id, importer) {
|
|
30
|
-
return node.resolveId(id, importer);
|
|
31
|
-
},
|
|
17
|
+
const threadPool = new Tinypool({
|
|
18
|
+
filename: new URL('./worker.js', import.meta.url).href,
|
|
19
|
+
// WebContainer compatibility (Stackblitz)
|
|
20
|
+
useAtomics: false,
|
|
32
21
|
});
|
|
33
22
|
function clearCache() {
|
|
34
23
|
node.fetchCache.clear();
|
|
35
|
-
|
|
24
|
+
}
|
|
25
|
+
function createChannel() {
|
|
26
|
+
const channel = new MessageChannel();
|
|
27
|
+
const port = channel.port2;
|
|
28
|
+
const workerPort = channel.port1;
|
|
29
|
+
createBirpc({
|
|
30
|
+
fetchModule: (id) => node.fetchModule(id),
|
|
31
|
+
resolveId: (id, importer) => node.resolveId(id, importer),
|
|
32
|
+
}, {
|
|
33
|
+
post: data => port.postMessage(data),
|
|
34
|
+
on: data => port.on('message', data),
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
port,
|
|
38
|
+
workerPort,
|
|
39
|
+
};
|
|
36
40
|
}
|
|
37
41
|
async function executeStoryFile(storyFile) {
|
|
38
42
|
try {
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const { workerPort } = createChannel();
|
|
44
|
+
const { storyData } = await threadPool.run({
|
|
45
|
+
root: server.config.root,
|
|
46
|
+
base: server.config.base,
|
|
47
|
+
storyFile,
|
|
48
|
+
port: workerPort,
|
|
49
|
+
}, {
|
|
50
|
+
transferList: [
|
|
51
|
+
workerPort,
|
|
52
|
+
],
|
|
53
|
+
});
|
|
44
54
|
if (storyData.length === 0) {
|
|
45
55
|
console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`));
|
|
46
56
|
return;
|
|
@@ -64,7 +74,7 @@ export function useCollectStories(options, ctx) {
|
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
76
|
async function destroy() {
|
|
67
|
-
|
|
77
|
+
await threadPool.destroy();
|
|
68
78
|
}
|
|
69
79
|
return {
|
|
70
80
|
clearCache,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { MessagePort } from 'worker_threads';
|
|
3
|
+
import type { StoryFile, Story } from '../types.js';
|
|
4
|
+
export interface Payload {
|
|
5
|
+
root: string;
|
|
6
|
+
base: string;
|
|
7
|
+
port: MessagePort;
|
|
8
|
+
storyFile: StoryFile;
|
|
9
|
+
}
|
|
10
|
+
export interface ReturnData {
|
|
11
|
+
storyData: Story[];
|
|
12
|
+
}
|
|
13
|
+
declare const _default: (payload: Payload) => Promise<ReturnData>;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { ViteNodeRunner } from 'vite-node/client';
|
|
3
|
+
import { createBirpc } from 'birpc';
|
|
4
|
+
import { dirname, resolve } from 'pathe';
|
|
5
|
+
import { createDomEnv } from '../dom/env.js';
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
export default async (payload) => {
|
|
8
|
+
const rpc = createBirpc({}, {
|
|
9
|
+
post: data => payload.port.postMessage(data),
|
|
10
|
+
on: data => payload.port.on('message', data),
|
|
11
|
+
});
|
|
12
|
+
const runner = new ViteNodeRunner({
|
|
13
|
+
root: payload.root,
|
|
14
|
+
base: payload.base,
|
|
15
|
+
fetchModule(id) {
|
|
16
|
+
// Alias
|
|
17
|
+
if (id.endsWith('vue.runtime.esm-bundler.js')) {
|
|
18
|
+
id = 'vue';
|
|
19
|
+
}
|
|
20
|
+
return rpc.fetchModule(id);
|
|
21
|
+
},
|
|
22
|
+
resolveId(id, importer) {
|
|
23
|
+
return rpc.resolveId(id, importer);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const { destroy: destroyDomEnv } = createDomEnv();
|
|
27
|
+
const el = window.document.createElement('div');
|
|
28
|
+
// Mount app to collect stories/variants
|
|
29
|
+
const { run } = await runner.executeFile(resolve(__dirname, '../../client/server/index.js'));
|
|
30
|
+
const storyData = [];
|
|
31
|
+
await run(payload.storyFile, storyData, el);
|
|
32
|
+
destroyDomEnv();
|
|
33
|
+
return {
|
|
34
|
+
storyData,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import { resolveConfig as resolveViteConfig } from 'vite';
|
|
3
|
+
import connect from 'connect';
|
|
4
|
+
import sirv from 'sirv';
|
|
5
|
+
import pc from 'picocolors';
|
|
6
|
+
import { createContext } from '../context.js';
|
|
7
|
+
import { createVitePlugins } from '../plugin.js';
|
|
8
|
+
export async function previewCommand(options) {
|
|
9
|
+
const ctx = await createContext({
|
|
10
|
+
mode: 'build',
|
|
11
|
+
});
|
|
12
|
+
const viteConfig = await resolveViteConfig({
|
|
13
|
+
plugins: await createVitePlugins(ctx),
|
|
14
|
+
}, 'build');
|
|
15
|
+
const app = connect();
|
|
16
|
+
app.use(viteConfig.base, sirv(ctx.config.outDir, {
|
|
17
|
+
dev: true,
|
|
18
|
+
etag: true,
|
|
19
|
+
single: true,
|
|
20
|
+
}));
|
|
21
|
+
let port = options.port ?? 3000;
|
|
22
|
+
const httpServer = http.createServer(app);
|
|
23
|
+
function onError(e) {
|
|
24
|
+
if (e.code === 'EADDRINUSE') {
|
|
25
|
+
httpServer.listen(++port);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
httpServer.on('error', onError);
|
|
32
|
+
httpServer.listen(port, () => {
|
|
33
|
+
httpServer.off('error', onError);
|
|
34
|
+
console.log(`Preview server listening on ${pc.cyan(`http://localhost:${port}`)}`);
|
|
35
|
+
});
|
|
36
|
+
}
|
package/dist/node/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServer as createViteServer } from 'vite';
|
|
2
2
|
import { createVitePlugins, RESOLVED_STORIES_ID } from './plugin.js';
|
|
3
3
|
import { notifyStoryChange, onStoryChange, watchStories } from './stories.js';
|
|
4
|
-
import { useCollectStories } from './collect.js';
|
|
4
|
+
import { useCollectStories } from './collect/index.js';
|
|
5
5
|
export async function createServer(ctx, port) {
|
|
6
6
|
await watchStories(ctx);
|
|
7
7
|
const server = await createViteServer({
|
package/dist/node/tree.js
CHANGED
|
@@ -20,17 +20,37 @@ export function makeTree(config, files) {
|
|
|
20
20
|
sortingFunction = config.tree.order;
|
|
21
21
|
}
|
|
22
22
|
return buildTree(treeObject);
|
|
23
|
-
// Undefined behavior for folder and file that share the same name under the same directory
|
|
24
23
|
function setPath(path, value, tree) {
|
|
25
24
|
path.reduce((subtree, key, i) => {
|
|
26
|
-
if (
|
|
25
|
+
if (i === path.length - 1) {
|
|
26
|
+
setKey(subtree, key, value);
|
|
27
|
+
}
|
|
28
|
+
else if (isLeaf(subtree[key])) {
|
|
29
|
+
setKey(subtree, key, subtree[key]);
|
|
27
30
|
subtree[key] = {};
|
|
28
31
|
}
|
|
29
|
-
if (
|
|
30
|
-
subtree[key] =
|
|
32
|
+
else if (!subtree[key]) {
|
|
33
|
+
subtree[key] = {};
|
|
31
34
|
}
|
|
32
35
|
return subtree[key];
|
|
33
36
|
}, tree);
|
|
37
|
+
function isLeaf(element) {
|
|
38
|
+
return !isNaN(element);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function setKey(tree, key, value) {
|
|
42
|
+
if (isUndefined(tree[key])) {
|
|
43
|
+
tree[key] = value;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let copyNumber = 1;
|
|
47
|
+
while (!isUndefined(tree[`${key}-${copyNumber}`])) {
|
|
48
|
+
copyNumber++;
|
|
49
|
+
}
|
|
50
|
+
tree[`${key}-${copyNumber}`] = value;
|
|
51
|
+
function isUndefined(element) {
|
|
52
|
+
return element === undefined;
|
|
53
|
+
}
|
|
34
54
|
}
|
|
35
55
|
function buildTree(treeObject) {
|
|
36
56
|
const tree = [];
|