archidocs 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands.d.ts +8 -8
- package/dist/cli/commands.js +7 -7
- package/dist/cli/dev.d.ts +5 -6
- package/dist/cli/dev.js +12 -14
- package/dist/cli/diff-format.d.ts +1 -5
- package/dist/cli/main.js +2 -324
- package/dist/cli/run.d.ts +18 -0
- package/dist/cli/run.js +283 -0
- package/dist/commands/build.d.ts +51 -0
- package/dist/commands/build.js +39 -0
- package/dist/commands/check.d.ts +8 -0
- package/dist/commands/check.js +5 -0
- package/dist/commands/diff.d.ts +29 -0
- package/dist/commands/diff.js +25 -0
- package/dist/commands/export.d.ts +41 -0
- package/dist/commands/export.js +47 -0
- package/dist/commands/history.d.ts +18 -0
- package/dist/commands/history.js +9 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.js +11 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/load.d.ts +0 -2
- package/dist/core/load.js +5 -6
- package/dist/core/workspace-files.d.ts +13 -0
- package/dist/core/workspace-files.js +20 -0
- package/dist/git.d.ts +2 -0
- package/dist/git.js +14 -4
- package/dist/history/git.d.ts +0 -10
- package/dist/history/git.js +1 -30
- package/dist/history/index.d.ts +15 -31
- package/dist/history/index.js +47 -43
- package/dist/history/points.d.ts +23 -0
- package/dist/history/points.js +28 -0
- package/dist/history/site.d.ts +30 -0
- package/dist/history/site.js +37 -0
- package/dist/mcp/history.d.ts +4 -4
- package/dist/mcp/history.js +56 -116
- package/dist/mcp/server.js +18 -17
- package/dist/mcp/site.d.ts +12 -0
- package/dist/mcp/site.js +46 -0
- package/dist/mcp/source.d.ts +14 -7
- package/dist/mcp/source.js +25 -99
- package/dist/revisions/find.d.ts +64 -0
- package/dist/revisions/find.js +85 -0
- package/dist/revisions/index.d.ts +57 -0
- package/dist/revisions/index.js +24 -0
- package/dist/revisions/site.d.ts +82 -0
- package/dist/revisions/site.js +157 -0
- package/dist/revisions/text.d.ts +8 -0
- package/dist/revisions/text.js +17 -0
- package/dist/revisions/touching.d.ts +7 -0
- package/dist/revisions/touching.js +7 -0
- package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
- package/dist/viewer/assets/{png-CAaXWR-k.js → png-DMwnpRCt.js} +1 -1
- package/dist/viewer/assets/{svg-BPVHfD36.js → svg-DN6lMeZo.js} +1 -1
- package/dist/viewer/index.html +1 -1
- package/dist/workspace/index.d.ts +37 -0
- package/dist/workspace/index.js +52 -0
- package/package.json +1 -1
- package/dist/viewer/assets/index-BXa5R96a.js +0 -138
- /package/dist/{history → revisions}/migrate.d.ts +0 -0
- /package/dist/{history → revisions}/migrate.js +0 -0
package/dist/cli/run.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
3
|
+
import { basename, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { directions } from "../render/layout.js";
|
|
6
|
+
import { themes } from "../render/tokens.js";
|
|
7
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
8
|
+
import { gitTopLevel } from "../git.js";
|
|
9
|
+
import { findCheckout } from "../workspace/index.js";
|
|
10
|
+
import { build, buildHistory, check, diff, exportViews } from "../commands/index.js";
|
|
11
|
+
import { bundleSource, checkoutSource, createServer, DEFAULT_PORT, serveHttp } from "../mcp/index.js";
|
|
12
|
+
import { authoringGuide } from "../guide/index.js";
|
|
13
|
+
import { EXIT, NO_WORKSPACE, parseCommand, usageText } from "./commands.js";
|
|
14
|
+
import { init } from "./init.js";
|
|
15
|
+
import { DEFAULT_DEV_PORT, serveDev } from "./dev.js";
|
|
16
|
+
import { exitCodeFor, formatIssues, formats, formatText } from "./format.js";
|
|
17
|
+
import { DEFAULT_KEEP, pointMessage } from "../history/index.js";
|
|
18
|
+
import { LATEST_BUNDLE_PATH } from "../revisions/index.js";
|
|
19
|
+
import { SCHEMA_VERSION } from "../schema/bundle.js";
|
|
20
|
+
import { diffFormats, formatDiff } from "./diff-format.js";
|
|
21
|
+
/** Exit codes, shared with the command definitions that document them: 0 no errors, 1 errors found (or any warning with `--strict`), 2 could not run. */
|
|
22
|
+
const { ok: OK, foundErrors: FOUND_ERRORS, couldNotRun: COULD_NOT_RUN } = EXIT;
|
|
23
|
+
class UsageError extends Error {
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The prebuilt viewer, which `build --out` copies as is. The CLI runs from
|
|
27
|
+
* dist/cli/ when installed and from src/cli/ in this repo; both sit two
|
|
28
|
+
* levels below the package root, whose dist/viewer/ holds the viewer.
|
|
29
|
+
*/
|
|
30
|
+
const VIEWER_DIR = fileURLToPath(new URL("../../dist/viewer/", import.meta.url));
|
|
31
|
+
/** The package's own package.json, two levels up from dist/cli/ or src/cli/ like the viewer. */
|
|
32
|
+
const PACKAGE_JSON = fileURLToPath(new URL("../../package.json", import.meta.url));
|
|
33
|
+
const usage = usageText();
|
|
34
|
+
const NOT_IN_GIT = "History needs the Workspace in a git repository.";
|
|
35
|
+
const viewerMissing = (viewerDir) => `The viewer is not built (no ${viewerDir}); run \`pnpm build\` first.`;
|
|
36
|
+
/**
|
|
37
|
+
* Runs one CLI command and returns its exit code. It never throws: an error is
|
|
38
|
+
* written to `io.stderr` as `archidocs: <message>`, with the usage text for a
|
|
39
|
+
* usage error, and returns the could-not-run code.
|
|
40
|
+
*/
|
|
41
|
+
export async function run(argv, io) {
|
|
42
|
+
try {
|
|
43
|
+
return await main(argv, io);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
+
io.stderr.write(`archidocs: ${message}\n`);
|
|
48
|
+
if (error instanceof UsageError || error.code?.startsWith("ERR_PARSE_ARGS"))
|
|
49
|
+
io.stderr.write(usage);
|
|
50
|
+
return COULD_NOT_RUN;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function main(argv, io) {
|
|
54
|
+
const [command, ...rest] = argv;
|
|
55
|
+
if (command === "init") {
|
|
56
|
+
const { values } = parseCommand("init", rest);
|
|
57
|
+
if (values.workspace !== undefined && !values.skill)
|
|
58
|
+
throw new UsageError("--workspace only applies with --skill; without it, init uses or creates this repo's Workspace.");
|
|
59
|
+
const cwd = await realpath(io.cwd);
|
|
60
|
+
const repoRoot = (await gitTopLevel(cwd)) ?? cwd;
|
|
61
|
+
const lines = await init({ repoRoot, cwd, skillOnly: values.skill, ...(values.workspace === undefined ? {} : { workspace: values.workspace }) });
|
|
62
|
+
io.stdout.write(lines.join("\n") + "\n");
|
|
63
|
+
return OK;
|
|
64
|
+
}
|
|
65
|
+
if (command === "version") {
|
|
66
|
+
const { values } = parseCommand("version", rest);
|
|
67
|
+
if (values.format !== "text" && values.format !== "json")
|
|
68
|
+
throw new UsageError(`Unknown format "${values.format}"; use text or json.`);
|
|
69
|
+
const { version } = JSON.parse(await readFile(PACKAGE_JSON, "utf8"));
|
|
70
|
+
io.stdout.write(values.format === "json" ? JSON.stringify({ version, schemaVersion: SCHEMA_VERSION }) + "\n" : `archidocs ${version} (Bundle schemaVersion ${SCHEMA_VERSION})\n`);
|
|
71
|
+
return OK;
|
|
72
|
+
}
|
|
73
|
+
if (command === "guide") {
|
|
74
|
+
const { positionals } = parseCommand("guide", rest);
|
|
75
|
+
if (positionals.length > 1)
|
|
76
|
+
throw new UsageError(`Give one topic at a time; got ${positionals.join(", ")}.`);
|
|
77
|
+
const guide = await authoringGuide(positionals[0]);
|
|
78
|
+
if (!guide.ok)
|
|
79
|
+
throw new UsageError(guide.message);
|
|
80
|
+
io.stdout.write(guide.text);
|
|
81
|
+
return OK;
|
|
82
|
+
}
|
|
83
|
+
if (command === "check") {
|
|
84
|
+
const { values } = parseCommand("check", rest);
|
|
85
|
+
const format = values.format;
|
|
86
|
+
if (!formats.includes(format))
|
|
87
|
+
throw new UsageError(`Unknown format "${values.format}"; use ${formats.join(", ")}.`);
|
|
88
|
+
const { issues } = await check(await checkoutFrom(io.cwd));
|
|
89
|
+
io.stdout.write(formatIssues(issues, format, { color: useColor(io) }));
|
|
90
|
+
return exitCodeFor(issues, { strict: values.strict });
|
|
91
|
+
}
|
|
92
|
+
if (command === "build") {
|
|
93
|
+
const { values } = parseCommand("build", rest);
|
|
94
|
+
if (values.preview && values.keep !== undefined)
|
|
95
|
+
throw new UsageError("--keep doesn't apply to --preview, whose site holds just the base and the PR head.");
|
|
96
|
+
if (values.preview && values["bundle-only"])
|
|
97
|
+
throw new UsageError("--bundle-only doesn't apply to --preview, which writes a site.");
|
|
98
|
+
if (values.base !== undefined && !values.preview)
|
|
99
|
+
throw new UsageError("--base only applies with --preview.");
|
|
100
|
+
const keep = values.keep === undefined ? DEFAULT_KEEP : values.keep === "all" ? "all" : Number(values.keep);
|
|
101
|
+
if (keep !== "all" && !(Number.isInteger(keep) && keep >= 0))
|
|
102
|
+
throw new UsageError(`--keep "${values.keep}" is not a count or all.`);
|
|
103
|
+
if (values["bundle-only"] && values.keep !== undefined)
|
|
104
|
+
throw new UsageError("--keep only applies to a site; --bundle-only writes no past Bundles.");
|
|
105
|
+
const result = await build(await checkoutFrom(io.cwd), {
|
|
106
|
+
out: resolve(io.cwd, values.out),
|
|
107
|
+
viewerDir: VIEWER_DIR,
|
|
108
|
+
keep,
|
|
109
|
+
bundleOnly: values["bundle-only"],
|
|
110
|
+
...(values.preview ? { preview: values.base === undefined ? {} : { base: values.base } } : {}),
|
|
111
|
+
});
|
|
112
|
+
switch (result.kind) {
|
|
113
|
+
case "errors":
|
|
114
|
+
io.stdout.write(formatText(result.issues, { color: useColor(io) }));
|
|
115
|
+
io.stderr.write(`Not writing the ${values["bundle-only"] ? "Bundle" : "site"}: the Workspace has errors.\n`);
|
|
116
|
+
return FOUND_ERRORS;
|
|
117
|
+
case "not-in-git":
|
|
118
|
+
throw new UsageError(NOT_IN_GIT);
|
|
119
|
+
case "viewer-missing":
|
|
120
|
+
throw new Error(viewerMissing(result.viewerDir));
|
|
121
|
+
case "preview":
|
|
122
|
+
io.stdout.write(`Wrote the preview site to ${values.out}: Compare origin/${result.base} (${result.baseSha.slice(0, 7)}) → PR (${result.headSha.slice(0, 7)})\n`);
|
|
123
|
+
return OK;
|
|
124
|
+
case "bundle":
|
|
125
|
+
io.stdout.write(`Wrote ${join(values.out, LATEST_BUNDLE_PATH)}\n`);
|
|
126
|
+
return OK;
|
|
127
|
+
case "site":
|
|
128
|
+
io.stdout.write(`Wrote the site to ${values.out}\n`);
|
|
129
|
+
return OK;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (command === "dev") {
|
|
133
|
+
const { values } = parseCommand("dev", rest);
|
|
134
|
+
const port = values.port === undefined ? DEFAULT_DEV_PORT : Number(values.port);
|
|
135
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
136
|
+
throw new UsageError(`--port "${values.port}" is not a port.`);
|
|
137
|
+
if (!existsSync(join(VIEWER_DIR, "index.html")))
|
|
138
|
+
throw new Error(viewerMissing(VIEWER_DIR));
|
|
139
|
+
const checkout = await checkoutFrom(values.workspace === undefined ? io.cwd : resolve(io.cwd, values.workspace));
|
|
140
|
+
const color = useColor(io);
|
|
141
|
+
const dev = await serveDev({
|
|
142
|
+
checkout,
|
|
143
|
+
viewerDir: VIEWER_DIR,
|
|
144
|
+
port,
|
|
145
|
+
...(values.host === undefined ? {} : { host: values.host }),
|
|
146
|
+
onLoad: ({ issues, kept, first }) => {
|
|
147
|
+
const shown = issues.filter((i) => i.severity === "error" || first);
|
|
148
|
+
if (shown.length > 0)
|
|
149
|
+
io.stdout.write(formatText(shown, { color }));
|
|
150
|
+
if (kept)
|
|
151
|
+
io.stderr.write("The Workspace has errors; still serving the last good Bundle.\n");
|
|
152
|
+
else if (!first)
|
|
153
|
+
io.stderr.write(`Reloaded the Workspace (${new Date().toLocaleTimeString()})\n`);
|
|
154
|
+
},
|
|
155
|
+
}).catch((e) => {
|
|
156
|
+
if (e.code === "EADDRINUSE")
|
|
157
|
+
throw new UsageError(`Port ${port} is in use; pick another with --port.`);
|
|
158
|
+
throw e;
|
|
159
|
+
});
|
|
160
|
+
io.stderr.write(`Archidocs dev server on ${dev.url} (watching ${checkout.root}; Ctrl+C to stop)\n`);
|
|
161
|
+
return OK;
|
|
162
|
+
}
|
|
163
|
+
if (command === "export") {
|
|
164
|
+
const { values, positionals } = parseCommand("export", rest);
|
|
165
|
+
const allSaved = values["all-saved"];
|
|
166
|
+
const [viewId, ...extra] = positionals;
|
|
167
|
+
if (allSaved && viewId !== undefined)
|
|
168
|
+
throw new UsageError("Give a View or --all-saved, not both.");
|
|
169
|
+
if (allSaved && values.out === undefined)
|
|
170
|
+
throw new UsageError("--all-saved needs --out <dir> for the pictures.");
|
|
171
|
+
if (!allSaved && viewId === undefined)
|
|
172
|
+
throw new UsageError("Give the View to export, such as c1 or c2/<system>, or --all-saved.");
|
|
173
|
+
if (extra.length > 0)
|
|
174
|
+
throw new UsageError(`Export one View at a time; got ${positionals.join(", ")}.`);
|
|
175
|
+
const format = values.format;
|
|
176
|
+
if (format !== "svg" && format !== "png")
|
|
177
|
+
throw new UsageError(`Unknown format "${format}"; use svg or png.`);
|
|
178
|
+
const direction = values.direction;
|
|
179
|
+
if (direction !== undefined && !directions.includes(direction))
|
|
180
|
+
throw new UsageError(`Unknown direction "${direction}"; use ${directions.join(", ")}.`);
|
|
181
|
+
const theme = values.theme;
|
|
182
|
+
if (!themes.includes(theme))
|
|
183
|
+
throw new UsageError(`Unknown theme "${values.theme}"; use ${themes.join(" or ")}.`);
|
|
184
|
+
const { label } = values;
|
|
185
|
+
const result = await exportViews(await checkoutFrom(io.cwd), {
|
|
186
|
+
views: allSaved ? "all-saved" : [viewId],
|
|
187
|
+
format,
|
|
188
|
+
...(direction === undefined ? {} : { direction }),
|
|
189
|
+
theme,
|
|
190
|
+
...(label === undefined ? {} : { label }),
|
|
191
|
+
out: allSaved ? resolve(io.cwd, values.out) : io.cwd,
|
|
192
|
+
...(!allSaved && values.out !== undefined ? { file: resolve(io.cwd, values.out) } : {}),
|
|
193
|
+
});
|
|
194
|
+
switch (result.kind) {
|
|
195
|
+
case "errors":
|
|
196
|
+
io.stdout.write(formatText(result.issues, { color: useColor(io) }));
|
|
197
|
+
io.stderr.write("Not exporting: the Workspace has errors.\n");
|
|
198
|
+
return FOUND_ERRORS;
|
|
199
|
+
case "unknown-view":
|
|
200
|
+
throw new UsageError(`Unknown View "${result.id}"; Views are c1, c2, c2/<system>, c3/<service with Components>, deployment/<environment> and Saved Views (project:view-id).`);
|
|
201
|
+
case "written":
|
|
202
|
+
// Each picture as the user named it: under --out, or --out itself, or its own name in the current folder.
|
|
203
|
+
for (const { path } of result.files)
|
|
204
|
+
io.stdout.write(`Wrote ${allSaved ? join(values.out, basename(path)) : (values.out ?? basename(path))}\n`);
|
|
205
|
+
return OK;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (command === "diff") {
|
|
209
|
+
const { values, positionals } = parseCommand("diff", rest);
|
|
210
|
+
const format = values.format;
|
|
211
|
+
if (!diffFormats.includes(format))
|
|
212
|
+
throw new UsageError(`Unknown format "${values.format}"; use ${diffFormats.join(", ")}.`);
|
|
213
|
+
const [fromPoint, toPoint, ...extra] = positionals;
|
|
214
|
+
if (fromPoint === undefined)
|
|
215
|
+
throw new UsageError("Give the point to diff from: a ref or a date.");
|
|
216
|
+
if (extra.length > 0)
|
|
217
|
+
throw new UsageError(`Give at most two points; got ${positionals.join(", ")}.`);
|
|
218
|
+
const result = await diff(await checkoutFrom(io.cwd), toPoint === undefined ? { from: fromPoint } : { from: fromPoint, to: toPoint });
|
|
219
|
+
if (result.kind === "not-in-git")
|
|
220
|
+
throw new UsageError(NOT_IN_GIT);
|
|
221
|
+
if (result.kind === "unknown-point")
|
|
222
|
+
throw new UsageError(pointMessage(result.point, result.failure));
|
|
223
|
+
io.stdout.write(formatDiff(result.changes, result.from, result.to, format));
|
|
224
|
+
return OK;
|
|
225
|
+
}
|
|
226
|
+
if (command === "history") {
|
|
227
|
+
const [sub, ...args] = rest;
|
|
228
|
+
if (sub !== "build")
|
|
229
|
+
throw new UsageError(sub ? `Unknown history command "${sub}".` : "Give a history command: build.");
|
|
230
|
+
const { values } = parseCommand("history build", args);
|
|
231
|
+
const result = await buildHistory(await checkoutFrom(io.cwd), values.since === undefined ? {} : { since: values.since });
|
|
232
|
+
if (result.kind === "not-in-git")
|
|
233
|
+
throw new UsageError(NOT_IN_GIT);
|
|
234
|
+
const { revisions, built } = result;
|
|
235
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
236
|
+
io.stdout.write(`Built ${plural(built, "Revision")}; ${revisions - built} of ${revisions} already built.\n`);
|
|
237
|
+
return OK;
|
|
238
|
+
}
|
|
239
|
+
if (command === "mcp") {
|
|
240
|
+
const { values } = parseCommand("mcp", rest);
|
|
241
|
+
const viewerUrl = values["viewer-url"];
|
|
242
|
+
if (viewerUrl !== undefined && !URL.canParse(viewerUrl))
|
|
243
|
+
throw new UsageError(`--viewer-url "${viewerUrl}" is not a URL.`);
|
|
244
|
+
if (values.workspace !== undefined && values.bundle !== undefined)
|
|
245
|
+
throw new UsageError("Give --workspace or --bundle, not both.");
|
|
246
|
+
if (!values.http && values["allow-writes"])
|
|
247
|
+
throw new UsageError("--allow-writes only applies with --http; over stdio a checkout already takes writes.");
|
|
248
|
+
if (!values.http && (values.host !== undefined || values.port !== undefined))
|
|
249
|
+
throw new UsageError("--host and --port only apply with --http.");
|
|
250
|
+
const port = values.port === undefined ? DEFAULT_PORT : Number(values.port);
|
|
251
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
252
|
+
throw new UsageError(`--port "${values.port}" is not a port.`);
|
|
253
|
+
const source = values.bundle !== undefined
|
|
254
|
+
? bundleSource({ location: /^https?:\/\//i.test(values.bundle) ? values.bundle : resolve(io.cwd, values.bundle) })
|
|
255
|
+
: checkoutSource({ root: (await checkoutFrom(values.workspace === undefined ? io.cwd : resolve(io.cwd, values.workspace))).root });
|
|
256
|
+
const options = { source, ...(viewerUrl === undefined ? {} : { viewerUrl }) };
|
|
257
|
+
if (values.http) {
|
|
258
|
+
const http = await serveHttp({ ...options, port, allowWrites: values["allow-writes"], ...(values.host === undefined ? {} : { host: values.host }) });
|
|
259
|
+
io.stderr.write(`Archidocs MCP server on ${http.url} (writes ${values["allow-writes"] && source.writesAllowed ? "allowed" : "off"})\n`);
|
|
260
|
+
return OK;
|
|
261
|
+
}
|
|
262
|
+
// The one command bound to the process: stdout carries the protocol; the server runs until the client closes stdin.
|
|
263
|
+
serveStdio(() => createServer(options));
|
|
264
|
+
return OK;
|
|
265
|
+
}
|
|
266
|
+
throw new UsageError(command ? `Unknown command "${command}".` : "No command given.");
|
|
267
|
+
}
|
|
268
|
+
/** Colour only on a terminal; `NO_COLOR` turns it off and `FORCE_COLOR` on. */
|
|
269
|
+
function useColor(io) {
|
|
270
|
+
const { NO_COLOR, FORCE_COLOR } = io.env;
|
|
271
|
+
if (NO_COLOR)
|
|
272
|
+
return false;
|
|
273
|
+
if (FORCE_COLOR !== undefined)
|
|
274
|
+
return FORCE_COLOR !== "0";
|
|
275
|
+
return io.stdout.isTTY === true;
|
|
276
|
+
}
|
|
277
|
+
/** The Checkout whose Workspace holds `start`, found by walking up from it. */
|
|
278
|
+
async function checkoutFrom(start) {
|
|
279
|
+
const checkout = await findCheckout(start);
|
|
280
|
+
if (!checkout)
|
|
281
|
+
throw new UsageError(NO_WORKSPACE);
|
|
282
|
+
return checkout;
|
|
283
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Issue } from "../core/index.ts";
|
|
2
|
+
import type { Checkout } from "../workspace/index.ts";
|
|
3
|
+
export interface BuildOptions {
|
|
4
|
+
/** The folder to write, absolute. */
|
|
5
|
+
out: string;
|
|
6
|
+
/** The prebuilt viewer, copied as is into a site. */
|
|
7
|
+
viewerDir: string;
|
|
8
|
+
/** How many past Bundles a site keeps: a count or all. */
|
|
9
|
+
keep: number | "all";
|
|
10
|
+
/** Write only the Bundle, not the site. */
|
|
11
|
+
bundleOnly: boolean;
|
|
12
|
+
/** Write a preview site of HEAD against `origin/<base>`; `base` defaults to origin's HEAD branch, else main. */
|
|
13
|
+
preview?: {
|
|
14
|
+
base?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export type BuildResult =
|
|
18
|
+
/** The Workspace has errors; nothing was written. */
|
|
19
|
+
{
|
|
20
|
+
kind: "errors";
|
|
21
|
+
issues: Issue[];
|
|
22
|
+
}
|
|
23
|
+
/** A preview needs git and the Workspace isn't in a repo; nothing was written. */
|
|
24
|
+
| {
|
|
25
|
+
kind: "not-in-git";
|
|
26
|
+
}
|
|
27
|
+
/** A site needs the viewer, and `viewerDir` has none; nothing was written. */
|
|
28
|
+
| {
|
|
29
|
+
kind: "viewer-missing";
|
|
30
|
+
viewerDir: string;
|
|
31
|
+
}
|
|
32
|
+
/** Wrote the Bundle alone, to `file`. */
|
|
33
|
+
| {
|
|
34
|
+
kind: "bundle";
|
|
35
|
+
file: string;
|
|
36
|
+
}
|
|
37
|
+
/** Wrote the site to `out`. */
|
|
38
|
+
| {
|
|
39
|
+
kind: "site";
|
|
40
|
+
out: string;
|
|
41
|
+
}
|
|
42
|
+
/** Wrote the preview site: the PR head against `origin/<base>`. */
|
|
43
|
+
| {
|
|
44
|
+
kind: "preview";
|
|
45
|
+
out: string;
|
|
46
|
+
base: string;
|
|
47
|
+
baseSha: string;
|
|
48
|
+
headSha: string;
|
|
49
|
+
};
|
|
50
|
+
/** The Workspace's Bundle, alone or as a site with the viewer and past Bundles, or as a PR preview site. */
|
|
51
|
+
export declare function build(checkout: Checkout, options: BuildOptions): Promise<BuildResult>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { cp } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { defaultBaseBranch, previewSides, publishHistory, publishPreview, writeSite } from "../history/index.js";
|
|
5
|
+
import { INDEX_VERSION, LATEST_BUNDLE_PATH } from "../revisions/index.js";
|
|
6
|
+
/** The Workspace's Bundle, alone or as a site with the viewer and past Bundles, or as a PR preview site. */
|
|
7
|
+
export async function build(checkout, options) {
|
|
8
|
+
const { out, viewerDir, keep, bundleOnly } = options;
|
|
9
|
+
const { bundle, issues } = await checkout.load();
|
|
10
|
+
if (issues.some((i) => i.severity === "error"))
|
|
11
|
+
return { kind: "errors", issues };
|
|
12
|
+
// A preview finds both sides before writing anything, so a missing base writes no site.
|
|
13
|
+
let preview;
|
|
14
|
+
if (options.preview) {
|
|
15
|
+
const repo = await checkout.repo();
|
|
16
|
+
if (!repo)
|
|
17
|
+
return { kind: "not-in-git" };
|
|
18
|
+
const h = repo.history;
|
|
19
|
+
preview = { h, sides: await previewSides(h, options.preview.base ?? (await defaultBaseBranch(h.repoRoot))) };
|
|
20
|
+
}
|
|
21
|
+
if (bundleOnly) {
|
|
22
|
+
await writeSite(out, { bundle });
|
|
23
|
+
return { kind: "bundle", file: join(out, LATEST_BUNDLE_PATH) };
|
|
24
|
+
}
|
|
25
|
+
if (!existsSync(join(viewerDir, "index.html")))
|
|
26
|
+
return { kind: "viewer-missing", viewerDir };
|
|
27
|
+
await cp(viewerDir, out, { recursive: true });
|
|
28
|
+
// The viewer's exports name the Workspace as `archidocs export` does: by its repo's folder.
|
|
29
|
+
const latest = { bundle, workspace: await checkout.name() };
|
|
30
|
+
if (preview)
|
|
31
|
+
return { kind: "preview", out, ...(await publishPreview(preview.h, out, preview.sides, bundle, latest.workspace)) };
|
|
32
|
+
const repo = await checkout.repo();
|
|
33
|
+
if (repo)
|
|
34
|
+
await publishHistory(repo.history, out, latest, { keep });
|
|
35
|
+
// Outside git, an empty index, so the viewer knows there is no history.
|
|
36
|
+
else
|
|
37
|
+
await writeSite(out, { ...latest, index: { schemaVersion: INDEX_VERSION, revisions: [] } });
|
|
38
|
+
return { kind: "site", out };
|
|
39
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Issue } from "../core/index.ts";
|
|
2
|
+
import type { Checkout } from "../workspace/index.ts";
|
|
3
|
+
export type CheckResult = {
|
|
4
|
+
kind: "checked";
|
|
5
|
+
issues: Issue[];
|
|
6
|
+
};
|
|
7
|
+
/** The Workspace's issues. */
|
|
8
|
+
export declare function check(checkout: Checkout): Promise<CheckResult>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Change } from "../core/index.ts";
|
|
2
|
+
import { type PointFailure } from "../history/index.ts";
|
|
3
|
+
import type { Checkout } from "../workspace/index.ts";
|
|
4
|
+
/** One side of a diff: the point as given and the commit it resolved to (null for the working tree). */
|
|
5
|
+
export interface DiffSide {
|
|
6
|
+
point: string;
|
|
7
|
+
commit: string | null;
|
|
8
|
+
}
|
|
9
|
+
export type DiffResult =
|
|
10
|
+
/** History needs the Workspace in a git repo. */
|
|
11
|
+
{
|
|
12
|
+
kind: "not-in-git";
|
|
13
|
+
}
|
|
14
|
+
/** A point names no commit: an unknown ref, a date before the first Revision, or a prefix of several Revisions' shas. */
|
|
15
|
+
| {
|
|
16
|
+
kind: "unknown-point";
|
|
17
|
+
point: string;
|
|
18
|
+
failure: PointFailure;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "ok";
|
|
21
|
+
from: DiffSide;
|
|
22
|
+
to: DiffSide;
|
|
23
|
+
changes: Change[];
|
|
24
|
+
};
|
|
25
|
+
/** The Changes between two points in history (refs or dates); a missing `to` is the working tree. */
|
|
26
|
+
export declare function diff(checkout: Checkout, points: {
|
|
27
|
+
from: string;
|
|
28
|
+
to?: string;
|
|
29
|
+
}): Promise<DiffResult>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { diff as diffBundles } from "../core/index.js";
|
|
2
|
+
import { bundleAt, resolvePoint } from "../history/index.js";
|
|
3
|
+
/** The Changes between two points in history (refs or dates); a missing `to` is the working tree. */
|
|
4
|
+
export async function diff(checkout, points) {
|
|
5
|
+
const repo = await checkout.repo();
|
|
6
|
+
if (!repo)
|
|
7
|
+
return { kind: "not-in-git" };
|
|
8
|
+
const h = repo.history;
|
|
9
|
+
/** A point's Bundle; with no point, the working tree's. */
|
|
10
|
+
const side = async (point) => {
|
|
11
|
+
if (point === undefined)
|
|
12
|
+
return { ok: true, side: { point: "working tree", commit: null }, bundle: (await checkout.load()).bundle };
|
|
13
|
+
const resolved = await resolvePoint(h, point);
|
|
14
|
+
if (!resolved.ok)
|
|
15
|
+
return { ok: false, result: { kind: "unknown-point", point, failure: resolved } };
|
|
16
|
+
return { ok: true, side: { point, commit: resolved.sha }, bundle: (await bundleAt(h, resolved.sha)).bundle };
|
|
17
|
+
};
|
|
18
|
+
const from = await side(points.from);
|
|
19
|
+
if (!from.ok)
|
|
20
|
+
return from.result;
|
|
21
|
+
const to = await side(points.to);
|
|
22
|
+
if (!to.ok)
|
|
23
|
+
return to.result;
|
|
24
|
+
return { kind: "ok", from: from.side, to: to.side, changes: diffBundles(from.bundle, to.bundle) };
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Issue } from "../core/index.ts";
|
|
2
|
+
import { type Direction } from "../render/layout.ts";
|
|
3
|
+
import type { Theme } from "../render/tokens.ts";
|
|
4
|
+
import type { Checkout } from "../workspace/index.ts";
|
|
5
|
+
export interface ExportOptions {
|
|
6
|
+
/** The View ids to draw (c1, c2/<system>, project:view-id, …), or every Saved View. */
|
|
7
|
+
views: string[] | "all-saved";
|
|
8
|
+
format: "svg" | "png";
|
|
9
|
+
/** Wins over each View's own direction. */
|
|
10
|
+
direction?: Direction;
|
|
11
|
+
theme: Theme;
|
|
12
|
+
/** Replaces the source line under the title. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** The folder the pictures go in, absolute; each is named by its View id. */
|
|
15
|
+
out: string;
|
|
16
|
+
/** With one View id: the picture's path, absolute, instead of one named by the id in `out`. */
|
|
17
|
+
file?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ExportedFile {
|
|
20
|
+
view: string;
|
|
21
|
+
/** Absolute. */
|
|
22
|
+
path: string;
|
|
23
|
+
}
|
|
24
|
+
export type ExportResult =
|
|
25
|
+
/** The Workspace has errors; nothing was written. */
|
|
26
|
+
{
|
|
27
|
+
kind: "errors";
|
|
28
|
+
issues: Issue[];
|
|
29
|
+
}
|
|
30
|
+
/** No View has this id; nothing was written. */
|
|
31
|
+
| {
|
|
32
|
+
kind: "unknown-view";
|
|
33
|
+
id: string;
|
|
34
|
+
}
|
|
35
|
+
/** The pictures written, in order. */
|
|
36
|
+
| {
|
|
37
|
+
kind: "written";
|
|
38
|
+
files: ExportedFile[];
|
|
39
|
+
};
|
|
40
|
+
/** Lays out and draws Views to SVG or PNG files. */
|
|
41
|
+
export declare function exportViews(checkout: Checkout, options: ExportOptions): Promise<ExportResult>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { resolveView } from "../core/index.js";
|
|
4
|
+
// The render files themselves, not render/index.ts, which re-exports png.ts and so would load resvg for every caller.
|
|
5
|
+
import { layoutView } from "../render/layout.js";
|
|
6
|
+
import { renderSequenceSvg } from "../render/sequence-svg.js";
|
|
7
|
+
import { renderSvg } from "../render/svg.js";
|
|
8
|
+
/** Lays out and draws Views to SVG or PNG files. */
|
|
9
|
+
export async function exportViews(checkout, options) {
|
|
10
|
+
const { format, direction, theme, label } = options;
|
|
11
|
+
if (options.file !== undefined && (options.views === "all-saved" || options.views.length !== 1))
|
|
12
|
+
throw new Error("`file` names the picture of one View.");
|
|
13
|
+
const { bundle, issues } = await checkout.load();
|
|
14
|
+
if (issues.some((i) => i.severity === "error"))
|
|
15
|
+
return { kind: "errors", issues };
|
|
16
|
+
const views = [];
|
|
17
|
+
if (options.views === "all-saved") {
|
|
18
|
+
for (const saved of bundle.views) {
|
|
19
|
+
const view = resolveView(bundle, saved.id);
|
|
20
|
+
if (view)
|
|
21
|
+
views.push([saved.id, view]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
for (const id of options.views) {
|
|
26
|
+
const view = resolveView(bundle, id);
|
|
27
|
+
if (!view)
|
|
28
|
+
return { kind: "unknown-view", id };
|
|
29
|
+
views.push([id, view]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const source = { workspace: await checkout.name(), commit: bundle.commit, date: bundle.builtAt };
|
|
33
|
+
const toPng = format === "png" ? (await import("../render/node.js")).renderPngInNode : undefined;
|
|
34
|
+
if (options.file === undefined)
|
|
35
|
+
await mkdir(options.out, { recursive: true });
|
|
36
|
+
const files = [];
|
|
37
|
+
for (const [id, view] of views) {
|
|
38
|
+
const path = options.file ?? join(options.out, `${id.replace(/[/:]/g, "-")}.${format}`);
|
|
39
|
+
// A Dynamic View draws as a sequence chart, any other as a diagram.
|
|
40
|
+
const svg = view.kind === "dynamic"
|
|
41
|
+
? renderSequenceSvg({ bundle, view, source, theme, label })
|
|
42
|
+
: renderSvg({ bundle, view, layout: await layoutView(view, direction === undefined ? {} : { direction }), source, theme, label });
|
|
43
|
+
await writeFile(path, toPng ? await toPng(svg) : svg);
|
|
44
|
+
files.push({ view: id, path });
|
|
45
|
+
}
|
|
46
|
+
return { kind: "written", files };
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Checkout } from "../workspace/index.ts";
|
|
2
|
+
export interface BuildHistoryOptions {
|
|
3
|
+
/** Only Revisions at or after this ref or date. */
|
|
4
|
+
since?: string;
|
|
5
|
+
}
|
|
6
|
+
export type BuildHistoryResult =
|
|
7
|
+
/** History needs the Workspace in a git repo. */
|
|
8
|
+
{
|
|
9
|
+
kind: "not-in-git";
|
|
10
|
+
}
|
|
11
|
+
/** How many Revisions are in scope, and how many of those this run built. */
|
|
12
|
+
| {
|
|
13
|
+
kind: "ok";
|
|
14
|
+
revisions: number;
|
|
15
|
+
built: number;
|
|
16
|
+
};
|
|
17
|
+
/** Builds and caches the Bundle of every Revision not yet built. */
|
|
18
|
+
export declare function buildHistory(checkout: Checkout, options?: BuildHistoryOptions): Promise<BuildHistoryResult>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { buildHistory as buildRevisions } from "../history/index.js";
|
|
2
|
+
/** Builds and caches the Bundle of every Revision not yet built. */
|
|
3
|
+
export async function buildHistory(checkout, options = {}) {
|
|
4
|
+
const repo = await checkout.repo();
|
|
5
|
+
if (!repo)
|
|
6
|
+
return { kind: "not-in-git" };
|
|
7
|
+
const { revisions, built } = await buildRevisions(repo.history, options.since === undefined ? {} : { since: options.since });
|
|
8
|
+
return { kind: "ok", revisions, built };
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's commands as functions over a Checkout: each takes options and
|
|
3
|
+
* returns a tagged result, for `run` to format or for the docs site to use.
|
|
4
|
+
* Node-only. None writes to a stream or reads `process`; an expected outcome
|
|
5
|
+
* is a result, and only unexpected failures (git, the disk) throw.
|
|
6
|
+
*/
|
|
7
|
+
export { check, type CheckResult } from "./check.ts";
|
|
8
|
+
export { build, type BuildOptions, type BuildResult } from "./build.ts";
|
|
9
|
+
export { exportViews, type ExportOptions, type ExportResult, type ExportedFile } from "./export.ts";
|
|
10
|
+
export { diff, type DiffResult, type DiffSide } from "./diff.ts";
|
|
11
|
+
export { buildHistory, type BuildHistoryOptions, type BuildHistoryResult } from "./history.ts";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's commands as functions over a Checkout: each takes options and
|
|
3
|
+
* returns a tagged result, for `run` to format or for the docs site to use.
|
|
4
|
+
* Node-only. None writes to a stream or reads `process`; an expected outcome
|
|
5
|
+
* is a result, and only unexpected failures (git, the disk) throw.
|
|
6
|
+
*/
|
|
7
|
+
export { check } from "./check.js";
|
|
8
|
+
export { build } from "./build.js";
|
|
9
|
+
export { exportViews } from "./export.js";
|
|
10
|
+
export { diff } from "./diff.js";
|
|
11
|
+
export { buildHistory } from "./history.js";
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { load, findWorkspaceRoot,
|
|
1
|
+
export { load, findWorkspaceRoot, type LoadOptions, type LoadResult } from "./load.ts";
|
|
2
2
|
export { nodeFileSystem, type FileSystem, type WritableFileSystem, type DirEntry } from "./fs.ts";
|
|
3
3
|
export { rules, removed, ruleDocsUrl, withDocs, RULE_DOCS_BASE_URL, type RuleDefinition, type RemovedRule } from "./rules.ts";
|
|
4
4
|
export type { Issue, Severity } from "./model.ts";
|
package/dist/core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { load, findWorkspaceRoot
|
|
1
|
+
export { load, findWorkspaceRoot } from "./load.js";
|
|
2
2
|
export { nodeFileSystem } from "./fs.js";
|
|
3
3
|
export { rules, removed, ruleDocsUrl, withDocs, RULE_DOCS_BASE_URL } from "./rules.js";
|
|
4
4
|
export { ruleCatalogue } from "./catalogue.js";
|
package/dist/core/load.d.ts
CHANGED
|
@@ -28,5 +28,3 @@ export declare function loadDetailed(options: LoadOptions): Promise<LoadResult &
|
|
|
28
28
|
}>;
|
|
29
29
|
/** Walks up from `start` to the folder holding `workspace.yaml`, also looking in each folder's `archidocs/`. */
|
|
30
30
|
export declare function findWorkspaceRoot(fs: FileSystem, start: string): Promise<string | undefined>;
|
|
31
|
-
/** The Bundle as written to `workspace.bundle.json`: stable key order, two-space indent. */
|
|
32
|
-
export declare function serializeBundle(bundle: Bundle): string;
|
package/dist/core/load.js
CHANGED
|
@@ -7,6 +7,7 @@ import { checkSchema } from "./schema-check.js";
|
|
|
7
7
|
import { bundleAdrs } from "./adrs.js";
|
|
8
8
|
import { PROJECT_TEMPLATE, readAdr } from "./adr.js";
|
|
9
9
|
import { parseYaml } from "./yaml.js";
|
|
10
|
+
import { isSkippedName, isWorkspaceFile } from "./workspace-files.js";
|
|
10
11
|
const WORKSPACE_FILE = "workspace.yaml";
|
|
11
12
|
const PROJECT_FILE = "project.yaml";
|
|
12
13
|
const ADR_DIR = "adr";
|
|
@@ -117,14 +118,16 @@ async function walk(fs, root) {
|
|
|
117
118
|
const dirs = [root];
|
|
118
119
|
for (let i = 0; i < dirs.length; i++) {
|
|
119
120
|
for (const entry of await fs.readDir(dirs[i])) {
|
|
120
|
-
if (
|
|
121
|
+
if (isSkippedName(entry.name))
|
|
121
122
|
continue;
|
|
122
123
|
const path = join(dirs[i], entry.name);
|
|
123
124
|
if (entry.isDirectory)
|
|
124
125
|
dirs.push(path);
|
|
126
|
+
else if (!isWorkspaceFile(entry.name))
|
|
127
|
+
continue;
|
|
125
128
|
else if (entry.name.endsWith(".yaml"))
|
|
126
129
|
files.push(path);
|
|
127
|
-
else
|
|
130
|
+
else
|
|
128
131
|
markdown.push(path);
|
|
129
132
|
}
|
|
130
133
|
}
|
|
@@ -457,9 +460,5 @@ function toBundle(ws, options) {
|
|
|
457
460
|
// Parsing fixes key order to the schema's.
|
|
458
461
|
return Bundle.parse(bundle);
|
|
459
462
|
}
|
|
460
|
-
/** The Bundle as written to `workspace.bundle.json`: stable key order, two-space indent. */
|
|
461
|
-
export function serializeBundle(bundle) {
|
|
462
|
-
return JSON.stringify(Bundle.parse(bundle), null, 2) + "\n";
|
|
463
|
-
}
|
|
464
463
|
const asRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
465
464
|
const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|