forgebook 0.2.0 → 0.3.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/README.md +112 -5
- package/dist/bin/forgebook/agentLoopCommands.mjs +3 -0
- package/dist/bin/forgebook/agentText.d.ts +2 -2
- package/dist/bin/forgebook/agentText.js +15 -13
- package/dist/bin/forgebook/agents.md +21 -6
- package/dist/bin/forgebook/mcpTools.js +1 -1
- package/dist/bin/forgebook/newStoriesFile.js +7 -2
- package/dist/bin/forgebook-docs/collectDocs.js +1 -1
- package/dist/src/argsProps.d.ts +32 -0
- package/dist/src/argsProps.js +69 -0
- package/dist/src/catalogue.d.ts +48 -5
- package/dist/src/catalogue.js +47 -8
- package/dist/src/frame/mountFrame.js +26 -7
- package/dist/src/frame/touchCaret.d.ts +43 -0
- package/dist/src/frame/touchCaret.js +195 -0
- package/dist/src/frame/touchEvents.d.ts +3 -2
- package/dist/src/frame/touchEvents.js +17 -18
- package/dist/src/frame/touchLayer.js +48 -7
- package/dist/src/propGroups.d.ts +66 -3
- package/dist/src/propGroups.js +67 -13
- package/dist/src/shell/ApiReference.d.ts +9 -4
- package/dist/src/shell/ApiReference.js +47 -39
- package/dist/src/shell/AudienceSections.js +1 -1
- package/dist/src/shell/ComponentPage.d.ts +5 -2
- package/dist/src/shell/ComponentPage.js +4 -18
- package/dist/src/shell/DocBlocks.js +1 -1
- package/dist/src/shell/PropRows.d.ts +42 -0
- package/dist/src/shell/PropRows.js +60 -0
- package/dist/src/shell/PropsTab.d.ts +14 -10
- package/dist/src/shell/PropsTab.js +18 -58
- package/dist/src/shell/RequiredFirstSwitch.d.ts +16 -0
- package/dist/src/shell/RequiredFirstSwitch.js +8 -0
- package/dist/src/shell/Stage.js +11 -23
- package/dist/src/shell/StoryCoverage.js +4 -1
- package/dist/src/shell/docPage.css +6 -0
- package/dist/src/shell/dockTabs.d.ts +7 -5
- package/dist/src/shell/dockTabs.js +4 -4
- package/dist/src/shell/reportedPanel.d.ts +12 -0
- package/dist/src/shell/reportedPanel.js +19 -0
- package/dist/src/shell/shell.css +56 -1
- package/dist/src/shell/strings.d.ts +2 -0
- package/dist/src/shell/strings.js +2 -0
- package/dist/src/shell/usePanelDocs.d.ts +11 -0
- package/dist/src/shell/usePanelDocs.js +29 -0
- package/dist/src/shell/useRequiredFirst.d.ts +27 -0
- package/dist/src/shell/useRequiredFirst.js +67 -0
- package/dist/src/storyCheck.d.ts +2 -0
- package/dist/src/storyCheck.js +2 -1
- package/dist/src/storyGlobals.js +2 -1
- package/dist/src/storyTree.d.ts +11 -1
- package/dist/src/storyTree.js +3 -1
- package/dist/src/viewState.d.ts +7 -0
- package/dist/src/viewState.js +13 -0
- package/dist/src/vite/agent.types.d.ts +12 -0
- package/dist/src/vite/agentApi.js +6 -1
- package/dist/src/vite/agentRoutes.js +18 -4
- package/dist/src/vite/builtTexts.d.ts +2 -2
- package/dist/src/vite/builtTexts.js +7 -6
- package/dist/src/vite/configFile.d.ts +3 -2
- package/dist/src/vite/configFile.js +63 -14
- package/dist/src/vite/docPagesModule.d.ts +10 -7
- package/dist/src/vite/docPagesModule.js +14 -11
- package/dist/src/vite/docsExtractor.d.ts +6 -0
- package/dist/src/vite/docsExtractor.js +13 -0
- package/dist/src/vite/fileAccess.d.ts +51 -0
- package/dist/src/vite/fileAccess.js +109 -0
- package/dist/src/vite/forgebookPlugin.d.ts +1 -1
- package/dist/src/vite/forgebookPlugin.js +61 -96
- package/dist/src/vite/framesServer.js +21 -5
- package/dist/src/vite/generatedModules.d.ts +23 -0
- package/dist/src/vite/generatedModules.js +58 -0
- package/dist/src/vite/hotSnippets.js +7 -3
- package/dist/src/vite/indexStoryFile.d.ts +2 -2
- package/dist/src/vite/indexStoryFile.js +2 -2
- package/dist/src/vite/indexedParameters.d.ts +1 -1
- package/dist/src/vite/indexedParameters.js +21 -1
- package/dist/src/vite/originGuard.d.ts +14 -4
- package/dist/src/vite/originGuard.js +15 -6
- package/dist/src/vite/pages.d.ts +3 -2
- package/dist/src/vite/pages.js +23 -16
- package/dist/src/vite/pluginIds.d.ts +9 -2
- package/dist/src/vite/pluginIds.js +21 -6
- package/dist/src/vite/pluginModules.d.ts +39 -10
- package/dist/src/vite/pluginModules.js +67 -22
- package/dist/src/vite/prebundled.js +2 -1
- package/dist/src/vite/searchModule.d.ts +6 -4
- package/dist/src/vite/searchModule.js +8 -7
- package/dist/src/vite/storyFilesModule.d.ts +59 -27
- package/dist/src/vite/storyFilesModule.js +88 -58
- package/dist/src/vite/storyPatterns.d.ts +39 -0
- package/dist/src/vite/storyPatterns.js +100 -0
- package/dist/src/vite/textQueries.d.ts +7 -1
- package/dist/src/vite/textQueries.js +7 -1
- package/package.json +2 -2
|
@@ -10,11 +10,15 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { codeLiteral } from "../codeLiteral.js";
|
|
12
12
|
import { packedUsage } from "../usedIn.js";
|
|
13
|
-
import { indexedStoryFiles, PAGES_SEARCH_PREFIX, REACH_PREFIX, SEARCH_PREFIX, storyFilesCode, storyFilesGroupOf, TEXTS_PREFIX, USAGE_PREFIX } from "./storyFilesModule.js";
|
|
13
|
+
import { EVERY_FILE, FILES_SPECIFIER_PREFIX, indexedStoryFiles, PAGES_SEARCH_PREFIX, REACH_PREFIX, SEARCH_PREFIX, storyFileKeys, storyFilesCode, storyFilesGroupOf, TEXTS_PREFIX, USAGE_PREFIX } from "./storyFilesModule.js";
|
|
14
14
|
import { storyReach } from "./storyReach.js";
|
|
15
15
|
import { joinedUsage } from "./usageModule.js";
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
import { VITE_PATHS } from "./vitePaths.js";
|
|
17
|
+
/**
|
|
18
|
+
* The id of a group of story files' module: virtual, with the declaring module's folder and the patterns after it,
|
|
19
|
+
* whether a `?forgebook-files` import or the group's specifier (`FILES_SPECIFIER_PREFIX`) names it.
|
|
20
|
+
*/
|
|
21
|
+
export const FILES_PREFIX = `\0${FILES_SPECIFIER_PREFIX}`;
|
|
18
22
|
/** The resolved id of a group's "Used in" module: Rollup's mark of a virtual module, then its import's specifier. */
|
|
19
23
|
export const USAGE_ID_PREFIX = `\0${USAGE_PREFIX}`;
|
|
20
24
|
/** The resolved id of a group's reach module, the same way. */
|
|
@@ -51,7 +55,7 @@ export const docsModule = (component, watch) => ({
|
|
|
51
55
|
moduleType: "js"
|
|
52
56
|
});
|
|
53
57
|
/**
|
|
54
|
-
* The module of a
|
|
58
|
+
* The module of a group of story files: every listed story file's index and loaders; with the files, indexed,
|
|
55
59
|
* which the dev server keeps to tell an edit that changes the list.
|
|
56
60
|
*
|
|
57
61
|
* @param id - the module's id (`FILES_PREFIX`, then the group: `storyFilesGroupText`).
|
|
@@ -61,18 +65,51 @@ export const docsModule = (component, watch) => ({
|
|
|
61
65
|
* @param warm - starts reading the docs of a story file ahead of its request; none in a test run.
|
|
62
66
|
* @param startTexts - a build's: starts reading the files' docs, code and pages, which the module imports from the
|
|
63
67
|
* group's texts module (`builtTexts.ts`); none imports each from its query.
|
|
68
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
64
69
|
* @throws when a story file cannot be indexed.
|
|
65
70
|
*/
|
|
66
|
-
export const patternModule = (id, watch, loaders, cache, warm, startTexts) => {
|
|
67
|
-
const { root,
|
|
68
|
-
const files = indexedStoryFiles(root,
|
|
71
|
+
export const patternModule = (id, watch, loaders, cache, warm, startTexts, isKept = EVERY_FILE) => {
|
|
72
|
+
const { root, patterns } = storyFilesGroupOf(id.slice(FILES_PREFIX.length));
|
|
73
|
+
const files = indexedStoryFiles(root, patterns, watch, cache, isKept);
|
|
69
74
|
const [first] = files;
|
|
70
75
|
if (first !== undefined)
|
|
71
76
|
warm?.(first.file);
|
|
72
77
|
startTexts?.(files);
|
|
73
|
-
const code = storyFilesCode(root,
|
|
78
|
+
const code = storyFilesCode(root, patterns, files, loaders, startTexts !== undefined);
|
|
74
79
|
return { code, moduleType: "js", files };
|
|
75
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Whether a story file added or removed changes what a group of story files lists: listed now and not when its module
|
|
83
|
+
* was served, or the other way round. A file no pattern lists, or one a `!` pattern leaves out, changes nothing, so
|
|
84
|
+
* the pages need no reload for it.
|
|
85
|
+
*
|
|
86
|
+
* @param id - the group's module's id (`FILES_PREFIX`, then the group).
|
|
87
|
+
* @param listed - the files its module listed when served, absolute in Vite's form; none when it could not be made.
|
|
88
|
+
* @param file - the file added or removed.
|
|
89
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
90
|
+
*/
|
|
91
|
+
export const isListingChanged = (id, listed, file, isKept = EVERY_FILE) => {
|
|
92
|
+
if (listed === undefined)
|
|
93
|
+
return true;
|
|
94
|
+
const { root, patterns } = storyFilesGroupOf(id.slice(FILES_PREFIX.length));
|
|
95
|
+
const isListed = storyFileKeys(root, patterns, isKept).includes(VITE_PATHS.relativeKey(root, file));
|
|
96
|
+
return isListed !== listed.has(VITE_PATHS.normalize(file));
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The modules a story file added or removed renews: the groups whose list it changes (`isListingChanged`) and, with
|
|
100
|
+
* them, the modules that read their files; none when it changes no list.
|
|
101
|
+
*
|
|
102
|
+
* @param served - the groups' modules, with the files each listed when served.
|
|
103
|
+
* @param file - the file added or removed.
|
|
104
|
+
* @param readers - the modules that read the groups' files: their "Used in" and search indexes.
|
|
105
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
106
|
+
*/
|
|
107
|
+
export const listingRenewals = (served, file, readers, isKept = EVERY_FILE) => {
|
|
108
|
+
const changed = [...served]
|
|
109
|
+
.filter(([id, listed]) => isListingChanged(id, listed, file, isKept))
|
|
110
|
+
.map(([id]) => id);
|
|
111
|
+
return changed.length === 0 ? undefined : [...changed, ...readers];
|
|
112
|
+
};
|
|
76
113
|
/**
|
|
77
114
|
* A group's facts: its story files indexed, what their stories render read in the docs worker.
|
|
78
115
|
*
|
|
@@ -80,10 +117,11 @@ export const patternModule = (id, watch, loaders, cache, warm, startTexts) => {
|
|
|
80
117
|
* @param watch - adds a file whose edit renews the module (each story file).
|
|
81
118
|
* @param usage - reads the facts in the docs worker.
|
|
82
119
|
* @param cache - the pattern's index kept between starts; none reads every file.
|
|
120
|
+
* @param isKept - whether a listed file may be read.
|
|
83
121
|
*/
|
|
84
|
-
const groupUsage = async (group, watch, usage, cache) => {
|
|
85
|
-
const { root,
|
|
86
|
-
const files = indexedStoryFiles(root,
|
|
122
|
+
const groupUsage = async (group, watch, usage, cache, isKept) => {
|
|
123
|
+
const { root, patterns } = storyFilesGroupOf(group);
|
|
124
|
+
const files = indexedStoryFiles(root, patterns, watch, cache, isKept);
|
|
87
125
|
const graph = await usage(files.map((file) => ({
|
|
88
126
|
storyFile: file.file,
|
|
89
127
|
exports: file.index.stories.map((story) => story.exportName)
|
|
@@ -99,9 +137,10 @@ const groupUsage = async (group, watch, usage, cache) => {
|
|
|
99
137
|
* @param usage - reads the facts in the docs worker.
|
|
100
138
|
* @param cache - the pattern's index kept between starts; none reads every file.
|
|
101
139
|
* @param pack - writes the module's JSON as its value: as it is on a dev server, in a gzipped file of a build's.
|
|
140
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
102
141
|
*/
|
|
103
|
-
export const usageModule = async (id, watch, usage, cache, pack) => {
|
|
104
|
-
const { files, graph } = await groupUsage(id.slice(USAGE_ID_PREFIX.length), watch, usage, cache);
|
|
142
|
+
export const usageModule = async (id, watch, usage, cache, pack, isKept = EVERY_FILE) => {
|
|
143
|
+
const { files, graph } = await groupUsage(id.slice(USAGE_ID_PREFIX.length), watch, usage, cache, isKept);
|
|
105
144
|
const answer = typeof graph === "string"
|
|
106
145
|
? { error: graph }
|
|
107
146
|
: packedUsage(joinedUsage(graph, files.map((file) => ({
|
|
@@ -120,9 +159,10 @@ export const usageModule = async (id, watch, usage, cache, pack) => {
|
|
|
120
159
|
* @param watch - adds a file whose edit renews the module (each story file).
|
|
121
160
|
* @param usage - reads the facts in the docs worker.
|
|
122
161
|
* @param cache - the pattern's index kept between starts; none reads every file.
|
|
162
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
123
163
|
*/
|
|
124
|
-
export const reachModule = async (id, watch, usage, cache) => {
|
|
125
|
-
const { files, graph } = await groupUsage(id.slice(REACH_ID_PREFIX.length), watch, usage, cache);
|
|
164
|
+
export const reachModule = async (id, watch, usage, cache, isKept = EVERY_FILE) => {
|
|
165
|
+
const { files, graph } = await groupUsage(id.slice(REACH_ID_PREFIX.length), watch, usage, cache, isKept);
|
|
126
166
|
const reach = typeof graph === "string"
|
|
127
167
|
? []
|
|
128
168
|
: storyReach(graph, files.map((file) => ({ storyFile: file.file, title: file.index.title })));
|
|
@@ -134,7 +174,7 @@ export const reachModule = async (id, watch, usage, cache) => {
|
|
|
134
174
|
*
|
|
135
175
|
* @param id - the module's id.
|
|
136
176
|
* @param watch - adds a file whose edit renews the module.
|
|
137
|
-
* @param read - a story file's component docs,
|
|
177
|
+
* @param read - a story file's component docs, how the module writes its JSON, and which listed files may be read.
|
|
138
178
|
* @returns the index; none for another id.
|
|
139
179
|
*/
|
|
140
180
|
export const searchIndexModule = async (id, watch, read) => {
|
|
@@ -142,17 +182,17 @@ export const searchIndexModule = async (id, watch, read) => {
|
|
|
142
182
|
if (!isPages && !id.startsWith(SEARCH_ID_PREFIX))
|
|
143
183
|
return undefined;
|
|
144
184
|
const { storySearchModule, pagesSearchModule } = await import("./searchModule.js");
|
|
145
|
-
const { root,
|
|
185
|
+
const { root, patterns } = storyFilesGroupOf(id.slice((isPages ? PAGES_SEARCH_ID_PREFIX : SEARCH_ID_PREFIX).length));
|
|
146
186
|
const code = isPages
|
|
147
|
-
? pagesSearchModule(root,
|
|
148
|
-
: await storySearchModule(root,
|
|
187
|
+
? pagesSearchModule(root, patterns, watch, read.pack, read.isKept)
|
|
188
|
+
: await storySearchModule(root, patterns, watch, read.docsOf, read.isServing, read.pack, read.isKept);
|
|
149
189
|
return { module: { code, moduleType: "js" }, isPages };
|
|
150
190
|
};
|
|
151
191
|
/**
|
|
152
192
|
* The search's indexes of a plugin: a build reads each component's docs once, for its page and its index.
|
|
153
193
|
*
|
|
154
|
-
* @param read - reads a story file's component docs, says whether a dev server runs,
|
|
155
|
-
* modules an edit renews (a docs pages' index with the docs pages').
|
|
194
|
+
* @param read - reads a story file's component docs, says whether a dev server runs, keeps each index's id with the
|
|
195
|
+
* modules an edit renews (a docs pages' index with the docs pages'), and says which listed files may be read.
|
|
156
196
|
*/
|
|
157
197
|
export const searchIndexes = (read) => {
|
|
158
198
|
const built = new Map();
|
|
@@ -166,7 +206,12 @@ export const searchIndexes = (read) => {
|
|
|
166
206
|
return {
|
|
167
207
|
docsOf,
|
|
168
208
|
moduleOf: async (id, watch, pack) => {
|
|
169
|
-
const search = await searchIndexModule(id, watch, {
|
|
209
|
+
const search = await searchIndexModule(id, watch, {
|
|
210
|
+
docsOf,
|
|
211
|
+
isServing: read.isServing(),
|
|
212
|
+
pack,
|
|
213
|
+
isKept: read.isKept
|
|
214
|
+
});
|
|
170
215
|
if (search === undefined)
|
|
171
216
|
return undefined;
|
|
172
217
|
read.track(id, search.isPages);
|
|
@@ -86,6 +86,7 @@ export const scannedEntries = (config, resolve, readText) => {
|
|
|
86
86
|
return [];
|
|
87
87
|
return [...text.matchAll(FILES_IMPORT)].flatMap((match) => match[1] === undefined ? [] : [VITE_PATHS.join(VITE_PATHS.dirname(file), match[1])]);
|
|
88
88
|
});
|
|
89
|
-
// the previews too: what they import loads with the first story, and found then it reloads the page
|
|
89
|
+
// the previews too: what they import loads with the first story, and found then it reloads the page; the project's
|
|
90
|
+
// `!` patterns stay as they are, which Vite's scanner reads as fast-glob does, from the same folder
|
|
90
91
|
return [...config.stories, ...fromSources, ...config.previews];
|
|
91
92
|
};
|
|
@@ -2,6 +2,7 @@ import type { DocBlock } from "../docPages.ts";
|
|
|
2
2
|
import type { SearchSection } from "../searchIndex.ts";
|
|
3
3
|
import type { DocsResult } from "./docsExtractor.ts";
|
|
4
4
|
import type { PackJson } from "./packedModule.ts";
|
|
5
|
+
import { type IsFileKept } from "./storyFilesModule.ts";
|
|
5
6
|
/**
|
|
6
7
|
* HTML as stretches of documentation, one per heading that carries an anchor.
|
|
7
8
|
*
|
|
@@ -20,7 +21,7 @@ export declare const blockSections: (blocks: readonly DocBlock[]) => SearchSecti
|
|
|
20
21
|
* A group of story files' search index, as the code of its module.
|
|
21
22
|
*
|
|
22
23
|
* @param root - the declaring module's folder.
|
|
23
|
-
* @param
|
|
24
|
+
* @param patterns - the group's patterns.
|
|
24
25
|
* @param watch - adds a file whose edit renews the module.
|
|
25
26
|
* @param extract - reads a story file's component.
|
|
26
27
|
* @param isServing - whether a dev server runs: only its tools read the problems, which name files on this computer, so
|
|
@@ -28,13 +29,14 @@ export declare const blockSections: (blocks: readonly DocBlock[]) => SearchSecti
|
|
|
28
29
|
* @param pack - writes the index's JSON as the module's value: as it is, or in a gzipped file of a build's own, which
|
|
29
30
|
* few visits read.
|
|
30
31
|
*/
|
|
31
|
-
export declare const storySearchModule: (root: string,
|
|
32
|
+
export declare const storySearchModule: (root: string, patterns: readonly string[], watch: (file: string) => void, extract: (storyFile: string) => Promise<DocsResult>, isServing: boolean, pack: PackJson, isKept?: IsFileKept) => Promise<string>;
|
|
32
33
|
/**
|
|
33
34
|
* A group of docs pages' search index, as the code of its module.
|
|
34
35
|
*
|
|
35
36
|
* @param root - the declaring module's folder.
|
|
36
|
-
* @param
|
|
37
|
+
* @param patterns - the group's patterns.
|
|
37
38
|
* @param watch - adds a file whose edit renews the module.
|
|
38
39
|
* @param pack - writes the index's JSON as the module's value.
|
|
40
|
+
* @param isKept - whether a listed page may be read; every one by default.
|
|
39
41
|
*/
|
|
40
|
-
export declare const pagesSearchModule: (root: string,
|
|
42
|
+
export declare const pagesSearchModule: (root: string, patterns: readonly string[], watch: (file: string) => void, pack: PackJson, isKept?: IsFileKept) => string;
|
|
@@ -14,7 +14,7 @@ import { readFileSync } from "node:fs";
|
|
|
14
14
|
import { componentPage } from "./componentPage.js";
|
|
15
15
|
import { compiledDocPage } from "./docPageMarkdown.js";
|
|
16
16
|
import { indexedDocPages } from "./docPagesModule.js";
|
|
17
|
-
import { indexedStoryFiles } from "./storyFilesModule.js";
|
|
17
|
+
import { EVERY_FILE, indexedStoryFiles } from "./storyFilesModule.js";
|
|
18
18
|
/** A heading of the pages' HTML: its anchor, and what is inside it. */
|
|
19
19
|
const HEADING = /<h[1-6] id="doc-([^"]*)"[^>]*>([\s\S]*?)<\/h[1-6]>/g;
|
|
20
20
|
/** A tag: `>` inside a quoted attribute does not end it. */
|
|
@@ -177,7 +177,7 @@ const entryOf = (file, read, watch) => {
|
|
|
177
177
|
* A group of story files' search index, as the code of its module.
|
|
178
178
|
*
|
|
179
179
|
* @param root - the declaring module's folder.
|
|
180
|
-
* @param
|
|
180
|
+
* @param patterns - the group's patterns.
|
|
181
181
|
* @param watch - adds a file whose edit renews the module.
|
|
182
182
|
* @param extract - reads a story file's component.
|
|
183
183
|
* @param isServing - whether a dev server runs: only its tools read the problems, which name files on this computer, so
|
|
@@ -185,8 +185,8 @@ const entryOf = (file, read, watch) => {
|
|
|
185
185
|
* @param pack - writes the index's JSON as the module's value: as it is, or in a gzipped file of a build's own, which
|
|
186
186
|
* few visits read.
|
|
187
187
|
*/
|
|
188
|
-
export const storySearchModule = async (root,
|
|
189
|
-
const files = indexedStoryFiles(root,
|
|
188
|
+
export const storySearchModule = async (root, patterns, watch, extract, isServing, pack, isKept = EVERY_FILE) => {
|
|
189
|
+
const files = indexedStoryFiles(root, patterns, watch, undefined, isKept);
|
|
190
190
|
const entries = await Promise.all(files.map(async (file) => ({ file, ...entryOf(file, await extract(file.file), watch) })));
|
|
191
191
|
const problems = entries.flatMap(({ problem }) => problem ?? []);
|
|
192
192
|
const index = {
|
|
@@ -199,12 +199,13 @@ export const storySearchModule = async (root, pattern, watch, extract, isServing
|
|
|
199
199
|
* A group of docs pages' search index, as the code of its module.
|
|
200
200
|
*
|
|
201
201
|
* @param root - the declaring module's folder.
|
|
202
|
-
* @param
|
|
202
|
+
* @param patterns - the group's patterns.
|
|
203
203
|
* @param watch - adds a file whose edit renews the module.
|
|
204
204
|
* @param pack - writes the index's JSON as the module's value.
|
|
205
|
+
* @param isKept - whether a listed page may be read; every one by default.
|
|
205
206
|
*/
|
|
206
|
-
export const pagesSearchModule = (root,
|
|
207
|
-
const pages = indexedDocPages(root,
|
|
207
|
+
export const pagesSearchModule = (root, patterns, watch, pack, isKept = EVERY_FILE) => {
|
|
208
|
+
const pages = indexedDocPages(root, patterns, watch, [], isKept).map(({ key, file }) => [
|
|
208
209
|
key,
|
|
209
210
|
blockSections(compiledDocPage(file, readFileSync(file, "utf8")).blocks)
|
|
210
211
|
]);
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
import type { StoryFileIndex } from "@forgebook/story-format/source";
|
|
2
2
|
import { type DiskCache } from "./diskCache.ts";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* A group of story files and the folder its patterns are read from: the declaring module's folder, the import's
|
|
5
|
+
* patterns.
|
|
6
|
+
*/
|
|
4
7
|
export type StoryFilesGroup = {
|
|
5
8
|
/** The declaring module's folder, absolute: the files' keys are relative to it. */
|
|
6
9
|
readonly root: string;
|
|
7
|
-
/**
|
|
8
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The patterns relative to it, their leading `./` dropped (`../src/**\/*.stories.tsx`), and the `!` ones that leave
|
|
12
|
+
* files out (`listedFiles`).
|
|
13
|
+
*/
|
|
14
|
+
readonly patterns: readonly string[];
|
|
9
15
|
};
|
|
16
|
+
/** Between a group's parts in a module's id: no path or pattern holds it. */
|
|
17
|
+
export declare const GROUP_SEPARATOR = "::";
|
|
10
18
|
/**
|
|
11
|
-
* A
|
|
12
|
-
* of
|
|
13
|
-
* before it (`app::../storybook`: the folder and the separator), so
|
|
19
|
+
* A group of story files written for a module's id: the folder, then for each pattern how many folders it climbs and
|
|
20
|
+
* the rest of it. A Vite module's id is served under a URL path, whose normalisation would let a `..` remove the part
|
|
21
|
+
* before it (`app::../storybook`: the folder and the separator), so a pattern's leading `../` are counted, never
|
|
14
22
|
* written. The files keep their keys relative to the declaring module (`../src/x.stories.tsx`), unique in a source and
|
|
15
23
|
* the testing package's too.
|
|
16
24
|
*
|
|
17
25
|
* @param folder - the declaring module's folder.
|
|
18
|
-
* @param
|
|
26
|
+
* @param patterns - the patterns as the import or the configuration writes them (`../src/**\/*.stories.tsx`).
|
|
19
27
|
*/
|
|
20
|
-
export declare const storyFilesGroupText: (folder: string,
|
|
28
|
+
export declare const storyFilesGroupText: (folder: string, patterns: readonly string[]) => string;
|
|
21
29
|
/**
|
|
22
30
|
* A group read back from a module's id (`storyFilesGroupText`).
|
|
23
31
|
*
|
|
@@ -25,12 +33,31 @@ export declare const storyFilesGroupText: (folder: string, pattern: string) => s
|
|
|
25
33
|
*/
|
|
26
34
|
export declare const storyFilesGroupOf: (text: string) => StoryFilesGroup;
|
|
27
35
|
/**
|
|
28
|
-
*
|
|
36
|
+
* Whether a file a group lists may be read. A dev server refuses what `server.fs.deny` names (`fileAccess.ts`).
|
|
37
|
+
*
|
|
38
|
+
* @param file - the file, absolute in Vite's form.
|
|
39
|
+
*/
|
|
40
|
+
export type IsFileKept = (file: string) => boolean;
|
|
41
|
+
/** Every file a group lists: a build's, and a test's that reads the files from the disk. */
|
|
42
|
+
export declare const EVERY_FILE: IsFileKept;
|
|
43
|
+
/**
|
|
44
|
+
* The story files patterns list, as paths relative to `root` starting with `./` or `../`, each once, sorted: the union
|
|
45
|
+
* of the patterns less what the `!` ones match (`listedFiles`).
|
|
29
46
|
*
|
|
30
47
|
* @param root - the folder the patterns are relative to: the declaring module's.
|
|
31
|
-
* @param patterns - the patterns (`../src/**\/*.stories.tsx
|
|
48
|
+
* @param patterns - the patterns (`../src/**\/*.stories.tsx`, `!../src/**\/legacy/*`).
|
|
49
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
50
|
+
* @throws when every pattern is a `!` one.
|
|
51
|
+
*/
|
|
52
|
+
export declare const storyFileKeys: (root: string, patterns: readonly string[], isKept?: IsFileKept) => string[];
|
|
53
|
+
/**
|
|
54
|
+
* The specifier prefix of a group of story files named by its patterns, the group following (`storyFilesGroupText`):
|
|
55
|
+
* how the module generated for a catalogue's `stories` imports them as one group, `!` patterns included, which a
|
|
56
|
+
* `?forgebook-files` import of one pattern cannot say.
|
|
32
57
|
*/
|
|
33
|
-
export declare const
|
|
58
|
+
export declare const FILES_SPECIFIER_PREFIX = "virtual:forgebook-files:";
|
|
59
|
+
/** The specifier prefix of a group of docs pages named by its patterns, the same way: a catalogue's `docs`. */
|
|
60
|
+
export declare const DOCS_PAGES_SPECIFIER_PREFIX = "virtual:forgebook-docs-pages:";
|
|
34
61
|
/**
|
|
35
62
|
* The id prefix of a group's "Used in" module: the group follows (`storyFilesGroupText`), as in a `?forgebook-files`
|
|
36
63
|
* module's id. The plugin answers it (`usageModule.ts`) only when a page asks.
|
|
@@ -53,66 +80,71 @@ export declare const TEXTS_PREFIX = "virtual:forgebook-texts:";
|
|
|
53
80
|
* it, so a page that shows "Used in" never downloads it.
|
|
54
81
|
*/
|
|
55
82
|
export declare const REACH_PREFIX = "virtual:forgebook-reach:";
|
|
56
|
-
/** A story file a
|
|
83
|
+
/** A story file a group lists, with its key, the pattern that lists it and its index. */
|
|
57
84
|
export type IndexedStoryFile = {
|
|
58
85
|
/** Its path relative to the declaring module (`../src/x.stories.tsx`). */
|
|
59
86
|
readonly key: string;
|
|
87
|
+
/** The group's first pattern that lists it, whose static start begins its title when its meta writes none. */
|
|
88
|
+
readonly pattern: string;
|
|
60
89
|
/** Its absolute path. */
|
|
61
90
|
readonly file: string;
|
|
62
91
|
/** Its index. */
|
|
63
92
|
readonly index: StoryFileIndex;
|
|
64
93
|
};
|
|
65
|
-
/** A
|
|
94
|
+
/** A group's index as it is kept between starts, by file key. */
|
|
66
95
|
export type KeptIndex = Readonly<Record<string, StoryFileIndex>>;
|
|
67
|
-
/** Whether what a cache file holds is a
|
|
96
|
+
/** Whether what a cache file holds is a group's index. */
|
|
68
97
|
export declare const isKeptIndex: (value: unknown) => value is KeptIndex;
|
|
69
98
|
/**
|
|
70
|
-
* One story file a pattern
|
|
99
|
+
* One story file a pattern lists, indexed from its text on disk, with the title its path makes when it writes none.
|
|
71
100
|
*
|
|
72
101
|
* @internal
|
|
73
102
|
* @param root - the declaring module's folder.
|
|
74
|
-
* @param pattern - the pattern.
|
|
103
|
+
* @param pattern - the pattern that lists it.
|
|
75
104
|
* @param key - the file's path relative to the declaring module.
|
|
76
105
|
* @returns the index, or a message saying why the file cannot be indexed.
|
|
77
106
|
*/
|
|
78
107
|
export declare const storyFileIndex: (root: string, pattern: string, key: string) => StoryFileIndex | string;
|
|
79
108
|
/**
|
|
80
|
-
* Every story file a
|
|
109
|
+
* Every story file a group's patterns list, indexed.
|
|
81
110
|
*
|
|
82
111
|
* @param root - the declaring module's folder.
|
|
83
|
-
* @param
|
|
112
|
+
* @param patterns - the patterns (`storyFileKeys`).
|
|
84
113
|
* @param watch - adds a file whose edit renews the module that read it.
|
|
85
114
|
* @param cache - the index kept between starts, which holds while the files it came from do; none reads them all.
|
|
115
|
+
* @param isKept - whether a listed file may be read; every one by default.
|
|
86
116
|
* @throws when a story file cannot be indexed.
|
|
87
117
|
*/
|
|
88
|
-
export declare const indexedStoryFiles: (root: string,
|
|
118
|
+
export declare const indexedStoryFiles: (root: string, patterns: readonly string[], watch: (file: string) => void, cache?: DiskCache<KeptIndex>, isKept?: IsFileKept) => IndexedStoryFile[];
|
|
89
119
|
/** The loaders a group offers besides its story files'. */
|
|
90
120
|
export type GroupLoaders = {
|
|
121
|
+
/** Whether it offers each story file's component docs (the catalogue reads them); `true` by default. */
|
|
122
|
+
readonly hasDocs?: boolean;
|
|
91
123
|
/** Whether it offers its "Used in" (the catalogue did not turn it off). */
|
|
92
124
|
readonly hasUsage: boolean;
|
|
93
125
|
/** Whether it offers what each story reaches: only on a dev server, for its tools. */
|
|
94
126
|
readonly hasReach: boolean;
|
|
95
127
|
};
|
|
96
128
|
/**
|
|
97
|
-
* The code of the module for one
|
|
129
|
+
* The code of the module for one group.
|
|
98
130
|
*
|
|
99
131
|
* @param root - the declaring module's folder.
|
|
100
|
-
* @param
|
|
132
|
+
* @param patterns - the group's patterns.
|
|
101
133
|
* @param watch - adds a file whose edit renews the module (each story file: its index is in the module).
|
|
102
|
-
* @param loaders - the group's loaders besides its story files';
|
|
134
|
+
* @param loaders - the group's loaders besides its story files'; all of them by default.
|
|
103
135
|
* @param cache - the index kept between starts.
|
|
104
136
|
* @returns the module's code, or a message saying which file cannot be indexed.
|
|
105
137
|
*/
|
|
106
|
-
export declare const storyFilesModule: (root: string,
|
|
138
|
+
export declare const storyFilesModule: (root: string, patterns: readonly string[], watch: (file: string) => void, loaders?: GroupLoaders, cache?: DiskCache<KeptIndex>) => string;
|
|
107
139
|
/**
|
|
108
|
-
* The code of the module for one
|
|
140
|
+
* The code of the module for one group, from its story files indexed.
|
|
109
141
|
*
|
|
110
142
|
* @internal
|
|
111
143
|
* @param root - the declaring module's folder.
|
|
112
|
-
* @param
|
|
113
|
-
* @param files - the story files it
|
|
144
|
+
* @param patterns - the group's patterns.
|
|
145
|
+
* @param files - the story files it lists, indexed.
|
|
114
146
|
* @param loaders - the group's loaders besides its story files'.
|
|
115
147
|
* @param hasTexts - a build's: whether each file's docs, code and page come from the group's texts module, in the
|
|
116
148
|
* rows' order (`TEXTS_PREFIX`), and not each from its query.
|
|
117
149
|
*/
|
|
118
|
-
export declare const storyFilesCode: (root: string,
|
|
150
|
+
export declare const storyFilesCode: (root: string, patterns: readonly string[], files: readonly IndexedStoryFile[], loaders: GroupLoaders, hasTexts?: boolean) => string;
|