histoire 0.13.1 → 0.13.2
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/client.d.ts +3 -0
- package/dist/node/bin.js +1 -0
- package/dist/node/build-serialize.d.ts +21 -0
- package/dist/node/build-serialize.js +36 -0
- package/dist/node/build.js +2 -0
- package/dist/node/commands/dev.d.ts +1 -0
- package/dist/node/commands/dev.js +4 -1
- package/dist/node/config.js +2 -0
- package/dist/node/server.d.ts +1 -0
- package/dist/node/server.js +3 -0
- package/package.json +5 -5
- package/src/node/bin.ts +1 -0
- package/src/node/build-serialize.ts +62 -0
- package/src/node/build.ts +3 -0
- package/src/node/commands/dev.ts +5 -1
- package/src/node/config.ts +2 -0
- package/src/node/server.ts +6 -0
package/client.d.ts
CHANGED
|
@@ -14,3 +14,6 @@ export function logEvent (name: string, argument): void
|
|
|
14
14
|
* Returns `true` when in the NodeJS server while collecting stories.
|
|
15
15
|
*/
|
|
16
16
|
export function isCollecting (): boolean
|
|
17
|
+
|
|
18
|
+
export function toggleDark (value?: boolean): boolean
|
|
19
|
+
export function isDark (): boolean
|
package/dist/node/bin.js
CHANGED
|
@@ -11,6 +11,7 @@ program.version(version);
|
|
|
11
11
|
program.command('dev')
|
|
12
12
|
.describe('open the stories in your browser for development')
|
|
13
13
|
.option('-p, --port <port>', 'Listening port of the server')
|
|
14
|
+
.option('--open', 'Open in your default browser')
|
|
14
15
|
.action(async (options) => {
|
|
15
16
|
const { devCommand } = await import('./commands/dev.js');
|
|
16
17
|
return devCommand(options);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from './context.js';
|
|
2
|
+
import type { ServerStory } from '@histoire/shared';
|
|
3
|
+
interface SerializedStory extends Omit<ServerStory, 'docsText'> {
|
|
4
|
+
relativePath: string;
|
|
5
|
+
supportPluginId: string;
|
|
6
|
+
treePath?: string[];
|
|
7
|
+
virtual?: boolean;
|
|
8
|
+
markdownFile?: SerializedMarkdownFile;
|
|
9
|
+
}
|
|
10
|
+
interface SerializedMarkdownFile {
|
|
11
|
+
id: string;
|
|
12
|
+
relativePath: string;
|
|
13
|
+
isRelatedToStory: boolean;
|
|
14
|
+
frontmatter?: any;
|
|
15
|
+
}
|
|
16
|
+
interface SerializedStoryData {
|
|
17
|
+
stories: SerializedStory[];
|
|
18
|
+
markdownFiles: SerializedMarkdownFile[];
|
|
19
|
+
}
|
|
20
|
+
export declare function getSerializedStoryData(ctx: Context): SerializedStoryData;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function getSerializedStoryData(ctx) {
|
|
2
|
+
const data = {
|
|
3
|
+
stories: [],
|
|
4
|
+
markdownFiles: [],
|
|
5
|
+
};
|
|
6
|
+
for (const storyFile of ctx.storyFiles) {
|
|
7
|
+
if (storyFile.story) {
|
|
8
|
+
data.stories.push({
|
|
9
|
+
...Object.assign({}, storyFile.story, {
|
|
10
|
+
docsText: undefined,
|
|
11
|
+
}),
|
|
12
|
+
relativePath: storyFile.relativePath,
|
|
13
|
+
supportPluginId: storyFile.supportPluginId,
|
|
14
|
+
treePath: storyFile.treePath,
|
|
15
|
+
virtual: storyFile.virtual,
|
|
16
|
+
markdownFile: storyFile.markdownFile
|
|
17
|
+
? {
|
|
18
|
+
id: storyFile.markdownFile.id,
|
|
19
|
+
relativePath: storyFile.markdownFile.relativePath,
|
|
20
|
+
isRelatedToStory: storyFile.markdownFile.isRelatedToStory,
|
|
21
|
+
frontmatter: storyFile.markdownFile.frontmatter,
|
|
22
|
+
}
|
|
23
|
+
: null,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const markdownFile of ctx.markdownFiles) {
|
|
28
|
+
data.markdownFiles.push({
|
|
29
|
+
id: markdownFile.id,
|
|
30
|
+
relativePath: markdownFile.relativePath,
|
|
31
|
+
isRelatedToStory: markdownFile.isRelatedToStory,
|
|
32
|
+
frontmatter: markdownFile.frontmatter,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return data;
|
|
36
|
+
}
|
package/dist/node/build.js
CHANGED
|
@@ -12,6 +12,7 @@ import { BuildPluginApi } from './plugin.js';
|
|
|
12
12
|
import { useModuleLoader } from './load.js';
|
|
13
13
|
import { startPreview } from './preview.js';
|
|
14
14
|
import { createMarkdownFilesWatcher } from './markdown.js';
|
|
15
|
+
import { getSerializedStoryData } from './build-serialize.js';
|
|
15
16
|
const PRELOAD_MODULES = [
|
|
16
17
|
'vendor',
|
|
17
18
|
];
|
|
@@ -149,6 +150,7 @@ export async function build(ctx) {
|
|
|
149
150
|
const sandboxOutput = result.output.find(o => o.name === 'bundle-sandbox' && o.type === 'chunk');
|
|
150
151
|
const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx);
|
|
151
152
|
await writeFile('__sandbox.html', sandboxHtml, ctx);
|
|
153
|
+
await writeFile('histoire.json', JSON.stringify(getSerializedStoryData(ctx), null, 2), ctx);
|
|
152
154
|
const duration = performance.now() - startTime;
|
|
153
155
|
if (emptyStoryCount) {
|
|
154
156
|
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`));
|
|
@@ -9,7 +9,10 @@ export async function devCommand(options) {
|
|
|
9
9
|
const ctx = await createContext({
|
|
10
10
|
mode: 'dev',
|
|
11
11
|
});
|
|
12
|
-
const { server, viteConfigFile, close } = await createServer(ctx, {
|
|
12
|
+
const { server, viteConfigFile, close } = await createServer(ctx, {
|
|
13
|
+
port: options.port,
|
|
14
|
+
open: options.open,
|
|
15
|
+
});
|
|
13
16
|
server.printUrls();
|
|
14
17
|
// Histoire config watcher
|
|
15
18
|
let watcher;
|
package/dist/node/config.js
CHANGED
package/dist/node/server.d.ts
CHANGED
package/dist/node/server.js
CHANGED
|
@@ -12,6 +12,9 @@ import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js'
|
|
|
12
12
|
export async function createServer(ctx, options = {}) {
|
|
13
13
|
const getViteServer = async (collecting) => {
|
|
14
14
|
const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx);
|
|
15
|
+
if (!collecting && options.open) {
|
|
16
|
+
viteConfig.server.open = true;
|
|
17
|
+
}
|
|
15
18
|
const server = await createViteServer(viteConfig);
|
|
16
19
|
await server.pluginContainer.buildStart({});
|
|
17
20
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@histoire/app": "^0.13.
|
|
37
|
-
"@histoire/controls": "^0.13.
|
|
38
|
-
"@histoire/shared": "^0.13.
|
|
39
|
-
"@histoire/vendors": "^0.13.
|
|
36
|
+
"@histoire/app": "^0.13.2",
|
|
37
|
+
"@histoire/controls": "^0.13.2",
|
|
38
|
+
"@histoire/shared": "^0.13.2",
|
|
39
|
+
"@histoire/vendors": "^0.13.2",
|
|
40
40
|
"@types/flexsearch": "^0.7.3",
|
|
41
41
|
"@types/markdown-it": "^12.2.3",
|
|
42
42
|
"birpc": "^0.1.1",
|
package/src/node/bin.ts
CHANGED
|
@@ -16,6 +16,7 @@ program.version(version)
|
|
|
16
16
|
program.command('dev')
|
|
17
17
|
.describe('open the stories in your browser for development')
|
|
18
18
|
.option('-p, --port <port>', 'Listening port of the server')
|
|
19
|
+
.option('--open', 'Open in your default browser')
|
|
19
20
|
.action(async (options) => {
|
|
20
21
|
const { devCommand } = await import('./commands/dev.js')
|
|
21
22
|
return devCommand(options)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Context } from './context.js'
|
|
2
|
+
import type { ServerStory } from '@histoire/shared'
|
|
3
|
+
|
|
4
|
+
interface SerializedStory extends Omit<ServerStory, 'docsText'> {
|
|
5
|
+
relativePath: string
|
|
6
|
+
supportPluginId: string
|
|
7
|
+
treePath?: string[]
|
|
8
|
+
virtual?: boolean
|
|
9
|
+
markdownFile?: SerializedMarkdownFile
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SerializedMarkdownFile {
|
|
13
|
+
id: string
|
|
14
|
+
relativePath: string
|
|
15
|
+
isRelatedToStory: boolean
|
|
16
|
+
frontmatter?: any
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface SerializedStoryData {
|
|
20
|
+
stories: SerializedStory[]
|
|
21
|
+
markdownFiles: SerializedMarkdownFile[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getSerializedStoryData (ctx: Context): SerializedStoryData {
|
|
25
|
+
const data: SerializedStoryData = {
|
|
26
|
+
stories: [],
|
|
27
|
+
markdownFiles: [],
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const storyFile of ctx.storyFiles) {
|
|
31
|
+
if (storyFile.story) {
|
|
32
|
+
data.stories.push({
|
|
33
|
+
...Object.assign({}, storyFile.story, {
|
|
34
|
+
docsText: undefined,
|
|
35
|
+
}),
|
|
36
|
+
relativePath: storyFile.relativePath,
|
|
37
|
+
supportPluginId: storyFile.supportPluginId,
|
|
38
|
+
treePath: storyFile.treePath,
|
|
39
|
+
virtual: storyFile.virtual,
|
|
40
|
+
markdownFile: storyFile.markdownFile
|
|
41
|
+
? {
|
|
42
|
+
id: storyFile.markdownFile.id,
|
|
43
|
+
relativePath: storyFile.markdownFile.relativePath,
|
|
44
|
+
isRelatedToStory: storyFile.markdownFile.isRelatedToStory,
|
|
45
|
+
frontmatter: storyFile.markdownFile.frontmatter,
|
|
46
|
+
}
|
|
47
|
+
: null,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const markdownFile of ctx.markdownFiles) {
|
|
53
|
+
data.markdownFiles.push({
|
|
54
|
+
id: markdownFile.id,
|
|
55
|
+
relativePath: markdownFile.relativePath,
|
|
56
|
+
isRelatedToStory: markdownFile.isRelatedToStory,
|
|
57
|
+
frontmatter: markdownFile.frontmatter,
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return data
|
|
62
|
+
}
|
package/src/node/build.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { BuildPluginApi } from './plugin.js'
|
|
|
24
24
|
import { useModuleLoader } from './load.js'
|
|
25
25
|
import { startPreview } from './preview.js'
|
|
26
26
|
import { createMarkdownFilesWatcher } from './markdown.js'
|
|
27
|
+
import { getSerializedStoryData } from './build-serialize.js'
|
|
27
28
|
|
|
28
29
|
const PRELOAD_MODULES = [
|
|
29
30
|
'vendor',
|
|
@@ -181,6 +182,8 @@ export async function build (ctx: Context) {
|
|
|
181
182
|
const sandboxHtml = generateEntryHtml(sandboxOutput.fileName, styleOutput.fileName, {}, ctx)
|
|
182
183
|
await writeFile('__sandbox.html', sandboxHtml, ctx)
|
|
183
184
|
|
|
185
|
+
await writeFile('histoire.json', JSON.stringify(getSerializedStoryData(ctx), null, 2), ctx)
|
|
186
|
+
|
|
184
187
|
const duration = performance.now() - startTime
|
|
185
188
|
if (emptyStoryCount) {
|
|
186
189
|
console.warn(pc.yellow(`⚠️ ${emptyStoryCount} empty story file`))
|
package/src/node/commands/dev.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { createServer } from '../server.js'
|
|
|
6
6
|
|
|
7
7
|
export interface DevOptions {
|
|
8
8
|
port: number
|
|
9
|
+
open?: boolean
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export async function devCommand (options: DevOptions) {
|
|
@@ -15,7 +16,10 @@ export async function devCommand (options: DevOptions) {
|
|
|
15
16
|
const ctx = await createContext({
|
|
16
17
|
mode: 'dev',
|
|
17
18
|
})
|
|
18
|
-
const { server, viteConfigFile, close } = await createServer(ctx, {
|
|
19
|
+
const { server, viteConfigFile, close } = await createServer(ctx, {
|
|
20
|
+
port: options.port,
|
|
21
|
+
open: options.open,
|
|
22
|
+
})
|
|
19
23
|
server.printUrls()
|
|
20
24
|
|
|
21
25
|
// Histoire config watcher
|
package/src/node/config.ts
CHANGED
package/src/node/server.ts
CHANGED
|
@@ -14,11 +14,17 @@ import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js'
|
|
|
14
14
|
|
|
15
15
|
export interface CreateServerOptions {
|
|
16
16
|
port?: number
|
|
17
|
+
open?: boolean
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export async function createServer (ctx: Context, options: CreateServerOptions = {}) {
|
|
20
21
|
const getViteServer = async (collecting: boolean) => {
|
|
21
22
|
const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx)
|
|
23
|
+
|
|
24
|
+
if (!collecting && options.open) {
|
|
25
|
+
viteConfig.server.open = true
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
const server = await createViteServer(viteConfig)
|
|
23
29
|
await server.pluginContainer.buildStart({})
|
|
24
30
|
return {
|