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 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/node/dom/env.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY;;;EAqD3B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { JSDOM, VirtualConsole, } from 'jsdom';
|
|
2
|
+
import { populateGlobal } from './util.js';
|
|
3
|
+
export function createDomEnv() {
|
|
4
|
+
const dom = new JSDOM('<!DOCTYPE html>', {
|
|
5
|
+
pretendToBeVisual: true,
|
|
6
|
+
runScripts: 'dangerously',
|
|
7
|
+
url: 'http://localhost:3000',
|
|
8
|
+
virtualConsole: console && globalThis.console ? new VirtualConsole().forwardTo(globalThis.console) : undefined,
|
|
9
|
+
includeNodeLocations: false,
|
|
10
|
+
contentType: 'text/html',
|
|
11
|
+
});
|
|
12
|
+
const { keys, originals } = populateGlobal(globalThis, dom.window, { bindFunctions: true });
|
|
13
|
+
function destroy() {
|
|
14
|
+
keys.forEach(key => delete globalThis[key]);
|
|
15
|
+
originals.forEach((v, k) => {
|
|
16
|
+
globalThis[k] = v;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
window.ResizeObserver = window.ResizeObserver || class ResizeObserver {
|
|
20
|
+
disconnect() { }
|
|
21
|
+
observe(_target, _options) { }
|
|
22
|
+
unobserve(_target) { }
|
|
23
|
+
};
|
|
24
|
+
window.IntersectionObserver = window.IntersectionObserver || class IntersectionObserver {
|
|
25
|
+
root;
|
|
26
|
+
rootMargin;
|
|
27
|
+
thresholds;
|
|
28
|
+
disconnect() { }
|
|
29
|
+
observe = (_target) => void { /* noop */};
|
|
30
|
+
unobserve(_target) { }
|
|
31
|
+
takeRecords() { return []; }
|
|
32
|
+
};
|
|
33
|
+
window.matchMedia = window.matchMedia || ((query) => ({
|
|
34
|
+
matches: false,
|
|
35
|
+
media: query,
|
|
36
|
+
onchange: null,
|
|
37
|
+
addListener: () => { },
|
|
38
|
+
removeListener: () => { },
|
|
39
|
+
addEventListener: () => { },
|
|
40
|
+
removeEventListener: () => { },
|
|
41
|
+
dispatchEvent: () => false,
|
|
42
|
+
}));
|
|
43
|
+
return {
|
|
44
|
+
window,
|
|
45
|
+
destroy,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getWindowKeys(global: any, win: any): Set<string>;
|
|
2
|
+
interface PopulateOptions {
|
|
3
|
+
bindFunctions?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function populateGlobal(global: any, win: any, options?: PopulateOptions): {
|
|
6
|
+
keys: Set<string>;
|
|
7
|
+
skipKeys: string[];
|
|
8
|
+
originals: Map<string | symbol, any>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/node/dom/util.ts"],"names":[],"mappings":"AAaA,wBAAgB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,eAalD;AAMD,UAAU,eAAe;IAKvB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,eAAoB;;;;EA0ClF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code from vitest https://github.com/vitest-dev/vitest/blob/98974ba4a5b95a57a98bc2077b74bc5609d6bb3a/packages/vitest/src/integrations/env/utils.ts#L1 by @antfu and @patak
|
|
3
|
+
*/
|
|
4
|
+
import { KEYS } from './dom-keys.js';
|
|
5
|
+
const skipKeys = [
|
|
6
|
+
'window',
|
|
7
|
+
'self',
|
|
8
|
+
'top',
|
|
9
|
+
'parent',
|
|
10
|
+
];
|
|
11
|
+
export function getWindowKeys(global, win) {
|
|
12
|
+
const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win))
|
|
13
|
+
.filter((k) => {
|
|
14
|
+
if (skipKeys.includes(k)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (k in global) {
|
|
18
|
+
return KEYS.includes(k);
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}));
|
|
22
|
+
return keys;
|
|
23
|
+
}
|
|
24
|
+
function isClassLikeName(name) {
|
|
25
|
+
return name[0] === name[0].toUpperCase();
|
|
26
|
+
}
|
|
27
|
+
export function populateGlobal(global, win, options = {}) {
|
|
28
|
+
const { bindFunctions = false } = options;
|
|
29
|
+
const keys = getWindowKeys(global, win);
|
|
30
|
+
const originals = new Map();
|
|
31
|
+
const overrideObject = new Map();
|
|
32
|
+
for (const key of keys) {
|
|
33
|
+
const boundFunction = bindFunctions
|
|
34
|
+
&& typeof win[key] === 'function'
|
|
35
|
+
&& !isClassLikeName(key)
|
|
36
|
+
&& win[key].bind(win);
|
|
37
|
+
if (KEYS.includes(key) && key in global)
|
|
38
|
+
originals.set(key, global[key]);
|
|
39
|
+
Object.defineProperty(global, key, {
|
|
40
|
+
get() {
|
|
41
|
+
if (overrideObject.has(key))
|
|
42
|
+
return overrideObject.get(key);
|
|
43
|
+
if (boundFunction)
|
|
44
|
+
return boundFunction;
|
|
45
|
+
return win[key];
|
|
46
|
+
},
|
|
47
|
+
set(v) {
|
|
48
|
+
overrideObject.set(key, v);
|
|
49
|
+
},
|
|
50
|
+
configurable: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
global.window = global;
|
|
54
|
+
global.self = global;
|
|
55
|
+
global.top = global;
|
|
56
|
+
global.parent = global;
|
|
57
|
+
if (global.global)
|
|
58
|
+
global.global = global;
|
|
59
|
+
skipKeys.forEach(k => keys.add(k));
|
|
60
|
+
return {
|
|
61
|
+
keys,
|
|
62
|
+
skipKeys,
|
|
63
|
+
originals,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { defaultColors } from './colors.js';
|
|
2
|
+
export * from './config.js';
|
|
3
|
+
export * from './plugin.js';
|
|
4
|
+
export * from '@poveste/shared';
|
|
5
|
+
declare module 'rollup' {
|
|
6
|
+
interface PluginContextMeta {
|
|
7
|
+
histoire: {
|
|
8
|
+
isCollecting: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAE/B,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,iBAAiB;QACzB,QAAQ,EAAE;YACR,YAAY,EAAE,OAAO,CAAA;SACtB,CAAA;KACF;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModuleLoader } from '@poveste/shared';
|
|
2
|
+
import type { ViteDevServer } from 'vite';
|
|
3
|
+
export interface UseModuleLoaderOptions {
|
|
4
|
+
server: ViteDevServer;
|
|
5
|
+
throws?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function useModuleLoader(options: UseModuleLoaderOptions): ModuleLoader;
|
|
8
|
+
export declare const loadModule: ModuleLoader['loadModule'];
|
|
9
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/node/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAMzC,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAID,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,YAAY,CA0C7E;AAED,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,YAAY,CAAiC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { resolve } from 'pathe';
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
import { ViteNodeRunner } from 'vite-node/client';
|
|
4
|
+
import { ViteNodeServer } from 'vite-node/server';
|
|
5
|
+
let _load;
|
|
6
|
+
export function useModuleLoader(options) {
|
|
7
|
+
const { server } = options;
|
|
8
|
+
const node = new ViteNodeServer(server);
|
|
9
|
+
const runner = new ViteNodeRunner({
|
|
10
|
+
root: server.config.root,
|
|
11
|
+
base: server.config.base,
|
|
12
|
+
fetchModule: async (id) => node.fetchModule(id),
|
|
13
|
+
resolveId: (id, importer) => node.resolveId(id, importer),
|
|
14
|
+
});
|
|
15
|
+
function clearCache() {
|
|
16
|
+
server.moduleGraph.invalidateAll();
|
|
17
|
+
node.fetchCache.clear();
|
|
18
|
+
runner.moduleCache.clear();
|
|
19
|
+
}
|
|
20
|
+
async function loadModule(file) {
|
|
21
|
+
try {
|
|
22
|
+
const result = await runner.executeFile(resolve(file));
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
console.error(pc.red(`Error while loading module ${file}:\n${e.frame ? `${pc.bold(e.message)}\n${e.frame}` : e.stack}`));
|
|
27
|
+
if (options.throws) {
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
_load = loadModule;
|
|
33
|
+
async function destroy() {
|
|
34
|
+
// Noop
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
clearCache,
|
|
38
|
+
loadModule,
|
|
39
|
+
destroy,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export const loadModule = (...args) => _load?.(...args);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin as VitePlugin } from 'vite';
|
|
2
|
+
import type { Context } from './context.js';
|
|
3
|
+
import MarkdownIt from 'markdown-it';
|
|
4
|
+
export declare function onMarkdownListChange(handler: () => unknown): void;
|
|
5
|
+
export declare function createMarkdownRenderer(ctx: Context): Promise<MarkdownIt>;
|
|
6
|
+
export declare function createMarkdownPlugins(ctx: Context): Promise<VitePlugin<any>[]>;
|
|
7
|
+
export declare function createMarkdownFilesWatcher(ctx: Context): Promise<{
|
|
8
|
+
stop: () => Promise<void>;
|
|
9
|
+
}>;
|
|
10
|
+
export type MarkdownFilesWatcher = ReturnType<typeof createMarkdownFilesWatcher>;
|
|
11
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/node/markdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAK3C,OAAO,UAAU,MAAM,aAAa,CAAA;AAapC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,OAAO,QAE1D;AAQD,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,OAAO,uBAsExD;AAaD,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,OAAO,8BAqBvD;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE,OAAO;;GAgI5D;AAED,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAA"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { kebabCase } from 'change-case';
|
|
2
|
+
import chokidar from 'chokidar';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import matter from 'gray-matter';
|
|
5
|
+
import MarkdownIt from 'markdown-it';
|
|
6
|
+
import anchor from 'markdown-it-anchor';
|
|
7
|
+
import attrs from 'markdown-it-attrs';
|
|
8
|
+
import { full as emoji } from 'markdown-it-emoji';
|
|
9
|
+
import micromatch from 'micromatch';
|
|
10
|
+
import path from 'pathe';
|
|
11
|
+
import pc from 'picocolors';
|
|
12
|
+
import { bundledLanguages, createHighlighter } from 'shiki';
|
|
13
|
+
import { addStory, notifyStoryChange, removeStory } from './stories.js';
|
|
14
|
+
import { slugify } from './util/slugify.js';
|
|
15
|
+
const onMarkdownListChangeHandlers = [];
|
|
16
|
+
export function onMarkdownListChange(handler) {
|
|
17
|
+
onMarkdownListChangeHandlers.push(handler);
|
|
18
|
+
}
|
|
19
|
+
function notifyMarkdownListChange() {
|
|
20
|
+
for (const handler of onMarkdownListChangeHandlers) {
|
|
21
|
+
handler();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function createMarkdownRenderer(ctx) {
|
|
25
|
+
const highlighter = await createHighlighter({
|
|
26
|
+
themes: ['github-dark'],
|
|
27
|
+
langs: Object.keys(bundledLanguages), // not ideal but markdown-it does not provide async highlight
|
|
28
|
+
});
|
|
29
|
+
const md = new MarkdownIt({
|
|
30
|
+
highlight: (code, lang) => `<div class="htw-relative htw-not-prose __histoire-code"><div class="htw-absolute htw-top-0 htw-right-0 htw-text-xs htw-text-white/40">${lang}</div>${highlighter.codeToHtml(code, { theme: 'github-dark', lang })}</div>`,
|
|
31
|
+
linkify: true,
|
|
32
|
+
html: true,
|
|
33
|
+
breaks: false,
|
|
34
|
+
});
|
|
35
|
+
md.use(anchor, {
|
|
36
|
+
slugify,
|
|
37
|
+
permalink: anchor.permalink.ariaHidden({}),
|
|
38
|
+
})
|
|
39
|
+
.use(attrs)
|
|
40
|
+
.use(emoji);
|
|
41
|
+
// External links
|
|
42
|
+
{
|
|
43
|
+
const defaultRender = md.renderer.rules.link_open || function (tokens, idx, options, env, self) {
|
|
44
|
+
return self.renderToken(tokens, idx, options);
|
|
45
|
+
};
|
|
46
|
+
md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
|
|
47
|
+
const token = tokens[idx];
|
|
48
|
+
const hrefIndex = token.attrIndex('href');
|
|
49
|
+
const classIndex = token.attrIndex('class');
|
|
50
|
+
if (hrefIndex >= 0) {
|
|
51
|
+
const href = token.attrs[hrefIndex][1];
|
|
52
|
+
if (href.startsWith('.')) {
|
|
53
|
+
const queryIndex = href.indexOf('?');
|
|
54
|
+
const pathname = queryIndex >= 0 ? href.slice(0, queryIndex) : href;
|
|
55
|
+
const query = queryIndex >= 0 ? href.slice(queryIndex) : '';
|
|
56
|
+
// File lookup
|
|
57
|
+
const file = path.resolve(path.dirname(env.file), pathname);
|
|
58
|
+
const storyFile = ctx.storyFiles.find(f => f.path === file);
|
|
59
|
+
const mdFile = ctx.markdownFiles.find(f => f.absolutePath === file);
|
|
60
|
+
if (!storyFile && !mdFile?.storyFile) {
|
|
61
|
+
throw new Error(pc.red(`[md] Cannot find story file: ${pathname} from ${env.file}`));
|
|
62
|
+
}
|
|
63
|
+
// Add attributes
|
|
64
|
+
const newHref = `${ctx.resolvedViteConfig.base}story/${encodeURIComponent(storyFile?.id ?? mdFile.storyFile.id)}${query}`;
|
|
65
|
+
token.attrSet('href', newHref);
|
|
66
|
+
token.attrSet('data-route', 'true');
|
|
67
|
+
}
|
|
68
|
+
else if (!href.startsWith('/') && !href.startsWith('#') && (classIndex < 0 || !token.attrs[classIndex][1].includes('header-anchor'))) {
|
|
69
|
+
// Add target="_blank" to external links
|
|
70
|
+
const aIndex = token.attrIndex('target');
|
|
71
|
+
if (aIndex < 0) {
|
|
72
|
+
token.attrPush(['target', '_blank']); // add new attribute
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
token.attrs[aIndex][1] = '_blank'; // replace value of existing attr
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// pass token to default renderer.
|
|
80
|
+
return defaultRender(tokens, idx, options, env, self);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return md;
|
|
84
|
+
}
|
|
85
|
+
async function createMarkdownRendererWithPlugins(ctx) {
|
|
86
|
+
let md = await createMarkdownRenderer(ctx);
|
|
87
|
+
if (ctx.config.markdown) {
|
|
88
|
+
const result = await ctx.config.markdown(md);
|
|
89
|
+
if (result) {
|
|
90
|
+
md = result;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return md;
|
|
94
|
+
}
|
|
95
|
+
export async function createMarkdownPlugins(ctx) {
|
|
96
|
+
const plugins = [];
|
|
97
|
+
const md = await createMarkdownRendererWithPlugins(ctx);
|
|
98
|
+
// @TODO extract
|
|
99
|
+
plugins.push({
|
|
100
|
+
name: 'histoire-vue-docs-block',
|
|
101
|
+
transform(code, id) {
|
|
102
|
+
if (!id.includes('?vue&type=docs'))
|
|
103
|
+
return;
|
|
104
|
+
if (!id.includes('lang.md'))
|
|
105
|
+
return;
|
|
106
|
+
const file = id.substring(0, id.indexOf('?vue'));
|
|
107
|
+
const html = md.render(code, {
|
|
108
|
+
file,
|
|
109
|
+
});
|
|
110
|
+
return `export default Comp => {
|
|
111
|
+
Comp.doc = ${JSON.stringify(html)}
|
|
112
|
+
}`;
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
return plugins;
|
|
116
|
+
}
|
|
117
|
+
export async function createMarkdownFilesWatcher(ctx) {
|
|
118
|
+
const md = await createMarkdownRendererWithPlugins(ctx);
|
|
119
|
+
const watcher = chokidar.watch('.', {
|
|
120
|
+
cwd: ctx.root,
|
|
121
|
+
ignored: (path, stats) => {
|
|
122
|
+
if (ctx.config.storyIgnored.some(pattern => micromatch.isMatch(path, pattern))) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if (micromatch.isMatch(path, '**/*.story.md')) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return stats?.isFile();
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* Initial scan is complete.
|
|
133
|
+
*/
|
|
134
|
+
let watcherIsReady = false;
|
|
135
|
+
function addFile(relativePath) {
|
|
136
|
+
const absolutePath = path.resolve(ctx.root, relativePath);
|
|
137
|
+
const dirFiles = fs.readdirSync(path.dirname(absolutePath));
|
|
138
|
+
const truncatedName = path.basename(absolutePath, '.md');
|
|
139
|
+
const isRelatedToStory = dirFiles.some(file => !file.endsWith('.md') && file.startsWith(truncatedName));
|
|
140
|
+
const { data: frontmatter, content } = matter(fs.readFileSync(absolutePath, 'utf8'));
|
|
141
|
+
let html;
|
|
142
|
+
// We don't immediately render markdown during initial scanning in case
|
|
143
|
+
// markdown references other files in links (otherwise they might not
|
|
144
|
+
// be scanned yet and will throw 'not found' errors).
|
|
145
|
+
if (watcherIsReady) {
|
|
146
|
+
html = md.render(content, {
|
|
147
|
+
file: absolutePath,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const file = {
|
|
151
|
+
id: kebabCase(relativePath.toLowerCase()),
|
|
152
|
+
relativePath,
|
|
153
|
+
absolutePath,
|
|
154
|
+
isRelatedToStory,
|
|
155
|
+
frontmatter,
|
|
156
|
+
content,
|
|
157
|
+
html,
|
|
158
|
+
};
|
|
159
|
+
ctx.markdownFiles.push(file);
|
|
160
|
+
if (!isRelatedToStory) {
|
|
161
|
+
const storyRelativePath = relativePath.replace(/\.md$/, '.js');
|
|
162
|
+
const storyFile = addStory(storyRelativePath, `export default ${JSON.stringify({
|
|
163
|
+
id: frontmatter.id,
|
|
164
|
+
title: frontmatter.title,
|
|
165
|
+
icon: frontmatter.icon ?? 'carbon:document-blank',
|
|
166
|
+
iconColor: frontmatter.iconColor,
|
|
167
|
+
group: frontmatter.group,
|
|
168
|
+
docsOnly: true,
|
|
169
|
+
variants: [],
|
|
170
|
+
})}`);
|
|
171
|
+
file.storyFile = storyFile;
|
|
172
|
+
storyFile.markdownFile = file;
|
|
173
|
+
notifyStoryChange(storyFile);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const searchPath = path.join(path.dirname(relativePath), truncatedName);
|
|
177
|
+
const storyFile = ctx.storyFiles.find(f => f.relativePath.startsWith(searchPath));
|
|
178
|
+
if (storyFile) {
|
|
179
|
+
file.storyFile = storyFile;
|
|
180
|
+
storyFile.markdownFile = file;
|
|
181
|
+
notifyStoryChange(storyFile);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
notifyMarkdownListChange();
|
|
185
|
+
return file;
|
|
186
|
+
}
|
|
187
|
+
function removeFile(relativePath) {
|
|
188
|
+
const index = ctx.markdownFiles.findIndex(file => file.relativePath === relativePath);
|
|
189
|
+
if (index !== -1) {
|
|
190
|
+
const file = ctx.markdownFiles[index];
|
|
191
|
+
if (!file.isRelatedToStory) {
|
|
192
|
+
removeStory(file.storyFile.relativePath);
|
|
193
|
+
notifyStoryChange();
|
|
194
|
+
}
|
|
195
|
+
ctx.markdownFiles.splice(index, 1);
|
|
196
|
+
notifyMarkdownListChange();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function stop() {
|
|
200
|
+
await watcher.close();
|
|
201
|
+
}
|
|
202
|
+
watcher
|
|
203
|
+
.on('add', (relativePath) => {
|
|
204
|
+
addFile(relativePath);
|
|
205
|
+
})
|
|
206
|
+
.on('unlink', (relativePath) => {
|
|
207
|
+
removeFile(relativePath);
|
|
208
|
+
});
|
|
209
|
+
await new Promise((resolve) => {
|
|
210
|
+
watcher.once('ready', resolve);
|
|
211
|
+
});
|
|
212
|
+
try {
|
|
213
|
+
// Render markdown after initial scan is complete.
|
|
214
|
+
for (const mdFile of ctx.markdownFiles) {
|
|
215
|
+
mdFile.html = md.render(mdFile.content, {
|
|
216
|
+
file: mdFile.absolutePath,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
watcherIsReady = true;
|
|
220
|
+
return {
|
|
221
|
+
stop,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
await stop();
|
|
226
|
+
throw e;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BuildEndCallback, ChangeViteConfigCallback, ModuleLoader, Plugin, PluginApiBase, PluginApiBuild, PluginApiDev, PluginApiDevEvent, PovesteConfig, PreviewStoryCallback, ServerStory } from '@poveste/shared';
|
|
2
|
+
import type { Context } from './context.js';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import path from 'pathe';
|
|
5
|
+
export declare class BasePluginApi implements PluginApiBase {
|
|
6
|
+
protected ctx: Context;
|
|
7
|
+
protected plugin: Plugin;
|
|
8
|
+
moduleLoader: ModuleLoader;
|
|
9
|
+
colors: import("picocolors/types.js").Colors & {
|
|
10
|
+
createColors: (enabled?: boolean) => import("picocolors/types.js").Colors;
|
|
11
|
+
};
|
|
12
|
+
path: typeof path;
|
|
13
|
+
fs: typeof fs;
|
|
14
|
+
constructor(ctx: Context, plugin: Plugin, moduleLoader: ModuleLoader);
|
|
15
|
+
get pluginTempDir(): string;
|
|
16
|
+
log(...msg: any[]): void;
|
|
17
|
+
warn(...msg: any[]): void;
|
|
18
|
+
error(...msg: any[]): void;
|
|
19
|
+
addStoryFile(file: string): void;
|
|
20
|
+
getStories(): ServerStory[];
|
|
21
|
+
getConfig(): PovesteConfig;
|
|
22
|
+
}
|
|
23
|
+
export declare class DevPluginApi extends BasePluginApi implements PluginApiDev {
|
|
24
|
+
watcher: {
|
|
25
|
+
watch: typeof import("chokidar").watch;
|
|
26
|
+
FSWatcher: typeof import("chokidar").FSWatcher;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare class BuildPluginApi extends BasePluginApi implements PluginApiBuild {
|
|
30
|
+
changeViteConfigCallbacks: ChangeViteConfigCallback[];
|
|
31
|
+
buildEndCallbacks: BuildEndCallback[];
|
|
32
|
+
previewStoryCallbacks: PreviewStoryCallback[];
|
|
33
|
+
changeViteConfig(cb: ChangeViteConfigCallback): void;
|
|
34
|
+
onBuildEnd(cb: BuildEndCallback): void;
|
|
35
|
+
onPreviewStory(cb: PreviewStoryCallback): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class DevEventPluginApi extends BasePluginApi implements PluginApiDevEvent {
|
|
38
|
+
event: string;
|
|
39
|
+
payload: any;
|
|
40
|
+
constructor(ctx: Context, plugin: Plugin, moduleLoader: ModuleLoader, event: string, payload: any);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/node/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,MAAM,EACN,aAAa,EACb,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,WAAW,EACZ,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,IAAI,MAAM,OAAO,CAAA;AAKxB,qBAAa,aAAc,YAAW,aAAa;IAM/C,SAAS,CAAC,GAAG,EAAE,OAAO;IACtB,SAAS,CAAC,MAAM,EAAE,MAAM;IACjB,YAAY,EAAE,YAAY;IAPnC,MAAM;8BAjBH,CAAC;MAiBO;IACX,IAAI,cAAO;IACX,EAAE,YAAK;gBAGK,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY;IAGnC,IAAI,aAAa,WAEhB;IAED,GAAG,CAAC,GAAG,GAAG,OAAA;IAIV,IAAI,CAAC,GAAG,GAAG,OAAA;IAIX,KAAK,CAAC,GAAG,GAAG,OAAA;IAIZ,YAAY,CAAC,IAAI,EAAE,MAAM;IAKzB,UAAU,IAAI,WAAW,EAAE;IAI3B,SAAS,IAAI,aAAa;CAG3B;AAED,qBAAa,YAAa,SAAQ,aAAc,YAAW,YAAY;IACrE,OAAO;;;MAAW;CACnB;AAED,qBAAa,cAAe,SAAQ,aAAc,YAAW,cAAc;IACzE,yBAAyB,EAAE,wBAAwB,EAAE,CAAK;IAC1D,iBAAiB,EAAE,gBAAgB,EAAE,CAAK;IAC1C,qBAAqB,EAAE,oBAAoB,EAAE,CAAK;IAElD,gBAAgB,CAAC,EAAE,EAAE,wBAAwB;IAI7C,UAAU,CAAC,EAAE,EAAE,gBAAgB;IAI/B,cAAc,CAAC,EAAE,EAAE,oBAAoB;CAGxC;AAED,qBAAa,iBAAkB,SAAQ,aAAc,YAAW,iBAAiB;IAKtE,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,GAAG;gBAJnB,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,GAAG;CAItB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'pathe';
|
|
4
|
+
import pc from 'picocolors';
|
|
5
|
+
import { TEMP_PATH } from './alias.js';
|
|
6
|
+
import { addStory, removeStory } from './stories.js';
|
|
7
|
+
export class BasePluginApi {
|
|
8
|
+
ctx;
|
|
9
|
+
plugin;
|
|
10
|
+
moduleLoader;
|
|
11
|
+
colors = pc;
|
|
12
|
+
path = path;
|
|
13
|
+
fs = fs;
|
|
14
|
+
constructor(ctx, plugin, moduleLoader) {
|
|
15
|
+
this.ctx = ctx;
|
|
16
|
+
this.plugin = plugin;
|
|
17
|
+
this.moduleLoader = moduleLoader;
|
|
18
|
+
}
|
|
19
|
+
get pluginTempDir() {
|
|
20
|
+
return path.resolve(TEMP_PATH, 'plugins', this.plugin.name.replace(/:/g, '_'));
|
|
21
|
+
}
|
|
22
|
+
log(...msg) {
|
|
23
|
+
console.log(this.colors.gray(`[Plugin:${this.plugin.name}]`), ...msg);
|
|
24
|
+
}
|
|
25
|
+
warn(...msg) {
|
|
26
|
+
console.warn(this.colors.yellow(`[Plugin:${this.plugin.name}]`), ...msg);
|
|
27
|
+
}
|
|
28
|
+
error(...msg) {
|
|
29
|
+
console.error(this.colors.red(`[Plugin:${this.plugin.name}]`), ...msg);
|
|
30
|
+
}
|
|
31
|
+
addStoryFile(file) {
|
|
32
|
+
removeStory(file);
|
|
33
|
+
addStory(file);
|
|
34
|
+
}
|
|
35
|
+
getStories() {
|
|
36
|
+
return this.ctx.storyFiles.map(f => f.story).filter(Boolean);
|
|
37
|
+
}
|
|
38
|
+
getConfig() {
|
|
39
|
+
return this.ctx.config;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class DevPluginApi extends BasePluginApi {
|
|
43
|
+
watcher = chokidar;
|
|
44
|
+
}
|
|
45
|
+
export class BuildPluginApi extends BasePluginApi {
|
|
46
|
+
changeViteConfigCallbacks = [];
|
|
47
|
+
buildEndCallbacks = [];
|
|
48
|
+
previewStoryCallbacks = [];
|
|
49
|
+
changeViteConfig(cb) {
|
|
50
|
+
this.changeViteConfigCallbacks.push(cb);
|
|
51
|
+
}
|
|
52
|
+
onBuildEnd(cb) {
|
|
53
|
+
this.buildEndCallbacks.push(cb);
|
|
54
|
+
}
|
|
55
|
+
onPreviewStory(cb) {
|
|
56
|
+
this.previewStoryCallbacks.push(cb);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class DevEventPluginApi extends BasePluginApi {
|
|
60
|
+
event;
|
|
61
|
+
payload;
|
|
62
|
+
constructor(ctx, plugin, moduleLoader, event, payload) {
|
|
63
|
+
super(ctx, plugin, moduleLoader);
|
|
64
|
+
this.event = event;
|
|
65
|
+
this.payload = payload;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Context } from './context.js';
|
|
2
|
+
interface ReturnPayload {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
close: () => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare function startPreview(port: number | null, ctx: Context): Promise<ReturnPayload>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/node/preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAK3C,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CA8C5F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import http from 'node:http';
|
|
2
|
+
import connect from 'connect';
|
|
3
|
+
import sirv from 'sirv';
|
|
4
|
+
export async function startPreview(port, ctx) {
|
|
5
|
+
const app = connect();
|
|
6
|
+
app.use(ctx.resolvedViteConfig.base, sirv(ctx.config.outDir, {
|
|
7
|
+
dev: true,
|
|
8
|
+
etag: true,
|
|
9
|
+
single: true,
|
|
10
|
+
}));
|
|
11
|
+
let finalPort = port ?? 6006;
|
|
12
|
+
const httpServer = http.createServer(app);
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
function onError(e) {
|
|
15
|
+
if (e.code === 'EADDRINUSE') {
|
|
16
|
+
httpServer.listen(++finalPort);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
httpServer.on('error', onError);
|
|
23
|
+
httpServer.listen(finalPort, () => {
|
|
24
|
+
httpServer.off('error', onError);
|
|
25
|
+
const baseUrl = `http://localhost:${finalPort}${ctx.resolvedViteConfig.base}`;
|
|
26
|
+
resolve({
|
|
27
|
+
baseUrl,
|
|
28
|
+
close: () => new Promise((resolve, reject) => {
|
|
29
|
+
httpServer.close((err) => {
|
|
30
|
+
if (err) {
|
|
31
|
+
reject(err);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
resolve();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context } from './context.js';
|
|
2
|
+
export declare function generateTitleSearchData(ctx: Context): Promise<{
|
|
3
|
+
index: any[];
|
|
4
|
+
idMap: Record<number, {
|
|
5
|
+
id: string;
|
|
6
|
+
kind: string;
|
|
7
|
+
}>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function generateDocSearchData(ctx: Context): Promise<{
|
|
10
|
+
index: any[];
|
|
11
|
+
idMap: Record<number, {
|
|
12
|
+
id: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
}>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function getSearchDataJS(data: any): string;
|
|
17
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/node/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,OAAO;;;YA8CtB,MAAM;cAAQ,MAAM;;GAvBvD;AAED,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,OAAO;;;YAqBpB,MAAM;cAAQ,MAAM;;GAJvD;AAuBD,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,UAexC"}
|