@warlock.js/grimoire 5.57.0 → 5.58.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/CHANGELOG.md +20 -0
- package/esm/book/build.d.mts.map +1 -1
- package/esm/book/build.mjs +2 -1
- package/esm/book/build.mjs.map +1 -1
- package/esm/book/render.mjs +10 -0
- package/esm/book/render.mjs.map +1 -1
- package/esm/bookmap/build.d.mts.map +1 -1
- package/esm/bookmap/build.mjs +2 -2
- package/esm/bookmap/build.mjs.map +1 -1
- package/esm/bookmap/steps.mjs +53 -38
- package/esm/bookmap/steps.mjs.map +1 -1
- package/esm/check/check-grimoire.d.mts.map +1 -1
- package/esm/check/check-grimoire.mjs +4 -1
- package/esm/check/check-grimoire.mjs.map +1 -1
- package/esm/check/rules/criteria.mjs +21 -2
- package/esm/check/rules/criteria.mjs.map +1 -1
- package/esm/check/rules/screenshots.mjs +57 -0
- package/esm/check/rules/screenshots.mjs.map +1 -0
- package/esm/codes/codes.d.mts +12 -0
- package/esm/codes/codes.d.mts.map +1 -1
- package/esm/codes/codes.mjs +6 -0
- package/esm/codes/codes.mjs.map +1 -1
- package/esm/contracts/adapter.d.mts +6 -0
- package/esm/contracts/adapter.d.mts.map +1 -1
- package/esm/contracts/book.d.mts +2 -0
- package/esm/contracts/book.d.mts.map +1 -1
- package/esm/contracts/book.mjs.map +1 -1
- package/esm/contracts/bookmap.d.mts +19 -1
- package/esm/contracts/bookmap.d.mts.map +1 -1
- package/esm/contracts/snapshot.d.mts +11 -0
- package/esm/contracts/snapshot.d.mts.map +1 -1
- package/esm/contracts/test-results.d.mts +34 -0
- package/esm/contracts/test-results.d.mts.map +1 -1
- package/esm/contracts/written.d.mts +44 -0
- package/esm/contracts/written.d.mts.map +1 -1
- package/esm/contracts/written.mjs.map +1 -1
- package/esm/devtools/data.mjs +94 -3
- package/esm/devtools/data.mjs.map +1 -1
- package/esm/devtools/index.d.mts +26 -0
- package/esm/devtools/index.d.mts.map +1 -1
- package/esm/devtools/index.mjs +88 -5
- package/esm/devtools/index.mjs.map +1 -1
- package/esm/devtools/product-map.d.mts +14 -0
- package/esm/devtools/product-map.d.mts.map +1 -0
- package/esm/devtools/product-map.mjs +385 -0
- package/esm/devtools/product-map.mjs.map +1 -0
- package/esm/devtools/site.d.mts.map +1 -1
- package/esm/devtools/site.mjs +85 -13
- package/esm/devtools/site.mjs.map +1 -1
- package/esm/devtools/snapshot-source.mjs +10 -6
- package/esm/devtools/snapshot-source.mjs.map +1 -1
- package/esm/graph/index.d.mts +10 -1
- package/esm/graph/index.d.mts.map +1 -1
- package/esm/graph/index.mjs +3 -2
- package/esm/graph/index.mjs.map +1 -1
- package/esm/index.d.mts +4 -4
- package/esm/paths/index.d.mts +2 -0
- package/esm/paths/index.d.mts.map +1 -1
- package/esm/paths/index.mjs +3 -1
- package/esm/paths/index.mjs.map +1 -1
- package/esm/scry/compact.mjs +169 -0
- package/esm/scry/compact.mjs.map +1 -0
- package/esm/scry/format.d.mts.map +1 -1
- package/esm/scry/format.mjs +7 -1
- package/esm/scry/format.mjs.map +1 -1
- package/esm/scry/query.d.mts.map +1 -1
- package/esm/scry/query.mjs +12 -1
- package/esm/scry/query.mjs.map +1 -1
- package/esm/test-results/index.d.mts +7 -2
- package/esm/test-results/index.d.mts.map +1 -1
- package/esm/test-results/index.mjs +79 -12
- package/esm/test-results/index.mjs.map +1 -1
- package/esm/vitest/index.d.mts +6 -0
- package/esm/vitest/index.d.mts.map +1 -1
- package/esm/vitest/index.mjs +22 -6
- package/esm/vitest/index.mjs.map +1 -1
- package/esm/warlock/adapter.d.mts.map +1 -1
- package/esm/warlock/adapter.mjs +6 -2
- package/esm/warlock/adapter.mjs.map +1 -1
- package/esm/warlock/mcp-tools.mjs +48 -12
- package/esm/warlock/mcp-tools.mjs.map +1 -1
- package/esm/workspace/index.d.mts.map +1 -1
- package/esm/workspace/index.mjs +4 -2
- package/esm/workspace/index.mjs.map +1 -1
- package/esm/written/apps.mjs +4 -2
- package/esm/written/apps.mjs.map +1 -1
- package/esm/written/features.mjs +119 -6
- package/esm/written/features.mjs.map +1 -1
- package/esm/written/markdown.mjs +66 -1
- package/esm/written/markdown.mjs.map +1 -1
- package/esm/written/parse-grimoire.d.mts.map +1 -1
- package/esm/written/parse-grimoire.mjs +1 -1
- package/esm/written/parse-grimoire.mjs.map +1 -1
- package/llms-full.txt +76 -3
- package/package.json +3 -3
- package/skills/backfill-a-grimoire/SKILL.md +5 -0
- package/skills/describe-an-app/SKILL.md +12 -0
- package/skills/record-a-change/SKILL.md +8 -0
- package/skills/use-the-grimoire/SKILL.md +14 -1
- package/skills/write-a-feature/SKILL.md +37 -2
- package/ui/grimoire-static.js +4 -0
- package/ui/grimoire-view.js +1016 -178
- package/ui/grimoire.css +427 -2
- package/ui/product-map.css +636 -0
- package/ui/product-map.js +817 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"site.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"mappings":";;;;YAiBY;;EAEV;;EAEA,UAAU,qBAAqB,QAAQ;;EAEvC,WAAW;;;;;;;;;;;;;wBAwSS,mBACpB,cACA,UAAS,4BACR"}
|
package/esm/devtools/site.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { GRIMOIRE_PATHS, projectPath, toPosixPath } from "../paths/index.mjs";
|
|
2
2
|
import { featureGraph, fileGraph, pageGraph } from "./graphs.mjs";
|
|
3
|
-
import { apps, check, feature, features, file,
|
|
3
|
+
import { apps, check, checkGroups, feature, features, file, flowAnswer, graphOfModules, page, releases, summary, tasks } from "./data.mjs";
|
|
4
|
+
import { productFeature, productFlow, productMap } from "./product-map.mjs";
|
|
4
5
|
import { createSnapshotSource } from "./snapshot-source.mjs";
|
|
5
6
|
import path from "node:path";
|
|
6
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { copyFile, mkdir, readFile, realpath, stat, writeFile } from "node:fs/promises";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
8
9
|
|
|
9
10
|
//#region ../../packages/grimoire/src/devtools/site.ts
|
|
@@ -29,6 +30,14 @@ function buildSiteData(snapshot) {
|
|
|
29
30
|
},
|
|
30
31
|
"graph/modules": graphOfModules(snapshot)
|
|
31
32
|
};
|
|
33
|
+
const productOptions = {
|
|
34
|
+
shared: false,
|
|
35
|
+
errors: null
|
|
36
|
+
};
|
|
37
|
+
const productAnswer = attempt(() => productMap(snapshot, productOptions));
|
|
38
|
+
const groups = attempt(() => checkGroups(snapshot));
|
|
39
|
+
if (productAnswer !== void 0) routes.product = productAnswer;
|
|
40
|
+
if (groups !== void 0) routes["check/groups"] = groups;
|
|
32
41
|
const search = [];
|
|
33
42
|
for (const release of snapshot.written.releases) routes[`releases/${release.release.value}`] = release;
|
|
34
43
|
for (const feature$1 of snapshot.written.features) {
|
|
@@ -42,14 +51,18 @@ function buildSiteData(snapshot) {
|
|
|
42
51
|
if (answered !== void 0) routes[`features/${feature$1.id}`] = answered;
|
|
43
52
|
const graph = featureGraph(snapshot, feature$1.id);
|
|
44
53
|
if (graph !== null) routes[`graph/feature/${feature$1.id}`] = graph;
|
|
45
|
-
|
|
54
|
+
const product = attempt(() => productFeature(snapshot, feature$1.id, productOptions));
|
|
55
|
+
if (product !== void 0) routes[`product/features/${feature$1.id}`] = product;
|
|
56
|
+
for (const flow of feature$1.flows) {
|
|
46
57
|
search.push({
|
|
47
58
|
type: "flow",
|
|
48
|
-
id: flow
|
|
49
|
-
detail: flow
|
|
59
|
+
id: flow.ref,
|
|
60
|
+
detail: flow.heading?.value ?? null
|
|
50
61
|
});
|
|
51
|
-
const flowAnswer = attempt(() =>
|
|
52
|
-
|
|
62
|
+
const flowAnswer$1 = attempt(() => flowAnswer(snapshot, feature$1.id, flow.id.value));
|
|
63
|
+
const productFlowAnswer = attempt(() => productFlow(snapshot, feature$1.id, flow.id.value, productOptions));
|
|
64
|
+
if (flowAnswer$1 !== void 0) routes[`flows/${flow.ref}`] = flowAnswer$1;
|
|
65
|
+
if (productFlowAnswer !== void 0) routes[`product/flows/${flow.ref}`] = productFlowAnswer;
|
|
53
66
|
}
|
|
54
67
|
}
|
|
55
68
|
for (const app of snapshot.written.apps) {
|
|
@@ -113,6 +126,51 @@ function inlineJson(value) {
|
|
|
113
126
|
function inlineCode(code) {
|
|
114
127
|
return code.replace(/<\/(script)/gi, "<\\/$1").replaceAll("<!--", "<\\!--");
|
|
115
128
|
}
|
|
129
|
+
/** The image types the export copies (the same list the devtools panel serves). */
|
|
130
|
+
const SCREENSHOT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
131
|
+
".png",
|
|
132
|
+
".jpg",
|
|
133
|
+
".jpeg",
|
|
134
|
+
".webp",
|
|
135
|
+
".gif"
|
|
136
|
+
]);
|
|
137
|
+
/** Every `WrittenScreenshot.path` in the written files, once each. */
|
|
138
|
+
function collectScreenshotPaths(written) {
|
|
139
|
+
const found = /* @__PURE__ */ new Set();
|
|
140
|
+
const walk = (value) => {
|
|
141
|
+
if (Array.isArray(value)) for (const item of value) walk(item);
|
|
142
|
+
else if (value !== null && typeof value === "object") {
|
|
143
|
+
const record = value;
|
|
144
|
+
if (typeof record.path === "string" && typeof record.written === "string" && typeof record.alt === "string") found.add(record.path);
|
|
145
|
+
for (const item of Object.values(record)) walk(item);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
walk(written);
|
|
149
|
+
return [...found].sort();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Copy the screenshots the written files use into `<out>/screenshots/`. A path that leaves
|
|
153
|
+
* `grimoire/screenshots/`, has another extension or does not exist is skipped.
|
|
154
|
+
*
|
|
155
|
+
* @returns The paths that were copied.
|
|
156
|
+
*/
|
|
157
|
+
async function copyScreenshots(root, outFolder, paths) {
|
|
158
|
+
const folder = await realpath(path.join(root, GRIMOIRE_PATHS.screenshots)).catch(() => null);
|
|
159
|
+
const copied = [];
|
|
160
|
+
if (folder === null) return copied;
|
|
161
|
+
for (const written of paths) {
|
|
162
|
+
const segments = written.split("/");
|
|
163
|
+
if (written === "" || written.includes("\\") || written.includes("\0") || path.isAbsolute(written) || segments.some((segment) => segment === "" || segment === "." || segment === "..") || !SCREENSHOT_EXTENSIONS.has(path.extname(written).toLowerCase())) continue;
|
|
164
|
+
const source = await realpath(path.join(folder, ...segments)).catch(() => null);
|
|
165
|
+
if (source === null || !source.startsWith(folder + path.sep)) continue;
|
|
166
|
+
if (!(await stat(source)).isFile()) continue;
|
|
167
|
+
const target = path.join(outFolder, "screenshots", ...segments);
|
|
168
|
+
await mkdir(path.dirname(target), { recursive: true });
|
|
169
|
+
await copyFile(source, target);
|
|
170
|
+
copied.push(written);
|
|
171
|
+
}
|
|
172
|
+
return copied;
|
|
173
|
+
}
|
|
116
174
|
/** The answer, or `undefined` when the item cannot be answered (the export skips it). */
|
|
117
175
|
function attempt(answer) {
|
|
118
176
|
try {
|
|
@@ -128,6 +186,15 @@ function inlineView(source) {
|
|
|
128
186
|
return source.replace(marker, "");
|
|
129
187
|
}
|
|
130
188
|
/**
|
|
189
|
+
* The product map module as inline code: its `export` keywords are removed and the Grimoire view
|
|
190
|
+
* finds it as `globalThis.grimoireProductMap`.
|
|
191
|
+
*/
|
|
192
|
+
function inlineProductMap(source) {
|
|
193
|
+
const marker = "export default renderProductMap;";
|
|
194
|
+
if (!source.includes(marker)) throw new Error("product-map.js must end with `export default renderProductMap;`.");
|
|
195
|
+
return `${source.replace(marker, "").replace(/^export (async )?function /gm, "$1function ")}\nglobalThis.grimoireProductMap = { productMapView };\n`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
131
198
|
* The page's own styles: it defines every devtools panel token (light, then dark under
|
|
132
199
|
* `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.
|
|
133
200
|
* The values keep text AA on `--background` and `--card`.
|
|
@@ -142,14 +209,14 @@ main{max-width:1180px;margin:0 auto;padding:16px}
|
|
|
142
209
|
/** The `index.html` text. */
|
|
143
210
|
function renderSiteHtml(siteData, sources) {
|
|
144
211
|
const json = inlineJson(siteData);
|
|
145
|
-
const script = inlineCode(`${inlineView(sources.view)}\n${sources.loader}\ngrimoireStaticMount(JSON.parse(document.getElementById("grimoire-data").textContent), document.getElementById("grimoire-root"), renderGrimoire);\n`);
|
|
212
|
+
const script = inlineCode(`${sources.productMap === void 0 ? "" : inlineProductMap(sources.productMap)}${inlineView(sources.view)}\n${sources.loader}\ngrimoireStaticMount(JSON.parse(document.getElementById("grimoire-data").textContent), document.getElementById("grimoire-root"), renderGrimoire);\n`);
|
|
146
213
|
return `<!doctype html>
|
|
147
214
|
<html lang="en">
|
|
148
215
|
<head>
|
|
149
216
|
<meta charset="utf-8">
|
|
150
217
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
151
218
|
<title>Grimoire</title>
|
|
152
|
-
<style>${PAGE_STYLE}${sources.css}</style>
|
|
219
|
+
<style>${PAGE_STYLE}${sources.css}${sources.productCss ?? ""}</style>
|
|
153
220
|
</head>
|
|
154
221
|
<body>
|
|
155
222
|
<main id="grimoire-root"><p class="empty">Opening the book…</p></main>
|
|
@@ -173,22 +240,27 @@ function renderSiteHtml(siteData, sources) {
|
|
|
173
240
|
async function exportGrimoireSite(root, options = {}) {
|
|
174
241
|
const outDir = projectPath(root, toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite)).replace(/\/+$/, "");
|
|
175
242
|
const snapshot = options.snapshot ?? await createSnapshotSource(root, options.adapter === void 0 ? {} : { adapter: options.adapter }).get();
|
|
176
|
-
const [view, loader, css] = await Promise.all([
|
|
243
|
+
const [view, loader, css, productMapSource, productCss] = await Promise.all([
|
|
177
244
|
"grimoire-view.js",
|
|
178
245
|
"grimoire-static.js",
|
|
179
|
-
"grimoire.css"
|
|
246
|
+
"grimoire.css",
|
|
247
|
+
"product-map.js",
|
|
248
|
+
"product-map.css"
|
|
180
249
|
].map((name) => readFile(path.join(uiFolder, name), "utf8")));
|
|
181
250
|
const html = renderSiteHtml(buildSiteData(snapshot), {
|
|
182
251
|
view: view ?? "",
|
|
183
252
|
loader: loader ?? "",
|
|
184
|
-
css: css ?? ""
|
|
253
|
+
css: css ?? "",
|
|
254
|
+
productMap: productMapSource ?? "",
|
|
255
|
+
productCss: productCss ?? ""
|
|
185
256
|
});
|
|
186
257
|
const absolute = path.resolve(root, outDir);
|
|
187
258
|
await mkdir(absolute, { recursive: true });
|
|
188
259
|
await writeFile(path.join(absolute, "index.html"), html);
|
|
260
|
+
await copyScreenshots(root, absolute, collectScreenshotPaths(snapshot.written));
|
|
189
261
|
return outDir;
|
|
190
262
|
}
|
|
191
263
|
|
|
192
264
|
//#endregion
|
|
193
|
-
export { PAGE_STYLE, SITE_FILE_LIMIT, buildSiteData, exportGrimoireSite, inlineView, renderSiteHtml };
|
|
265
|
+
export { PAGE_STYLE, SITE_FILE_LIMIT, buildSiteData, collectScreenshotPaths, copyScreenshots, exportGrimoireSite, inlineProductMap, inlineView, renderSiteHtml };
|
|
194
266
|
//# sourceMappingURL=site.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.mjs","names":["data.summary","data.features","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","feature","data.feature","flow","data.flow","page","data.page","file","data.file"],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"sourcesContent":["/**\n * The static export: one folder with an `index.html` that holds the view, the\n * loader, the styles and the data as JSON. It opens from disk (`file://`) or\n * any static host and needs no running app.\n */\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS, projectPath, toPosixPath } from \"../paths\";\nimport * as data from \"./data\";\nimport { featureGraph, fileGraph, pageGraph } from \"./graphs\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\n/** Options of `exportGrimoireSite()`. */\nexport type ExportGrimoireSiteOptions = {\n /** Output folder, project-relative or absolute. Default `grimoire/book/site` (the book writer leaves it alone and git ignores it). */\n outDir?: string;\n /** The adapter to open the book with. Default: the Warlock adapter. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /** An already opened snapshot; skips opening one. */\n snapshot?: GrimoireSnapshot;\n};\n\n/** The most files the export keeps per-file answers for (the most imported first). */\nexport const SITE_FILE_LIMIT = 3000;\n\ntype SearchItem = { type: string; id: string; detail: string | null };\n\nconst uiFolder = fileURLToPath(new URL(\"../../ui/\", import.meta.url));\n\n/** Every answer the static page can give, keyed by the data route it replaces. */\nexport function buildSiteData(snapshot: GrimoireSnapshot) {\n const routes: Record<string, unknown> = {\n summary: data.summary(snapshot),\n features: data.features(snapshot),\n apps: data.apps(snapshot),\n tasks: data.tasks(snapshot),\n releases: data.releases(snapshot),\n // The page is meant to be shared: it does not name where the project sits on this machine.\n check: { ...data.check(snapshot), root: \".\" },\n \"graph/modules\": data.graphOfModules(snapshot),\n };\n const search: SearchItem[] = [];\n\n for (const release of snapshot.written.releases) {\n routes[`releases/${release.release.value}`] = release;\n }\n\n for (const feature of snapshot.written.features) {\n const readme = feature.readme;\n\n search.push({ type: \"feature\", id: feature.id, detail: readme?.title.value ?? null });\n const answered = attempt(() => data.feature(snapshot, feature.id));\n\n if (answered !== undefined) routes[`features/${feature.id}`] = answered;\n\n const graph = featureGraph(snapshot, feature.id);\n\n if (graph !== null) routes[`graph/feature/${feature.id}`] = graph;\n\n for (const flow of feature.flows) {\n search.push({ type: \"flow\", id: flow.ref, detail: flow.heading?.value ?? null });\n const flowAnswer = attempt(() => data.flow(snapshot, feature.id, flow.id.value));\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n }\n }\n\n for (const app of snapshot.written.apps) {\n const appId = app.id.value;\n\n for (const page of [...app.pages, ...app.screens]) {\n const route = page.route?.value ?? page.screen?.value ?? null;\n const answer = attempt(() => data.page(snapshot, appId, page.id));\n const graph = pageGraph(snapshot, appId, page.id);\n\n for (const key of new Set([page.id, ...(route === null ? [] : [route])])) {\n if (answer !== undefined) routes[`apps/${appId}/pages/${key}`] = answer;\n\n if (graph !== null) routes[`graph/page/${appId}/${key}`] = graph;\n }\n\n if (route !== null)\n search.push({\n type: page.type,\n id: `${appId} ${route}`,\n detail: page.heading?.value ?? null,\n });\n\n for (const block of page.blockFiles) {\n search.push({\n type: \"block\",\n id: `${appId}/${page.id}/${block.id}`,\n detail: block.flow?.value ?? null,\n });\n }\n }\n }\n\n for (const found of snapshot.book.facts.routes ?? []) {\n search.push({\n type: \"route\",\n id: `${found.method} ${found.path}`,\n detail: found.description ?? found.handler,\n });\n }\n\n for (const task of snapshot.collected.tasksIndex.open.concat(\n snapshot.collected.tasksIndex.done,\n )) {\n search.push({ type: \"task\", id: task.id, detail: task.title });\n }\n\n const files: Record<string, { result: unknown; graph: unknown }> = {};\n const ranked = [...snapshot.book.facts.files].sort(\n (left, right) =>\n right.importedBy.length - left.importedBy.length || left.file.localeCompare(right.file),\n );\n\n for (const [index, file] of ranked.entries()) {\n search.push({ type: \"file\", id: file.file, detail: file.about });\n\n if (index >= SITE_FILE_LIMIT) continue;\n\n const result = attempt(() => data.file(snapshot, file.file));\n\n if (result !== undefined) files[file.file] = { result, graph: fileGraph(snapshot, file.file) };\n }\n\n return { routes, files, search };\n}\n\n/** JSON for an inline `<script>`: every `<` is escaped, so no `</script` or `<!--` can appear. */\nfunction inlineJson(value: unknown): string {\n return JSON.stringify(value).replaceAll(\"<\", \"\\\\u003c\");\n}\n\n/** Code for an inline `<script>`: `</script` (in any case) and `<!--` (only possible in strings and comments) are broken up. */\nfunction inlineCode(code: string): string {\n return code.replace(/<\\/(script)/gi, \"<\\\\/$1\").replaceAll(\"<!--\", \"<\\\\!--\");\n}\n\n/** The answer, or `undefined` when the item cannot be answered (the export skips it). */\nfunction attempt<Value>(answer: () => Value): Value | undefined {\n try {\n return answer();\n } catch {\n return undefined;\n }\n}\n\n/** Everything before the page's `export default`, so the view can sit in an inline module. */\nexport function inlineView(source: string): string {\n const marker = \"export default renderGrimoire;\";\n\n if (!source.includes(marker))\n throw new Error(\"grimoire-view.js must end with `export default renderGrimoire;`.\");\n\n return source.replace(marker, \"\");\n}\n\n/**\n * The page's own styles: it defines every devtools panel token (light, then dark under\n * `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.\n * The values keep text AA on `--background` and `--card`.\n */\nexport const PAGE_STYLE = `\n:root{color-scheme:light dark;--background:#f7f8fa;--foreground:#161b22;--card:#fff;--card-foreground:#161b22;--popover:#fff;--popover-foreground:#161b22;--primary:#1f2937;--primary-foreground:#fff;--secondary:#eceff3;--secondary-foreground:#1f2937;--muted:#eceff3;--muted-foreground:#4b5565;--accent:#e4e9f2;--accent-foreground:#161b22;--destructive:#b42318;--border:#d5dae3;--input:#c3cad6;--ring:#2f5fd0;--radius:10px;--brand:#2757c4;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#2757c4;--chart-2:#13693b;--chart-3:#8a5300;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--background:#14171c;--foreground:#eceff4;--card:#1c2027;--card-foreground:#eceff4;--popover:#1c2027;--popover-foreground:#eceff4;--primary:#eceff4;--primary-foreground:#14171c;--secondary:#272c35;--secondary-foreground:#eceff4;--muted:#272c35;--muted-foreground:#a9b2c1;--accent:#2d3440;--accent-foreground:#eceff4;--destructive:#ff8f86;--border:#343b47;--input:#3f4756;--ring:#8fb0ff;--radius:10px;--brand:#86adff;--brand-foreground:#0d1320;--success:#5fd391;--warning:#f3b25a;--info:#6cc0f5;--chart-1:#86adff;--chart-2:#5fd391;--chart-3:#f3b25a;--chart-4:#b79cff;--chart-5:#ff8fbd}}\n*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}\nmain{max-width:1180px;margin:0 auto;padding:16px}\n.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}\n`;\n\n/** The `index.html` text. */\nexport function renderSiteHtml(\n siteData: unknown,\n sources: { view: string; loader: string; css: string },\n): string {\n const json = inlineJson(siteData);\n const script = inlineCode(\n `${inlineView(sources.view)}\\n${sources.loader}\\ngrimoireStaticMount(JSON.parse(document.getElementById(\"grimoire-data\").textContent), document.getElementById(\"grimoire-root\"), renderGrimoire);\\n`,\n );\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Grimoire</title>\n<style>${PAGE_STYLE}${sources.css}</style>\n</head>\n<body>\n<main id=\"grimoire-root\"><p class=\"empty\">Opening the book…</p></main>\n<script type=\"application/json\" id=\"grimoire-data\">${json}</script>\n<script type=\"module\">${script}</script>\n</body>\n</html>\n`;\n}\n\n/**\n * Write the tab as a static folder for people without the app running.\n *\n * The folder holds `index.html` only: the view, the loader, the styles and\n * the data (as JSON) are inside it, so it opens straight from disk. Open the\n * page and use `#grimoire/...` links; the answers that need the running app\n * (impact of a file) say so in place.\n *\n * @param root Absolute project root.\n * @returns The output folder, project-relative.\n */\nexport async function exportGrimoireSite(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<string> {\n // Project-relative from here on; an absolute folder is kept where it is.\n const outDir = projectPath(\n root,\n toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite),\n ).replace(/\\/+$/, \"\");\n const snapshot =\n options.snapshot ??\n (await createSnapshotSource(\n root,\n options.adapter === undefined ? {} : { adapter: options.adapter },\n ).get());\n const [view, loader, css] = await Promise.all(\n [\"grimoire-view.js\", \"grimoire-static.js\", \"grimoire.css\"].map((name) =>\n readFile(path.join(uiFolder, name), \"utf8\"),\n ),\n );\n const html = renderSiteHtml(buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n });\n const absolute = path.resolve(root, outDir);\n\n await mkdir(absolute, { recursive: true });\n await writeFile(path.join(absolute, \"index.html\"), html);\n\n return outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB;AAI/B,MAAM,WAAW,cAAc,IAAI,IAAI,aAAa,YAAY,GAAG,CAAC;;AAGpE,SAAgB,cAAc,UAA4B;CACxD,MAAM,SAAkC;EACtC,SAASA,QAAa,QAAQ;EAC9B,UAAUC,SAAc,QAAQ;EAChC,MAAMC,KAAU,QAAQ;EACxB,OAAOC,MAAW,QAAQ;EAC1B,UAAUC,SAAc,QAAQ;EAEhC,OAAO;GAAE,GAAGC,MAAW,QAAQ;GAAG,MAAM;EAAI;EAC5C,iBAAiBC,eAAoB,QAAQ;CAC/C;CACA,MAAM,SAAuB,CAAC;CAE9B,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,OAAO,YAAY,QAAQ,QAAQ,WAAW;CAGhD,KAAK,MAAMC,aAAW,SAAS,QAAQ,UAAU;EAC/C,MAAM,SAASA,UAAQ;EAEvB,OAAO,KAAK;GAAE,MAAM;GAAW,IAAIA,UAAQ;GAAI,QAAQ,QAAQ,MAAM,SAAS;EAAK,CAAC;EACpF,MAAM,WAAW,cAAcC,QAAa,UAAUD,UAAQ,EAAE,CAAC;EAEjE,IAAI,aAAa,QAAW,OAAO,YAAYA,UAAQ,QAAQ;EAE/D,MAAM,QAAQ,aAAa,UAAUA,UAAQ,EAAE;EAE/C,IAAI,UAAU,MAAM,OAAO,iBAAiBA,UAAQ,QAAQ;EAE5D,KAAK,MAAME,UAAQF,UAAQ,OAAO;GAChC,OAAO,KAAK;IAAE,MAAM;IAAQ,IAAIE,OAAK;IAAK,QAAQA,OAAK,SAAS,SAAS;GAAK,CAAC;GAC/E,MAAM,aAAa,cAAcC,KAAU,UAAU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MA,aAAa,QAAQ,IAAI;;;;qDAImB,KAAK;wBAClC,OAAO;;;;AAI/B;;;;;;;;;;;;AAaA,eAAsB,mBACpB,MACA,UAAqC,CAAC,GACrB;CAEjB,MAAM,SAAS,YACb,MACA,YAAY,QAAQ,UAAU,eAAe,UAAU,CACzD,CAAC,CAAC,QAAQ,QAAQ,EAAE;CACpB,MAAM,WACJ,QAAQ,YACP,MAAM,qBACL,MACA,QAAQ,YAAY,SAAY,CAAC,IAAI,EAAE,SAAS,QAAQ,QAAQ,CAClE,CAAC,CAAC,IAAI;CACR,MAAM,CAAC,MAAM,QAAQ,OAAO,MAAM,QAAQ,IACxC;EAAC;EAAoB;EAAsB;CAAc,CAAC,CAAC,KAAK,SAC9D,SAAS,KAAK,KAAK,UAAU,IAAI,GAAG,MAAM,CAC5C,CACF;CACA,MAAM,OAAO,eAAe,cAAc,QAAQ,GAAG;EACnD,MAAM,QAAQ;EACd,QAAQ,UAAU;EAClB,KAAK,OAAO;CACd,CAAC;CACD,MAAM,WAAW,KAAK,QAAQ,MAAM,MAAM;CAE1C,MAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;CACzC,MAAM,UAAU,KAAK,KAAK,UAAU,YAAY,GAAG,IAAI;CAEvD,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"site.mjs","names":["data.summary","data.features","data.apps","data.tasks","data.releases","data.check","data.graphOfModules","data.checkGroups","feature","data.feature","flowAnswer","data.flowAnswer","page","data.page","file","data.file"],"sources":["../../../../../../../../packages/grimoire/src/devtools/site.ts"],"sourcesContent":["/**\n * The static export: one folder with an `index.html` that holds the view, the\n * loader, the styles and the data as JSON. It opens from disk (`file://`) or\n * any static host and needs no running app.\n */\nimport { copyFile, mkdir, readFile, realpath, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS, projectPath, toPosixPath } from \"../paths\";\nimport * as data from \"./data\";\nimport { featureGraph, fileGraph, pageGraph } from \"./graphs\";\nimport { productFeature, productFlow, productMap } from \"./product-map\";\nimport { createSnapshotSource } from \"./snapshot-source\";\n\n/** Options of `exportGrimoireSite()`. */\nexport type ExportGrimoireSiteOptions = {\n /** Output folder, project-relative or absolute. Default `grimoire/book/site` (the book writer leaves it alone and git ignores it). */\n outDir?: string;\n /** The adapter to open the book with. Default: the Warlock adapter. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /** An already opened snapshot; skips opening one. */\n snapshot?: GrimoireSnapshot;\n};\n\n/** The most files the export keeps per-file answers for (the most imported first). */\nexport const SITE_FILE_LIMIT = 3000;\n\ntype SearchItem = { type: string; id: string; detail: string | null };\n\nconst uiFolder = fileURLToPath(new URL(\"../../ui/\", import.meta.url));\n\n/** Every answer the static page can give, keyed by the data route it replaces. */\nexport function buildSiteData(snapshot: GrimoireSnapshot) {\n const routes: Record<string, unknown> = {\n summary: data.summary(snapshot),\n features: data.features(snapshot),\n apps: data.apps(snapshot),\n tasks: data.tasks(snapshot),\n releases: data.releases(snapshot),\n // The page is meant to be shared: it does not name where the project sits on this machine.\n check: { ...data.check(snapshot), root: \".\" },\n \"graph/modules\": data.graphOfModules(snapshot),\n };\n // The static page is the signed-in view: developer detail stays, and no monitor reports errors.\n const productOptions = { shared: false, errors: null } as const;\n const productAnswer = attempt(() => productMap(snapshot, productOptions));\n const groups = attempt(() => data.checkGroups(snapshot));\n\n if (productAnswer !== undefined) routes.product = productAnswer;\n\n if (groups !== undefined) routes[\"check/groups\"] = groups;\n\n const search: SearchItem[] = [];\n\n for (const release of snapshot.written.releases) {\n routes[`releases/${release.release.value}`] = release;\n }\n\n for (const feature of snapshot.written.features) {\n const readme = feature.readme;\n\n search.push({ type: \"feature\", id: feature.id, detail: readme?.title.value ?? null });\n const answered = attempt(() => data.feature(snapshot, feature.id));\n\n if (answered !== undefined) routes[`features/${feature.id}`] = answered;\n\n const graph = featureGraph(snapshot, feature.id);\n\n if (graph !== null) routes[`graph/feature/${feature.id}`] = graph;\n\n const product = attempt(() => productFeature(snapshot, feature.id, productOptions));\n\n if (product !== undefined) routes[`product/features/${feature.id}`] = product;\n\n for (const flow of feature.flows) {\n search.push({ type: \"flow\", id: flow.ref, detail: flow.heading?.value ?? null });\n const flowAnswer = attempt(() => data.flowAnswer(snapshot, feature.id, flow.id.value));\n const productFlowAnswer = attempt(() =>\n productFlow(snapshot, feature.id, flow.id.value, productOptions),\n );\n\n if (flowAnswer !== undefined) routes[`flows/${flow.ref}`] = flowAnswer;\n\n if (productFlowAnswer !== undefined) routes[`product/flows/${flow.ref}`] = productFlowAnswer;\n }\n }\n\n for (const app of snapshot.written.apps) {\n const appId = app.id.value;\n\n for (const page of [...app.pages, ...app.screens]) {\n const route = page.route?.value ?? page.screen?.value ?? null;\n const answer = attempt(() => data.page(snapshot, appId, page.id));\n const graph = pageGraph(snapshot, appId, page.id);\n\n for (const key of new Set([page.id, ...(route === null ? [] : [route])])) {\n if (answer !== undefined) routes[`apps/${appId}/pages/${key}`] = answer;\n\n if (graph !== null) routes[`graph/page/${appId}/${key}`] = graph;\n }\n\n if (route !== null)\n search.push({\n type: page.type,\n id: `${appId} ${route}`,\n detail: page.heading?.value ?? null,\n });\n\n for (const block of page.blockFiles) {\n search.push({\n type: \"block\",\n id: `${appId}/${page.id}/${block.id}`,\n detail: block.flow?.value ?? null,\n });\n }\n }\n }\n\n for (const found of snapshot.book.facts.routes ?? []) {\n search.push({\n type: \"route\",\n id: `${found.method} ${found.path}`,\n detail: found.description ?? found.handler,\n });\n }\n\n for (const task of snapshot.collected.tasksIndex.open.concat(\n snapshot.collected.tasksIndex.done,\n )) {\n search.push({ type: \"task\", id: task.id, detail: task.title });\n }\n\n const files: Record<string, { result: unknown; graph: unknown }> = {};\n const ranked = [...snapshot.book.facts.files].sort(\n (left, right) =>\n right.importedBy.length - left.importedBy.length || left.file.localeCompare(right.file),\n );\n\n for (const [index, file] of ranked.entries()) {\n search.push({ type: \"file\", id: file.file, detail: file.about });\n\n if (index >= SITE_FILE_LIMIT) continue;\n\n const result = attempt(() => data.file(snapshot, file.file));\n\n if (result !== undefined) files[file.file] = { result, graph: fileGraph(snapshot, file.file) };\n }\n\n return { routes, files, search };\n}\n\n/** JSON for an inline `<script>`: every `<` is escaped, so no `</script` or `<!--` can appear. */\nfunction inlineJson(value: unknown): string {\n return JSON.stringify(value).replaceAll(\"<\", \"\\\\u003c\");\n}\n\n/** Code for an inline `<script>`: `</script` (in any case) and `<!--` (only possible in strings and comments) are broken up. */\nfunction inlineCode(code: string): string {\n return code.replace(/<\\/(script)/gi, \"<\\\\/$1\").replaceAll(\"<!--\", \"<\\\\!--\");\n}\n\n/** The image types the export copies (the same list the devtools panel serves). */\nconst SCREENSHOT_EXTENSIONS = new Set([\".png\", \".jpg\", \".jpeg\", \".webp\", \".gif\"]);\n\n/** Every `WrittenScreenshot.path` in the written files, once each. */\nexport function collectScreenshotPaths(written: unknown): string[] {\n const found = new Set<string>();\n const walk = (value: unknown): void => {\n if (Array.isArray(value)) {\n for (const item of value) walk(item);\n } else if (value !== null && typeof value === \"object\") {\n const record = value as Record<string, unknown>;\n\n if (\n typeof record.path === \"string\" &&\n typeof record.written === \"string\" &&\n typeof record.alt === \"string\"\n )\n found.add(record.path);\n\n for (const item of Object.values(record)) walk(item);\n }\n };\n\n walk(written);\n\n return [...found].sort();\n}\n\n/**\n * Copy the screenshots the written files use into `<out>/screenshots/`. A path that leaves\n * `grimoire/screenshots/`, has another extension or does not exist is skipped.\n *\n * @returns The paths that were copied.\n */\nexport async function copyScreenshots(\n root: string,\n outFolder: string,\n paths: readonly string[],\n): Promise<string[]> {\n const folder = await realpath(path.join(root, GRIMOIRE_PATHS.screenshots)).catch(() => null);\n const copied: string[] = [];\n\n if (folder === null) return copied;\n\n for (const written of paths) {\n const segments = written.split(\"/\");\n\n if (\n written === \"\" ||\n written.includes(\"\\\\\") ||\n written.includes(\"\\0\") ||\n path.isAbsolute(written) ||\n segments.some((segment) => segment === \"\" || segment === \".\" || segment === \"..\") ||\n !SCREENSHOT_EXTENSIONS.has(path.extname(written).toLowerCase())\n )\n continue;\n\n const source = await realpath(path.join(folder, ...segments)).catch(() => null);\n\n if (source === null || !source.startsWith(folder + path.sep)) continue;\n\n if (!(await stat(source)).isFile()) continue;\n\n const target = path.join(outFolder, \"screenshots\", ...segments);\n\n await mkdir(path.dirname(target), { recursive: true });\n await copyFile(source, target);\n copied.push(written);\n }\n\n return copied;\n}\n\n/** The answer, or `undefined` when the item cannot be answered (the export skips it). */\nfunction attempt<Value>(answer: () => Value): Value | undefined {\n try {\n return answer();\n } catch {\n return undefined;\n }\n}\n\n/** Everything before the page's `export default`, so the view can sit in an inline module. */\nexport function inlineView(source: string): string {\n const marker = \"export default renderGrimoire;\";\n\n if (!source.includes(marker))\n throw new Error(\"grimoire-view.js must end with `export default renderGrimoire;`.\");\n\n return source.replace(marker, \"\");\n}\n\n/**\n * The product map module as inline code: its `export` keywords are removed and the Grimoire view\n * finds it as `globalThis.grimoireProductMap`.\n */\nexport function inlineProductMap(source: string): string {\n const marker = \"export default renderProductMap;\";\n\n if (!source.includes(marker))\n throw new Error(\"product-map.js must end with `export default renderProductMap;`.\");\n\n return `${source.replace(marker, \"\").replace(/^export (async )?function /gm, \"$1function \")}\\nglobalThis.grimoireProductMap = { productMapView };\\n`;\n}\n\n/**\n * The page's own styles: it defines every devtools panel token (light, then dark under\n * `prefers-color-scheme`), so `grimoire.css` renders the same here as in the dashboard.\n * The values keep text AA on `--background` and `--card`.\n */\nexport const PAGE_STYLE = `\n:root{color-scheme:light dark;--background:#f7f8fa;--foreground:#161b22;--card:#fff;--card-foreground:#161b22;--popover:#fff;--popover-foreground:#161b22;--primary:#1f2937;--primary-foreground:#fff;--secondary:#eceff3;--secondary-foreground:#1f2937;--muted:#eceff3;--muted-foreground:#4b5565;--accent:#e4e9f2;--accent-foreground:#161b22;--destructive:#b42318;--border:#d5dae3;--input:#c3cad6;--ring:#2f5fd0;--radius:10px;--brand:#2757c4;--brand-foreground:#fff;--success:#13693b;--warning:#8a5300;--info:#0b66a3;--chart-1:#2757c4;--chart-2:#13693b;--chart-3:#8a5300;--chart-4:#6d3ac7;--chart-5:#b4306b;font-family:system-ui,-apple-system,\"Segoe UI\",sans-serif}\n@media (prefers-color-scheme:dark){:root{--background:#14171c;--foreground:#eceff4;--card:#1c2027;--card-foreground:#eceff4;--popover:#1c2027;--popover-foreground:#eceff4;--primary:#eceff4;--primary-foreground:#14171c;--secondary:#272c35;--secondary-foreground:#eceff4;--muted:#272c35;--muted-foreground:#a9b2c1;--accent:#2d3440;--accent-foreground:#eceff4;--destructive:#ff8f86;--border:#343b47;--input:#3f4756;--ring:#8fb0ff;--radius:10px;--brand:#86adff;--brand-foreground:#0d1320;--success:#5fd391;--warning:#f3b25a;--info:#6cc0f5;--chart-1:#86adff;--chart-2:#5fd391;--chart-3:#f3b25a;--chart-4:#b79cff;--chart-5:#ff8fbd}}\n*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font-size:14px;line-height:1.5}\nmain{max-width:1180px;margin:0 auto;padding:16px}\n.empty{padding:12px;color:var(--muted-foreground)}.error{padding:12px;color:var(--destructive)}\n`;\n\n/** The `index.html` text. */\nexport function renderSiteHtml(\n siteData: unknown,\n sources: { view: string; loader: string; css: string; productMap?: string; productCss?: string },\n): string {\n const json = inlineJson(siteData);\n const script = inlineCode(\n `${sources.productMap === undefined ? \"\" : inlineProductMap(sources.productMap)}${inlineView(sources.view)}\\n${sources.loader}\\ngrimoireStaticMount(JSON.parse(document.getElementById(\"grimoire-data\").textContent), document.getElementById(\"grimoire-root\"), renderGrimoire);\\n`,\n );\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Grimoire</title>\n<style>${PAGE_STYLE}${sources.css}${sources.productCss ?? \"\"}</style>\n</head>\n<body>\n<main id=\"grimoire-root\"><p class=\"empty\">Opening the book…</p></main>\n<script type=\"application/json\" id=\"grimoire-data\">${json}</script>\n<script type=\"module\">${script}</script>\n</body>\n</html>\n`;\n}\n\n/**\n * Write the tab as a static folder for people without the app running.\n *\n * The folder holds `index.html` only: the view, the loader, the styles and\n * the data (as JSON) are inside it, so it opens straight from disk. Open the\n * page and use `#grimoire/...` links; the answers that need the running app\n * (impact of a file) say so in place.\n *\n * @param root Absolute project root.\n * @returns The output folder, project-relative.\n */\nexport async function exportGrimoireSite(\n root: string,\n options: ExportGrimoireSiteOptions = {},\n): Promise<string> {\n // Project-relative from here on; an absolute folder is kept where it is.\n const outDir = projectPath(\n root,\n toPosixPath(options.outDir ?? GRIMOIRE_PATHS.staticSite),\n ).replace(/\\/+$/, \"\");\n const snapshot =\n options.snapshot ??\n (await createSnapshotSource(\n root,\n options.adapter === undefined ? {} : { adapter: options.adapter },\n ).get());\n const [view, loader, css, productMapSource, productCss] = await Promise.all(\n [\n \"grimoire-view.js\",\n \"grimoire-static.js\",\n \"grimoire.css\",\n \"product-map.js\",\n \"product-map.css\",\n ].map((name) => readFile(path.join(uiFolder, name), \"utf8\")),\n );\n const html = renderSiteHtml(buildSiteData(snapshot), {\n view: view ?? \"\",\n loader: loader ?? \"\",\n css: css ?? \"\",\n productMap: productMapSource ?? \"\",\n productCss: productCss ?? \"\",\n });\n const absolute = path.resolve(root, outDir);\n\n await mkdir(absolute, { recursive: true });\n await writeFile(path.join(absolute, \"index.html\"), html);\n await copyScreenshots(root, absolute, collectScreenshotPaths(snapshot.written));\n\n return outDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,MAAa,kBAAkB;AAI/B,MAAM,WAAW,cAAc,IAAI,IAAI,aAAa,YAAY,GAAG,CAAC;;AAGpE,SAAgB,cAAc,UAA4B;CACxD,MAAM,SAAkC;EACtC,SAASA,QAAa,QAAQ;EAC9B,UAAUC,SAAc,QAAQ;EAChC,M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O;EACZ,YAAY,oBAAoB;EAChC,YAAY,cAAc;CAC5B,CAAC;CACD,MAAM,WAAW,KAAK,QAAQ,MAAM,MAAM;CAE1C,MAAM,MAAM,UAAU,EAAE,WAAW,KAAK,CAAC;CACzC,MAAM,UAAU,KAAK,KAAK,UAAU,YAAY,GAAG,IAAI;CACvD,MAAM,gBAAgB,MAAM,UAAU,uBAAuB,SAAS,OAAO,CAAC;CAE9E,OAAO;AACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRIMOIRE_PATHS } from "../paths/index.mjs";
|
|
2
|
+
import { resolveResultsFile } from "../test-results/index.mjs";
|
|
2
3
|
import { openGrimoire } from "../workspace/index.mjs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { stat } from "node:fs/promises";
|
|
@@ -40,10 +41,11 @@ const STAMPED = [
|
|
|
40
41
|
GRIMOIRE_PATHS.doneTasks,
|
|
41
42
|
GRIMOIRE_PATHS.releases
|
|
42
43
|
];
|
|
43
|
-
async function changeStamp(root) {
|
|
44
|
-
|
|
44
|
+
async function changeStamp(root, resultsFile) {
|
|
45
|
+
const files = [...STAMPED.map((entry) => path.join(root, ...entry.split("/"))), resultsFile];
|
|
46
|
+
return (await Promise.all(files.map(async (file) => {
|
|
45
47
|
try {
|
|
46
|
-
return (await stat(
|
|
48
|
+
return (await stat(file)).mtimeMs;
|
|
47
49
|
} catch {
|
|
48
50
|
return 0;
|
|
49
51
|
}
|
|
@@ -60,6 +62,7 @@ async function loadAdapter(option) {
|
|
|
60
62
|
function createSnapshotSource(root, options = {}) {
|
|
61
63
|
let cached = null;
|
|
62
64
|
let opening = null;
|
|
65
|
+
const resultsFile = resolveResultsFile(root, options.testResultsFile);
|
|
63
66
|
const keepUntilChanged = options.mode === "production" && options.ttlMs === void 0;
|
|
64
67
|
const reuseFor = (took) => options.ttlMs ?? Math.max(2e3, took * 5);
|
|
65
68
|
async function open() {
|
|
@@ -67,13 +70,14 @@ function createSnapshotSource(root, options = {}) {
|
|
|
67
70
|
const adapter = await loadAdapter(options.adapter);
|
|
68
71
|
const snapshot = await openGrimoire(root, adapter, {
|
|
69
72
|
routes: "cached",
|
|
70
|
-
write: options.write ?? false
|
|
73
|
+
write: options.write ?? false,
|
|
74
|
+
...options.testResultsFile === void 0 ? {} : { testResultsFile: options.testResultsFile }
|
|
71
75
|
});
|
|
72
76
|
const at = Date.now();
|
|
73
77
|
cached = {
|
|
74
78
|
snapshot,
|
|
75
79
|
at,
|
|
76
|
-
stamp: await changeStamp(root),
|
|
80
|
+
stamp: await changeStamp(root, resultsFile),
|
|
77
81
|
took: at - started
|
|
78
82
|
};
|
|
79
83
|
return snapshot;
|
|
@@ -89,7 +93,7 @@ function createSnapshotSource(root, options = {}) {
|
|
|
89
93
|
async get() {
|
|
90
94
|
if (cached === null) return ensureOpening();
|
|
91
95
|
const known = cached;
|
|
92
|
-
const changed = await changeStamp(root) !== known.stamp;
|
|
96
|
+
const changed = await changeStamp(root, resultsFile) !== known.stamp;
|
|
93
97
|
if (changed || options.mode === "production") {
|
|
94
98
|
if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) return known.snapshot;
|
|
95
99
|
return ensureOpening().catch(() => known.snapshot);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-source.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/snapshot-source.ts"],"sourcesContent":["/**\n * Where the panel's routes get the snapshot: opened once with\n * `routes: \"cached\"` (a devtools request never boots the app) and kept in\n * memory. Concurrent requests share one open. A change stamp (the book\n * manifest plus the agent-written folders and indexes, a few `stat` calls and\n * no directory walk) tells when the book changed.\n *\n * - Production (`mode: \"production\"`): a snapshot is reused until the stamp\n * changes, with no time limit, unless `ttlMs` is set. A request that finds\n * the stamp changed waits for the new open. `warm()` opens the book ahead\n * of the first request.\n * - Development: the snapshot is reused for a short window (2 s, or five times\n * the last open when that is longer, so a slow open on a large app is not\n * repeated on every view; written files change while an agent works). A\n * request that finds the stamp changed waits for the new open. After the\n * window, with the stamp unchanged (a file edited in place), the cached\n * snapshot is served at once and one background open refreshes it (stale\n * while revalidate).\n *\n * An open that fails keeps serving the old snapshot; its error surfaces on a\n * request only when there is no snapshot at all. The panel passes\n * `write: true` in development, so the generated book stays current and the\n * next open is incremental; with `write: false` a stored book behind the\n * sources is rebuilt in memory on every open.\n */\nimport { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { openGrimoire } from \"../workspace\";\n\n/** Options of the panel's snapshot source. */\nexport type SnapshotSourceOptions = {\n /** The adapter, or a function that loads it. Default: the Warlock adapter, imported on first use. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long a snapshot is reused when the book did not change (ms).\n * Default in development: 2000, or five times as long as the last open took\n * when that is longer. Default in production: no limit (reused until the\n * book changes).\n */\n ttlMs?: number;\n /** Where the source runs. `\"production\"` keeps a snapshot until the book changes. Default: `\"development\"`. */\n mode?: \"development\" | \"production\";\n /** Let `openGrimoire` write the generated book and collected files (never agent-written files). Default `false`; the devtools panel passes `true`. */\n write?: boolean;\n};\n\n/** A cached, shared snapshot of one project. */\nexport type SnapshotSource = {\n get(): Promise<GrimoireSnapshot>;\n /** Forget the cached snapshot; the next `get()` opens again. */\n invalidate(): void;\n /** Start opening the book now, so the first `get()` is fast. Failures are ignored here and surface on `get()`. */\n warm(): void;\n /** Resolves when no open is running (specs and shutdown). Never rejects. */\n idle(): Promise<void>;\n};\n\n/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */\nconst STAMPED = [\n GRIMOIRE_PATHS.bookManifest,\n GRIMOIRE_PATHS.featuresIndex,\n GRIMOIRE_PATHS.tasksIndex,\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.openTasks,\n GRIMOIRE_PATHS.doneTasks,\n GRIMOIRE_PATHS.releases,\n];\n\nasync function changeStamp(root: string): Promise<string> {\n const times = await Promise.all(\n
|
|
1
|
+
{"version":3,"file":"snapshot-source.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/devtools/snapshot-source.ts"],"sourcesContent":["/**\n * Where the panel's routes get the snapshot: opened once with\n * `routes: \"cached\"` (a devtools request never boots the app) and kept in\n * memory. Concurrent requests share one open. A change stamp (the book\n * manifest plus the agent-written folders and indexes, a few `stat` calls and\n * no directory walk) tells when the book changed.\n *\n * - Production (`mode: \"production\"`): a snapshot is reused until the stamp\n * changes, with no time limit, unless `ttlMs` is set. A request that finds\n * the stamp changed waits for the new open. `warm()` opens the book ahead\n * of the first request.\n * - Development: the snapshot is reused for a short window (2 s, or five times\n * the last open when that is longer, so a slow open on a large app is not\n * repeated on every view; written files change while an agent works). A\n * request that finds the stamp changed waits for the new open. After the\n * window, with the stamp unchanged (a file edited in place), the cached\n * snapshot is served at once and one background open refreshes it (stale\n * while revalidate).\n *\n * An open that fails keeps serving the old snapshot; its error surfaces on a\n * request only when there is no snapshot at all. The panel passes\n * `write: true` in development, so the generated book stays current and the\n * next open is incremental; with `write: false` a stored book behind the\n * sources is rebuilt in memory on every open.\n */\nimport { stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { BookAdapter } from \"../contracts/adapter\";\nimport type { GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { GRIMOIRE_PATHS } from \"../paths\";\nimport { resolveResultsFile } from \"../test-results\";\nimport { openGrimoire } from \"../workspace\";\n\n/** Options of the panel's snapshot source. */\nexport type SnapshotSourceOptions = {\n /** The adapter, or a function that loads it. Default: the Warlock adapter, imported on first use. */\n adapter?: BookAdapter | (() => Promise<BookAdapter>);\n /**\n * How long a snapshot is reused when the book did not change (ms).\n * Default in development: 2000, or five times as long as the last open took\n * when that is longer. Default in production: no limit (reused until the\n * book changes).\n */\n ttlMs?: number;\n /** Where the source runs. `\"production\"` keeps a snapshot until the book changes. Default: `\"development\"`. */\n mode?: \"development\" | \"production\";\n /** Let `openGrimoire` write the generated book and collected files (never agent-written files). Default `false`; the devtools panel passes `true`. */\n write?: boolean;\n /**\n * Where the test results are read from (project-relative or absolute).\n * Default `grimoire/book/test-results.json`. The file's modified time is part\n * of the change stamp, so results written after the snapshot opened show up\n * without a restart.\n */\n testResultsFile?: string;\n};\n\n/** A cached, shared snapshot of one project. */\nexport type SnapshotSource = {\n get(): Promise<GrimoireSnapshot>;\n /** Forget the cached snapshot; the next `get()` opens again. */\n invalidate(): void;\n /** Start opening the book now, so the first `get()` is fast. Failures are ignored here and surface on `get()`. */\n warm(): void;\n /** Resolves when no open is running (specs and shutdown). Never rejects. */\n idle(): Promise<void>;\n};\n\n/** Files and folders whose modified time moves when the book or an agent-written file is added, removed or regenerated. */\nconst STAMPED = [\n GRIMOIRE_PATHS.bookManifest,\n GRIMOIRE_PATHS.featuresIndex,\n GRIMOIRE_PATHS.tasksIndex,\n GRIMOIRE_PATHS.features,\n GRIMOIRE_PATHS.apps,\n GRIMOIRE_PATHS.openTasks,\n GRIMOIRE_PATHS.doneTasks,\n GRIMOIRE_PATHS.releases,\n];\n\nasync function changeStamp(root: string, resultsFile: string): Promise<string> {\n const files = [...STAMPED.map((entry) => path.join(root, ...entry.split(\"/\"))), resultsFile];\n const times = await Promise.all(\n files.map(async (file) => {\n try {\n return (await stat(file)).mtimeMs;\n } catch {\n return 0;\n }\n }),\n );\n\n return times.join(\",\");\n}\n\nasync function loadAdapter(option: SnapshotSourceOptions[\"adapter\"]): Promise<BookAdapter> {\n if (option === undefined) {\n const { createWarlockAdapter } = await import(\"../warlock\");\n\n return createWarlockAdapter();\n }\n\n return typeof option === \"function\" ? option() : option;\n}\n\n/** Create the source for the project at `root`. */\nexport function createSnapshotSource(\n root: string,\n options: SnapshotSourceOptions = {},\n): SnapshotSource {\n let cached: { snapshot: GrimoireSnapshot; at: number; stamp: string; took: number } | null = null;\n let opening: Promise<GrimoireSnapshot> | null = null;\n\n const resultsFile = resolveResultsFile(root, options.testResultsFile);\n\n const keepUntilChanged = options.mode === \"production\" && options.ttlMs === undefined;\n const reuseFor = (took: number): number => options.ttlMs ?? Math.max(2000, took * 5);\n\n async function open(): Promise<GrimoireSnapshot> {\n const started = Date.now();\n const adapter = await loadAdapter(options.adapter);\n const snapshot = await openGrimoire(root, adapter, {\n routes: \"cached\",\n write: options.write ?? false,\n ...(options.testResultsFile === undefined ? {} : { testResultsFile: options.testResultsFile }),\n });\n\n const at = Date.now();\n\n cached = { snapshot, at, stamp: await changeStamp(root, resultsFile), took: at - started };\n\n return snapshot;\n }\n\n /** The open in flight, or a new one; concurrent callers share it. */\n function ensureOpening(): Promise<GrimoireSnapshot> {\n opening ??= open().finally(() => {\n opening = null;\n });\n\n return opening;\n }\n\n return {\n async get() {\n if (cached === null) return ensureOpening();\n\n const known = cached;\n const changed = (await changeStamp(root, resultsFile)) !== known.stamp;\n\n if (changed || options.mode === \"production\") {\n if (!changed && (keepUntilChanged || Date.now() - known.at < reuseFor(known.took))) {\n return known.snapshot;\n }\n\n // A failed open keeps the old snapshot; the next request tries again.\n return ensureOpening().catch(() => known.snapshot);\n }\n\n if (Date.now() - known.at < reuseFor(known.took)) return known.snapshot;\n\n // Development, nothing known to have changed: serve the old snapshot now and refresh behind it.\n ensureOpening().catch(() => {});\n\n return known.snapshot;\n },\n invalidate() {\n cached = null;\n },\n warm() {\n if (cached === null) ensureOpening().catch(() => {});\n },\n async idle() {\n await opening?.catch(() => {});\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,MAAM,UAAU;CACd,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AAEA,eAAe,YAAY,MAAc,aAAsC;CAC7E,MAAM,QAAQ,CAAC,GAAG,QAAQ,KAAK,UAAU,KAAK,KAAK,MAAM,GAAG,MAAM,MAAM,GAA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,MAAM,YAAY,MAAM,WAAW,MAAO,MAAM;GAEjE,IAAI,WAAW,QAAQ,SAAS,cAAc;IAC5C,IAAI,CAAC,YAAY,oBAAoB,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,IAC9E,OAAO,MAAM;IAIf,OAAO,cAAc,CAAC,CAAC,YAAY,MAAM,QAAQ;GACnD;GAEA,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,MAAM,IAAI,GAAG,OAAO,MAAM;GAG/D,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;GAE9B,OAAO,MAAM;EACf;EACA,aAAa;GACX,SAAS;EACX;EACA,OAAO;GACL,IAAI,WAAW,MAAM,cAAc,CAAC,CAAC,YAAY,CAAC,CAAC;EACrD;EACA,MAAM,OAAO;GACX,MAAM,SAAS,YAAY,CAAC,CAAC;EAC/B;CACF;AACF"}
|
package/esm/graph/index.d.mts
CHANGED
|
@@ -4,11 +4,20 @@ import { BookFile } from "../contracts/adapter.mjs";
|
|
|
4
4
|
export type FileGraph = ReadonlyMap<string, Pick<BookFile, "file" | "imports" | "importedBy">>;
|
|
5
5
|
/** Index files by path. */
|
|
6
6
|
export declare function fileGraph(files: readonly Pick<BookFile, "file" | "imports" | "importedBy">[]): FileGraph;
|
|
7
|
+
/** Options of {@link importClosure}. */
|
|
8
|
+
export type ImportClosureOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Leave out import edges marked `typeOnly` (erased at runtime), so a page
|
|
11
|
+
* that imports a type through a barrel does not reach the barrel's server
|
|
12
|
+
* files. Default `false`: every edge is followed.
|
|
13
|
+
*/
|
|
14
|
+
skipTypeOnly?: boolean;
|
|
15
|
+
};
|
|
7
16
|
/**
|
|
8
17
|
* The start files and every project file they import, transitively, sorted.
|
|
9
18
|
* Files not in the graph are left out. Cycles are walked once.
|
|
10
19
|
*/
|
|
11
|
-
export declare function importClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
20
|
+
export declare function importClosure(graph: FileGraph, start: readonly string[], options?: ImportClosureOptions): string[];
|
|
12
21
|
/** The start files and every project file that imports them, transitively, sorted. */
|
|
13
22
|
export declare function importerClosure(graph: FileGraph, start: readonly string[]): string[];
|
|
14
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"mappings":";;;YAQY,YAAY,oBAAoB,KAAK;;wBAGjC,UACd,gBAAgB,KAAK,iDACpB
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"mappings":";;;YAQY,YAAY,oBAAoB,KAAK;;wBAGjC,UACd,gBAAgB,KAAK,iDACpB;;YAyBS;;;;;;EAMV;;;;;;wBAOc,cACd,OAAO,WACP,0BACA,UAAS;;wBAYK,gBAAgB,OAAO,WAAW"}
|
package/esm/graph/index.mjs
CHANGED
|
@@ -18,8 +18,9 @@ function walk(graph, start, next) {
|
|
|
18
18
|
* The start files and every project file they import, transitively, sorted.
|
|
19
19
|
* Files not in the graph are left out. Cycles are walked once.
|
|
20
20
|
*/
|
|
21
|
-
function importClosure(graph, start) {
|
|
22
|
-
|
|
21
|
+
function importClosure(graph, start, options = {}) {
|
|
22
|
+
const skipTypeOnly = options.skipTypeOnly === true;
|
|
23
|
+
return walk(graph, start, (file) => (graph.get(file)?.imports ?? []).flatMap((entry) => entry.file === null || skipTypeOnly && entry.typeOnly === true ? [] : [entry.file]));
|
|
23
24
|
}
|
|
24
25
|
/** The start files and every project file that imports them, transitively, sorted. */
|
|
25
26
|
function importerClosure(graph, start) {
|
package/esm/graph/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"sourcesContent":["/**\n * Walks over the import graph of the book's files. Shared by the book maps\n * (files behind a step), `scry --route` (files behind a handler) and\n * `scry --impact` (files that reach a file).\n */\nimport type { BookFile } from \"../contracts/adapter\";\n\n/** Files indexed by path, for the walks below. */\nexport type FileGraph = ReadonlyMap<string, Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">>;\n\n/** Index files by path. */\nexport function fileGraph(\n files: readonly Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">[],\n): FileGraph {\n return new Map(files.map((file) => [file.file, file]));\n}\n\nfunction walk(\n graph: FileGraph,\n start: readonly string[],\n next: (file: string) => string[],\n): string[] {\n const seen = new Set<string>();\n const pending = [...start];\n\n while (pending.length > 0) {\n const current = pending.pop();\n\n if (current === undefined || seen.has(current) || !graph.has(current)) continue;\n\n seen.add(current);\n pending.push(...next(current));\n }\n\n return [...seen].sort();\n}\n\n/**\n * The start files and every project file they import, transitively, sorted.\n * Files not in the graph are left out. Cycles are walked once.\n */\nexport function importClosure(graph: FileGraph
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/graph/index.ts"],"sourcesContent":["/**\n * Walks over the import graph of the book's files. Shared by the book maps\n * (files behind a step), `scry --route` (files behind a handler) and\n * `scry --impact` (files that reach a file).\n */\nimport type { BookFile } from \"../contracts/adapter\";\n\n/** Files indexed by path, for the walks below. */\nexport type FileGraph = ReadonlyMap<string, Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">>;\n\n/** Index files by path. */\nexport function fileGraph(\n files: readonly Pick<BookFile, \"file\" | \"imports\" | \"importedBy\">[],\n): FileGraph {\n return new Map(files.map((file) => [file.file, file]));\n}\n\nfunction walk(\n graph: FileGraph,\n start: readonly string[],\n next: (file: string) => string[],\n): string[] {\n const seen = new Set<string>();\n const pending = [...start];\n\n while (pending.length > 0) {\n const current = pending.pop();\n\n if (current === undefined || seen.has(current) || !graph.has(current)) continue;\n\n seen.add(current);\n pending.push(...next(current));\n }\n\n return [...seen].sort();\n}\n\n/** Options of {@link importClosure}. */\nexport type ImportClosureOptions = {\n /**\n * Leave out import edges marked `typeOnly` (erased at runtime), so a page\n * that imports a type through a barrel does not reach the barrel's server\n * files. Default `false`: every edge is followed.\n */\n skipTypeOnly?: boolean;\n};\n\n/**\n * The start files and every project file they import, transitively, sorted.\n * Files not in the graph are left out. Cycles are walked once.\n */\nexport function importClosure(\n graph: FileGraph,\n start: readonly string[],\n options: ImportClosureOptions = {},\n): string[] {\n const skipTypeOnly = options.skipTypeOnly === true;\n\n return walk(graph, start, (file) =>\n (graph.get(file)?.imports ?? []).flatMap((entry) =>\n entry.file === null || (skipTypeOnly && entry.typeOnly === true) ? [] : [entry.file],\n ),\n );\n}\n\n/** The start files and every project file that imports them, transitively, sorted. */\nexport function importerClosure(graph: FileGraph, start: readonly string[]): string[] {\n return walk(graph, start, (file) => [...(graph.get(file)?.importedBy ?? [])]);\n}\n\n/**\n * The package name of a bare import specifier (`@warlock.js/core/tooling` →\n * `@warlock.js/core`, `dayjs/plugin/utc` → `dayjs`), or `null` for a relative\n * path, a `node:` builtin or an alias that starts with a path character.\n */\nexport function packageNameOf(specifier: string): string | null {\n if (specifier.startsWith(\".\") || specifier.startsWith(\"/\") || specifier.startsWith(\"node:\")) {\n return null;\n }\n\n const parts = specifier.split(\"/\");\n\n if (specifier.startsWith(\"@\")) {\n return parts.length >= 2 && parts[1] ? `${parts[0]}/${parts[1]}` : null;\n }\n\n return parts[0] || null;\n}\n"],"mappings":";;AAWA,SAAgB,UACd,OACW;CACX,OAAO,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC;AACvD;AAEA,SAAS,KACP,OACA,OACA,MACU;CACV,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,UAAU,CAAC,GAAG,KAAK;CAEzB,OAAO,QAAQ,SAAS,GAAG;EACzB,MAAM,UAAU,QAAQ,IAAI;EAE5B,IAAI,YAAY,UAAa,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,IAAI,OAAO,GAAG;EAEvE,KAAK,IAAI,OAAO;EAChB,QAAQ,KAAK,GAAG,KAAK,OAAO,CAAC;CAC/B;CAEA,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK;AACxB;;;;;AAgBA,SAAgB,cACd,OACA,OACA,UAAgC,CAAC,GACvB;CACV,MAAM,eAAe,QAAQ,iBAAiB;CAE9C,OAAO,KAAK,OAAO,QAAQ,UACxB,MAAM,IAAI,IAAI,CAAC,EAAE,WAAW,CAAC,EAAC,CAAE,SAAS,UACxC,MAAM,SAAS,QAAS,gBAAgB,MAAM,aAAa,OAAQ,CAAC,IAAI,CAAC,MAAM,IAAI,CACrF,CACF;AACF;;AAGA,SAAgB,gBAAgB,OAAkB,OAAoC;CACpF,OAAO,KAAK,OAAO,QAAQ,SAAS,CAAC,GAAI,MAAM,IAAI,IAAI,CAAC,EAAE,cAAc,CAAC,CAAE,CAAC;AAC9E;;;;;;AAOA,SAAgB,cAAc,WAAkC;CAC9D,IAAI,UAAU,WAAW,GAAG,KAAK,UAAU,WAAW,GAAG,KAAK,UAAU,WAAW,OAAO,GACxF,OAAO;CAGT,MAAM,QAAQ,UAAU,MAAM,GAAG;CAEjC,IAAI,UAAU,WAAW,GAAG,GAC1B,OAAO,MAAM,UAAU,KAAK,MAAM,KAAK,GAAG,MAAM,GAAG,GAAG,MAAM,OAAO;CAGrE,OAAO,MAAM,MAAM;AACrB"}
|
package/esm/index.d.mts
CHANGED
|
@@ -2,12 +2,12 @@ import { BookAdapter, BookExport, BookFacts, BookFile, BookFileType, BookImport,
|
|
|
2
2
|
import { Located, SourceLocation } from "./contracts/location.mjs";
|
|
3
3
|
import { GrimoireCheckReport, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireFinding, GrimoireFindingInput, GrimoireSeverity, RouteFreshness } from "./contracts/findings.mjs";
|
|
4
4
|
import { BOOK_SCHEMA_VERSION, BookAnnotations, BookEntry, BookFactsCache, BookManifest, BookManifestFile, BookMobileScreensFile, BookModuleSummary, BookRouteRef, BookRoutesFile, BookSitePagesFile, BuildBookOptions, BuildBookResult, LoadedBook, WriteBookResult } from "./contracts/book.mjs";
|
|
5
|
-
import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenStatus, WrittenStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
|
|
6
|
-
import { CriterionStatus, ProofLine, ProofResult, TestOutcome, TestResultsStore } from "./contracts/test-results.mjs";
|
|
5
|
+
import { CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CriterionId, FeatureVersion, FlowRef, StepType, TaskStatus, TaskType, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho } from "./contracts/written.mjs";
|
|
6
|
+
import { CriterionStatus, ProofLine, ProofResult, TestOutcome, TestResultsInfo, TestResultsStore, UnmatchedProof } from "./contracts/test-results.mjs";
|
|
7
7
|
import { CollectedFiles, FeatureBookmap, FeaturesIndex, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, Ownership, TaskSummary, TasksIndex } from "./contracts/bookmap.mjs";
|
|
8
8
|
import { AppMatch, GrimoireRule, GrimoireSnapshot, OpenGrimoireOptions } from "./contracts/snapshot.mjs";
|
|
9
|
-
import { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.mjs";
|
|
10
9
|
import { ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult } from "./contracts/scry.mjs";
|
|
10
|
+
import { CollectedListText, ReleaseCollection, ReleaseEntry, WriteReleaseResult } from "./contracts/releases.mjs";
|
|
11
11
|
import { GRIMOIRE_CODES, GRIMOIRE_CODE_LIST, GrimoireCode } from "./codes/codes.mjs";
|
|
12
12
|
import { GRIMOIRE_CODES_DOCS_URL, GrimoireError, createFinding, explainGrimoireCode, grimoireCodeDocsUrl, isGrimoireCode } from "./codes/index.mjs";
|
|
13
13
|
import { BookPathInput, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, bookEntryPath, bookEntryPaths, toPosixPath } from "./paths/index.mjs";
|
|
@@ -30,4 +30,4 @@ import { readTestResults } from "./test-results/index.mjs";
|
|
|
30
30
|
import { formatScryResult } from "./scry/format.mjs";
|
|
31
31
|
import { parseScryQuery } from "./scry/parse.mjs";
|
|
32
32
|
import { scry } from "./scry/query.mjs";
|
|
33
|
-
export { AppMatch, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CollectedFiles, type CollectedInput, CollectedListText, CriterionId, CriterionStatus, type CriterionTestResult, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireRule, GrimoireSeverity, GrimoireSnapshot, LoadedBook, Located, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ReleaseCollection, ReleaseEntry, RouteFreshness, type ScanProofsResult, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult, SourceLocation, StepType, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsStore, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenStatus, WrittenStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
|
|
33
|
+
export { AppMatch, BOOK_SCHEMA_VERSION, BookAdapter, BookAnnotations, BookEntry, BookExport, BookFacts, BookFactsCache, BookFile, BookFileType, BookImport, BookManifest, BookManifestFile, BookMobileApp, BookMobileScreensFile, BookModuleSummary, BookNamedThing, BookNamedType, BookPage, BookPageLink, type BookPathInput, BookRoute, BookRouteRef, BookRoutesFile, BookScreen, BookSite, BookSitePagesFile, BuildBookOptions, BuildBookResult, CASE_QUESTIONS, COLLECTED_END_MARKER, COLLECTED_START_MARKER, CaseQuestion, ChangeWord, CollectedFiles, type CollectedInput, CollectedListText, CriterionId, CriterionStatus, type CriterionTestResult, FeatureBookmap, FeatureVersion, FeaturesIndex, type FileGraph, FileOwnership, FlowBookmap, FlowBookmapCriterion, FlowBookmapStep, FlowRef, type FrontMatterField, type FrontMatterResult, type FrontMatterValue, GRIMOIRE_CODES, GRIMOIRE_CODES_DOCS_URL, GRIMOIRE_CODE_LIST, GRIMOIRE_DIR, GRIMOIRE_IGNORE_RULES, GRIMOIRE_PATHS, GrimoireCheckReport, type GrimoireCode, GrimoireCodeArea, GrimoireCodeDefinition, GrimoireError, GrimoireFinding, GrimoireFindingInput, GrimoireRule, GrimoireSeverity, GrimoireSnapshot, LoadedBook, Located, OpenGrimoireOptions, Ownership, type ParseGrimoireResult, ProofLine, ProofResult, ReleaseCollection, ReleaseEntry, RouteFreshness, type ScanProofsResult, ScryFeatureResult, ScryFileResult, ScryFlowResult, ScryHit, ScryHitType, ScryImpactResult, ScryNotes, ScryPageRef, ScryQuery, ScryResult, ScryRouteResult, ScrySearchResult, SourceLocation, StepType, TaskStatus, TaskSummary, TaskType, TasksIndex, TestOutcome, TestResultsInfo, TestResultsStore, UnmatchedProof, WriteBookResult, WriteReleaseResult, WrittenApp, WrittenBlockFile, WrittenBlockRow, WrittenCase, WrittenChangelog, WrittenChangelogEntry, WrittenChangelogSection, WrittenChangesWith, WrittenCriterion, WrittenEntryPoint, WrittenFeature, WrittenFeatureReadme, WrittenFlow, WrittenGrimoire, WrittenLayout, WrittenListLine, WrittenOrigin, WrittenPage, WrittenRelease, WrittenReleaseListed, WrittenScreenshot, WrittenStatus, WrittenStep, WrittenStoryStep, WrittenTask, WrittenVersionBrief, WrittenWho, bookEntryPath, bookEntryPaths, buildBook, buildCollectedFiles, checkGrimoire, collectRelease, createFinding, criterionStatus, explainGrimoireCode, fileGraph, formatCheckReport, formatScryResult, grimoireCodeDocsUrl, importClosure, importerClosure, isGrimoireCode, loadBook, matchApps, openGrimoire, parseGrimoire, parseScryQuery, readFrontMatter, readTestResults, renderCollectedList, resolveOwnership, scanProofs, scanProofsInText, scry, toPosixPath, writeBook, writeCollectedFiles, writeRelease };
|
package/esm/paths/index.d.mts
CHANGED
|
@@ -25,6 +25,8 @@ export declare const GRIMOIRE_PATHS: {
|
|
|
25
25
|
/** Warlock. */
|
|
26
26
|
readonly tasksIndex: "grimoire/tasks/index.json";
|
|
27
27
|
readonly releases: "grimoire/releases";
|
|
28
|
+
/** Images that written files show (`` lines point inside this folder). */
|
|
29
|
+
readonly screenshots: "grimoire/screenshots";
|
|
28
30
|
};
|
|
29
31
|
/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
|
|
30
32
|
export declare const GRIMOIRE_IGNORE_RULES: readonly ["/grimoire/book/", "/grimoire/features/index.json", "/grimoire/features/**/bookmap.json", "/grimoire/features/**/*.bookmap.json", "/grimoire/tasks/index.json"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"mappings":";;qBAOa;;qBAGA;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;;;qBAIW;;wBAWG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"mappings":";;qBAOa;;qBAGA;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;WACA;;WAEA;WACA;WACA;WACA;WACA;;WAEA;WACA;;WAEA;;;qBAIW;;wBAWG,YAAY;;YAkDhB;EACV;;EAEA;IAAc;IAAY;;;;;;;;;;;;;;;wBAeZ,eAAe,gBAAgB,kBAAkB;;wBAiCjD,cAAc,OAAO"}
|
package/esm/paths/index.mjs
CHANGED
|
@@ -30,7 +30,9 @@ const GRIMOIRE_PATHS = {
|
|
|
30
30
|
doneTasks: "grimoire/tasks/done",
|
|
31
31
|
/** Warlock. */
|
|
32
32
|
tasksIndex: "grimoire/tasks/index.json",
|
|
33
|
-
releases: "grimoire/releases"
|
|
33
|
+
releases: "grimoire/releases",
|
|
34
|
+
/** Images that written files show (`` lines point inside this folder). */
|
|
35
|
+
screenshots: "grimoire/screenshots"
|
|
34
36
|
};
|
|
35
37
|
/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */
|
|
36
38
|
const GRIMOIRE_IGNORE_RULES = [
|
package/esm/paths/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"sourcesContent":["/**\n * Where everything lives under `grimoire/`, and how a source file maps to its\n * book entry. Every path here is project-relative and uses `/`.\n */\nimport path from \"node:path\";\n\n/** The folder at the project root. */\nexport const GRIMOIRE_DIR = \"grimoire\";\n\n/** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */\nexport const GRIMOIRE_PATHS = {\n /** Warlock. The generated book (ignored by git). */\n book: \"grimoire/book\",\n /** Warlock. The freshness fingerprint. */\n bookManifest: \"grimoire/book/manifest.json\",\n /** Warlock. The adapter's last facts (machine use). */\n bookFactsCache: \"grimoire/book/.cache/facts.json\",\n /** Warlock. Every route, by module. */\n bookRoutes: \"grimoire/book/app/routes.json\",\n /** Warlock (the Vitest reporter). Test results per proving test. */\n testResults: \"grimoire/book/test-results.json\",\n /** Warlock. Default folder of the static devtools export. */\n staticSite: \"grimoire/book/site\",\n features: \"grimoire/features\",\n /** Warlock. */\n featuresIndex: \"grimoire/features/index.json\",\n apps: \"grimoire/apps\",\n tasks: \"grimoire/tasks\",\n openTasks: \"grimoire/tasks/open\",\n doneTasks: \"grimoire/tasks/done\",\n /** Warlock. */\n tasksIndex: \"grimoire/tasks/index.json\",\n releases: \"grimoire/releases\",\n} as const;\n\n/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */\nexport const GRIMOIRE_IGNORE_RULES = [\n \"/grimoire/book/\",\n \"/grimoire/features/index.json\",\n \"/grimoire/features/**/bookmap.json\",\n \"/grimoire/features/**/*.bookmap.json\",\n \"/grimoire/tasks/index.json\",\n] as const;\n\nconst CODE_EXTENSION = /\\.(?:d\\.ts|[cm]?[jt]s|[jt]sx)$/;\n\n/** A path with `\\` turned into `/`. */\nexport function toPosixPath(file: string): string {\n return file.split(\"\\\\\").join(\"/\");\n}\n\n/** A project-relative POSIX path for an absolute or relative path. */\nexport function projectPath(root: string, file: string): string {\n return toPosixPath(path.relative(root, path.resolve(root, file)));\n}\n\n/** Whether a project-relative file is inside a project-relative folder (or is it). */\nexport function isInsideFolder(file: string, folder: string): boolean {\n const normalizedFolder = toPosixPath(folder).replace(/\\/+$/, \"\");\n const normalizedFile = toPosixPath(file);\n\n return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);\n}\n\n/** Whether a file name is a code file the book has an entry for. */\nexport function isCodeFile(file: string): boolean {\n return CODE_EXTENSION.test(file);\n}\n\n/** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */\nexport function isReservedBookPath(bookPath: string): boolean {\n return (\n bookPath === GRIMOIRE_PATHS.bookManifest ||\n bookPath === GRIMOIRE_PATHS.bookRoutes ||\n bookPath === GRIMOIRE_PATHS.testResults ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) ||\n /^grimoire\\/book\\/web\\/[^/]+\\.pages\\.json$/.test(bookPath) ||\n /^grimoire\\/book\\/mobile\\/[^/]+\\.screens\\.json$/.test(bookPath)\n );\n}\n\n/** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */\nfunction plainEntryPath(file: string, mobileApp: string | null, mobileRoot: string | null): string {\n const posix = toPosixPath(file);\n let relative: string;\n\n if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) {\n relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\\/+$/, \"\").length + 1)}`;\n } else {\n relative = posix.startsWith(\"src/\") ? posix.slice(4) : posix;\n }\n\n return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, \"\")}.json`;\n}\n\n/** One file to place in the book. */\nexport type BookPathInput = {\n file: string;\n /** Mobile app id and root when the file belongs to a mobile app. */\n mobileApp?: { id: string; root: string } | null;\n};\n\n/**\n * The book entry path of every given code file.\n *\n * `src/app/auth/controllers/login.controller.ts` →\n * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app\n * file `mobile/app/index.tsx` of app `mobile` →\n * `grimoire/book/mobile/mobile/app/index.json`.\n *\n * When two files would share a path (`a.ts` and `a.tsx`), or a file would\n * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those\n * files keep their full name instead: `a.ts.json`, `routes.ts.json`.\n */\nexport function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string> {\n const plain = new Map<string, string>();\n const counts = new Map<string, number>();\n\n for (const input of files) {\n const entry = plainEntryPath(\n input.file,\n input.mobileApp?.id ?? null,\n input.mobileApp?.root ?? null,\n );\n plain.set(input.file, entry);\n counts.set(entry, (counts.get(entry) ?? 0) + 1);\n }\n\n const result = new Map<string, string>();\n\n for (const input of files) {\n const entry = plain.get(input.file);\n\n if (entry === undefined) continue;\n\n if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {\n const name = path.posix.basename(toPosixPath(input.file));\n result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);\n } else {\n result.set(input.file, entry);\n }\n }\n\n return result;\n}\n\n/** The book entry path of one file, when no other file can collide with it. */\nexport function bookEntryPath(input: BookPathInput): string {\n return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);\n}\n\n/** `grimoire/book/web/<site>.pages.json`. */\nexport function sitePagesPath(site: string): string {\n return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;\n}\n\n/** `grimoire/book/mobile/<app>.screens.json`. */\nexport function mobileScreensPath(app: string): string {\n return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;\n}\n\n/** `grimoire/book/<module without src/>/index.md`. */\nexport function moduleSummaryPath(module: string): string {\n const posix = toPosixPath(module);\n\n return `${GRIMOIRE_PATHS.book}/${posix.startsWith(\"src/\") ? posix.slice(4) : posix}/index.md`;\n}\n\n/** `grimoire/features/<feature>/bookmap.json`. */\nexport function featureBookmapPath(feature: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;\n}\n\n/** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */\nexport function flowBookmapPath(feature: string, flow: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;\n}\n\n/** `grimoire/releases/<release>.md`. */\nexport function releaseFilePath(release: string): string {\n return `${GRIMOIRE_PATHS.releases}/${release}.md`;\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe;;AAG5B,MAAa,iBAAiB;;CAE5B,MAAM;;CAEN,cAAc;;CAEd,gBAAgB;;CAEhB,YAAY;;CAEZ,aAAa;;CAEb,YAAY;CACZ,UAAU;;CAEV,eAAe;CACf,MAAM;CACN,OAAO;CACP,WAAW;CACX,WAAW;;CAEX,YAAY;CACZ,UAAU;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/paths/index.ts"],"sourcesContent":["/**\n * Where everything lives under `grimoire/`, and how a source file maps to its\n * book entry. Every path here is project-relative and uses `/`.\n */\nimport path from \"node:path\";\n\n/** The folder at the project root. */\nexport const GRIMOIRE_DIR = \"grimoire\";\n\n/** Project-relative paths of the Grimoire layout. Agent-written unless marked Warlock. */\nexport const GRIMOIRE_PATHS = {\n /** Warlock. The generated book (ignored by git). */\n book: \"grimoire/book\",\n /** Warlock. The freshness fingerprint. */\n bookManifest: \"grimoire/book/manifest.json\",\n /** Warlock. The adapter's last facts (machine use). */\n bookFactsCache: \"grimoire/book/.cache/facts.json\",\n /** Warlock. Every route, by module. */\n bookRoutes: \"grimoire/book/app/routes.json\",\n /** Warlock (the Vitest reporter). Test results per proving test. */\n testResults: \"grimoire/book/test-results.json\",\n /** Warlock. Default folder of the static devtools export. */\n staticSite: \"grimoire/book/site\",\n features: \"grimoire/features\",\n /** Warlock. */\n featuresIndex: \"grimoire/features/index.json\",\n apps: \"grimoire/apps\",\n tasks: \"grimoire/tasks\",\n openTasks: \"grimoire/tasks/open\",\n doneTasks: \"grimoire/tasks/done\",\n /** Warlock. */\n tasksIndex: \"grimoire/tasks/index.json\",\n releases: \"grimoire/releases\",\n /** Images that written files show (`` lines point inside this folder). */\n screenshots: \"grimoire/screenshots\",\n} as const;\n\n/** Lines a project's `.gitignore` needs so Warlock's files stay out of git. */\nexport const GRIMOIRE_IGNORE_RULES = [\n \"/grimoire/book/\",\n \"/grimoire/features/index.json\",\n \"/grimoire/features/**/bookmap.json\",\n \"/grimoire/features/**/*.bookmap.json\",\n \"/grimoire/tasks/index.json\",\n] as const;\n\nconst CODE_EXTENSION = /\\.(?:d\\.ts|[cm]?[jt]s|[jt]sx)$/;\n\n/** A path with `\\` turned into `/`. */\nexport function toPosixPath(file: string): string {\n return file.split(\"\\\\\").join(\"/\");\n}\n\n/** A project-relative POSIX path for an absolute or relative path. */\nexport function projectPath(root: string, file: string): string {\n return toPosixPath(path.relative(root, path.resolve(root, file)));\n}\n\n/** Whether a project-relative file is inside a project-relative folder (or is it). */\nexport function isInsideFolder(file: string, folder: string): boolean {\n const normalizedFolder = toPosixPath(folder).replace(/\\/+$/, \"\");\n const normalizedFile = toPosixPath(file);\n\n return normalizedFile === normalizedFolder || normalizedFile.startsWith(`${normalizedFolder}/`);\n}\n\n/** Whether a file name is a code file the book has an entry for. */\nexport function isCodeFile(file: string): boolean {\n return CODE_EXTENSION.test(file);\n}\n\n/** Book paths Warlock writes for lists; a mirrored entry never takes one of them. */\nexport function isReservedBookPath(bookPath: string): boolean {\n return (\n bookPath === GRIMOIRE_PATHS.bookManifest ||\n bookPath === GRIMOIRE_PATHS.bookRoutes ||\n bookPath === GRIMOIRE_PATHS.testResults ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.book}/.cache/`) ||\n bookPath.startsWith(`${GRIMOIRE_PATHS.staticSite}/`) ||\n /^grimoire\\/book\\/web\\/[^/]+\\.pages\\.json$/.test(bookPath) ||\n /^grimoire\\/book\\/mobile\\/[^/]+\\.screens\\.json$/.test(bookPath)\n );\n}\n\n/** The mirror of a source file without the collision rules: `src/` dropped, extension → `.json`. */\nfunction plainEntryPath(file: string, mobileApp: string | null, mobileRoot: string | null): string {\n const posix = toPosixPath(file);\n let relative: string;\n\n if (mobileApp !== null && mobileRoot !== null && isInsideFolder(posix, mobileRoot)) {\n relative = `mobile/${mobileApp}/${posix.slice(toPosixPath(mobileRoot).replace(/\\/+$/, \"\").length + 1)}`;\n } else {\n relative = posix.startsWith(\"src/\") ? posix.slice(4) : posix;\n }\n\n return `${GRIMOIRE_PATHS.book}/${relative.replace(CODE_EXTENSION, \"\")}.json`;\n}\n\n/** One file to place in the book. */\nexport type BookPathInput = {\n file: string;\n /** Mobile app id and root when the file belongs to a mobile app. */\n mobileApp?: { id: string; root: string } | null;\n};\n\n/**\n * The book entry path of every given code file.\n *\n * `src/app/auth/controllers/login.controller.ts` →\n * `grimoire/book/app/auth/controllers/login.controller.json`; a mobile app\n * file `mobile/app/index.tsx` of app `mobile` →\n * `grimoire/book/mobile/mobile/app/index.json`.\n *\n * When two files would share a path (`a.ts` and `a.tsx`), or a file would\n * take a reserved list path (`src/app/routes.ts` → `app/routes.json`), those\n * files keep their full name instead: `a.ts.json`, `routes.ts.json`.\n */\nexport function bookEntryPaths(files: readonly BookPathInput[]): Map<string, string> {\n const plain = new Map<string, string>();\n const counts = new Map<string, number>();\n\n for (const input of files) {\n const entry = plainEntryPath(\n input.file,\n input.mobileApp?.id ?? null,\n input.mobileApp?.root ?? null,\n );\n plain.set(input.file, entry);\n counts.set(entry, (counts.get(entry) ?? 0) + 1);\n }\n\n const result = new Map<string, string>();\n\n for (const input of files) {\n const entry = plain.get(input.file);\n\n if (entry === undefined) continue;\n\n if ((counts.get(entry) ?? 0) > 1 || isReservedBookPath(entry)) {\n const name = path.posix.basename(toPosixPath(input.file));\n result.set(input.file, `${path.posix.dirname(entry)}/${name}.json`);\n } else {\n result.set(input.file, entry);\n }\n }\n\n return result;\n}\n\n/** The book entry path of one file, when no other file can collide with it. */\nexport function bookEntryPath(input: BookPathInput): string {\n return bookEntryPaths([input]).get(input.file) ?? plainEntryPath(input.file, null, null);\n}\n\n/** `grimoire/book/web/<site>.pages.json`. */\nexport function sitePagesPath(site: string): string {\n return `${GRIMOIRE_PATHS.book}/web/${site}.pages.json`;\n}\n\n/** `grimoire/book/mobile/<app>.screens.json`. */\nexport function mobileScreensPath(app: string): string {\n return `${GRIMOIRE_PATHS.book}/mobile/${app}.screens.json`;\n}\n\n/** `grimoire/book/<module without src/>/index.md`. */\nexport function moduleSummaryPath(module: string): string {\n const posix = toPosixPath(module);\n\n return `${GRIMOIRE_PATHS.book}/${posix.startsWith(\"src/\") ? posix.slice(4) : posix}/index.md`;\n}\n\n/** `grimoire/features/<feature>/bookmap.json`. */\nexport function featureBookmapPath(feature: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/bookmap.json`;\n}\n\n/** `grimoire/features/<feature>/flows/<flow>.bookmap.json`. */\nexport function flowBookmapPath(feature: string, flow: string): string {\n return `${GRIMOIRE_PATHS.features}/${feature}/flows/${flow}.bookmap.json`;\n}\n\n/** `grimoire/releases/<release>.md`. */\nexport function releaseFilePath(release: string): string {\n return `${GRIMOIRE_PATHS.releases}/${release}.md`;\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe;;AAG5B,MAAa,iBAAiB;;CAE5B,MAAM;;CAEN,cAAc;;CAEd,gBAAgB;;CAEhB,YAAY;;CAEZ,aAAa;;CAEb,YAAY;CACZ,UAAU;;CAEV,eAAe;CACf,MAAM;CACN,OAAO;CACP,WAAW;CACX,WAAW;;CAEX,YAAY;CACZ,UAAU;;CAEV,aAAa;AACf;;AAGA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,iBAAiB;;AAGvB,SAAgB,YAAY,MAAsB;CAChD,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG;AAClC;;AAGA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,OAAO,YAAY,KAAK,SAAS,MAAM,KAAK,QAAQ,MAAM,IAAI,CAAC,CAAC;AAClE;;AAGA,SAAgB,eAAe,MAAc,QAAyB;CACpE,MAAM,mBAAmB,YAAY,MAAM,CAAC,CAAC,QAAQ,QAAQ,EAAE;CAC/D,MAAM,iBAAiB,YAAY,IAAI;CAEvC,OAAO,mBAAmB,oBAAoB,eAAe,WAAW,GAAG,iBAAiB,EAAE;AAChG;;AAGA,SAAgB,WAAW,MAAuB;CAChD,OAAO,eAAe,KAAK,IAAI;AACjC;;AAGA,SAAgB,mBAAmB,UAA2B;CAC5D,OACE,aAAa,eAAe,gBAC5B,aAAa,eAAe,cAC5B,aAAa,eAAe,eAC5B,SAAS,WAAW,GAAG,eAAe,KAAK,SAAS,KACpD,SAAS,WAAW,GAAG,eAAe,WAAW,EAAE,KACnD,4CAA4C,KAAK,QAAQ,KACzD,iDAAiD,KAAK,QAAQ;AAElE;;AAGA,SAAS,eAAe,MAAc,WAA0B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