archidocs 0.0.0-stage → 1.0.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/dist/cli/dev.d.ts +31 -0
- package/dist/cli/dev.js +156 -0
- package/dist/cli/diff-format.d.ts +9 -0
- package/dist/cli/diff-format.js +50 -0
- package/dist/cli/format.d.ts +15 -0
- package/dist/cli/format.js +60 -0
- package/dist/cli/init.d.ts +17 -0
- package/dist/cli/init.js +82 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +371 -0
- package/dist/core/adr.d.ts +28 -0
- package/dist/core/adr.js +88 -0
- package/dist/core/adrs.d.ts +20 -0
- package/dist/core/adrs.js +86 -0
- package/dist/core/catalogue.d.ts +7 -0
- package/dist/core/catalogue.js +35 -0
- package/dist/core/compare.d.ts +21 -0
- package/dist/core/compare.js +62 -0
- package/dist/core/deployment-views.d.ts +28 -0
- package/dist/core/deployment-views.js +108 -0
- package/dist/core/deployments.d.ts +18 -0
- package/dist/core/deployments.js +21 -0
- package/dist/core/diff.d.ts +44 -0
- package/dist/core/diff.js +138 -0
- package/dist/core/dynamic-views.d.ts +73 -0
- package/dist/core/dynamic-views.js +162 -0
- package/dist/core/files.d.ts +2 -0
- package/dist/core/files.js +1 -0
- package/dist/core/fs.d.ts +19 -0
- package/dist/core/fs.js +21 -0
- package/dist/core/history-scope.d.ts +40 -0
- package/dist/core/history-scope.js +63 -0
- package/dist/core/impact.d.ts +34 -0
- package/dist/core/impact.js +62 -0
- package/dist/core/index.d.ts +20 -0
- package/dist/core/index.js +18 -0
- package/dist/core/load.d.ts +32 -0
- package/dist/core/load.js +465 -0
- package/dist/core/model.d.ts +150 -0
- package/dist/core/model.js +1 -0
- package/dist/core/ownership.d.ts +34 -0
- package/dist/core/ownership.js +65 -0
- package/dist/core/paths.d.ts +47 -0
- package/dist/core/paths.js +115 -0
- package/dist/core/query.d.ts +51 -0
- package/dist/core/query.js +77 -0
- package/dist/core/refs.d.ts +31 -0
- package/dist/core/refs.js +50 -0
- package/dist/core/rules.d.ts +21 -0
- package/dist/core/rules.js +1025 -0
- package/dist/core/save-as-view.d.ts +45 -0
- package/dist/core/save-as-view.js +114 -0
- package/dist/core/saved-views.d.ts +48 -0
- package/dist/core/saved-views.js +243 -0
- package/dist/core/schema-check.d.ts +13 -0
- package/dist/core/schema-check.js +79 -0
- package/dist/core/search.d.ts +27 -0
- package/dist/core/search.js +63 -0
- package/dist/core/suggest.d.ts +3 -0
- package/dist/core/suggest.js +30 -0
- package/dist/core/views.d.ts +126 -0
- package/dist/core/views.js +217 -0
- package/dist/core/yaml.d.ts +16 -0
- package/dist/core/yaml.js +52 -0
- package/dist/git.d.ts +7 -0
- package/dist/git.js +23 -0
- package/dist/guide/index.d.ts +53 -0
- package/dist/guide/index.js +57 -0
- package/dist/history/git.d.ts +39 -0
- package/dist/history/git.js +126 -0
- package/dist/history/index.d.ts +118 -0
- package/dist/history/index.js +223 -0
- package/dist/history/migrate.d.ts +16 -0
- package/dist/history/migrate.js +30 -0
- package/dist/mcp/history.d.ts +36 -0
- package/dist/mcp/history.js +175 -0
- package/dist/mcp/http.d.ts +23 -0
- package/dist/mcp/http.js +85 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/server.d.ts +54 -0
- package/dist/mcp/server.js +822 -0
- package/dist/mcp/source.d.ts +50 -0
- package/dist/mcp/source.js +132 -0
- package/dist/mcp/writes.d.ts +10 -0
- package/dist/mcp/writes.js +266 -0
- package/dist/render/font.d.ts +8 -0
- package/dist/render/font.js +10 -0
- package/dist/render/index.d.ts +7 -0
- package/dist/render/index.js +7 -0
- package/dist/render/layout.d.ts +53 -0
- package/dist/render/layout.js +199 -0
- package/dist/render/node.d.ts +3 -0
- package/dist/render/node.js +8 -0
- package/dist/render/png.d.ts +11 -0
- package/dist/render/png.js +29 -0
- package/dist/render/sequence-svg.d.ts +28 -0
- package/dist/render/sequence-svg.js +98 -0
- package/dist/render/sequence.d.ts +103 -0
- package/dist/render/sequence.js +142 -0
- package/dist/render/svg.d.ts +23 -0
- package/dist/render/svg.js +159 -0
- package/dist/render/teams.d.ts +12 -0
- package/dist/render/teams.js +31 -0
- package/dist/render/text.d.ts +13 -0
- package/dist/render/text.js +27 -0
- package/dist/schema/adr.d.ts +36 -0
- package/dist/schema/adr.js +27 -0
- package/dist/schema/bundle.d.ts +726 -0
- package/dist/schema/bundle.js +171 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +4 -0
- package/dist/schema/json-schema.d.ts +8 -0
- package/dist/schema/json-schema.js +19 -0
- package/dist/schema/workspace.d.ts +1066 -0
- package/dist/schema/workspace.js +271 -0
- package/dist/viewer/assets/index-BwUCSYuf.js +113 -0
- package/dist/viewer/assets/index-DvKgCpBr.css +1 -0
- package/dist/viewer/assets/index_bg-Blvrv-U2.wasm +0 -0
- package/dist/viewer/assets/index_bg-D3t31u3-.js +1 -0
- package/dist/viewer/assets/layout.worker-Bg-OaLVN.js +26 -0
- package/dist/viewer/assets/overpass-latin-QyaMbcmi.woff2 +0 -0
- package/dist/viewer/assets/overpass-latin-ext-DSRhPfzW.woff2 +0 -0
- package/dist/viewer/assets/overpass-mono-latin-BTquVRaO.woff2 +0 -0
- package/dist/viewer/assets/overpass-mono-latin-ext-D47EiU4_.woff2 +0 -0
- package/dist/viewer/assets/png-D1zzLB1s.js +1 -0
- package/dist/viewer/assets/svg-Cw4FMsm3.js +2 -0
- package/dist/viewer/favicon.svg +1 -0
- package/dist/viewer/index.html +53 -0
- package/dist/writer/adrs.d.ts +21 -0
- package/dist/writer/adrs.js +72 -0
- package/dist/writer/deployments.d.ts +51 -0
- package/dist/writer/deployments.js +145 -0
- package/dist/writer/diff.d.ts +6 -0
- package/dist/writer/diff.js +77 -0
- package/dist/writer/document.d.ts +25 -0
- package/dist/writer/document.js +79 -0
- package/dist/writer/edit.d.ts +78 -0
- package/dist/writer/edit.js +63 -0
- package/dist/writer/index.d.ts +67 -0
- package/dist/writer/index.js +310 -0
- package/dist/writer/overlay.d.ts +7 -0
- package/dist/writer/overlay.js +26 -0
- package/dist/writer/views.d.ts +29 -0
- package/dist/writer/views.js +78 -0
- package/dist/writer/workspace.d.ts +25 -0
- package/dist/writer/workspace.js +56 -0
- package/guide/SKILL.md +36 -0
- package/guide/topics/add-service.md +30 -0
- package/guide/topics/bootstrap.md +28 -0
- package/guide/topics/change.md +32 -0
- package/guide/topics/deployments.md +36 -0
- package/guide/topics/dynamic-view.md +39 -0
- package/guide/topics/propose-adr.md +12 -0
- package/guide/topics/relationships.md +39 -0
- package/guide/topics/saved-view.md +36 -0
- package/package.json +60 -4
- package/schemas/adr.schema.json +82 -0
- package/schemas/model.schema.json +1381 -0
- package/schemas/project.schema.json +24 -0
- package/schemas/workspace.schema.json +72 -0
- package/README.md +0 -3
package/dist/cli/main.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { cp, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
|
|
4
|
+
import { basename, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { findWorkspaceRoot, load, nodeFileSystem, resolveDynamicView, resolveView, serializeBundle } from "../core/index.js";
|
|
8
|
+
import { directions, layoutView, renderSequenceSvg, renderSvg } from "../render/index.js";
|
|
9
|
+
import { renderPngInNode } from "../render/node.js";
|
|
10
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
11
|
+
import { gitHead, gitTopLevel } from "../git.js";
|
|
12
|
+
import { bundleSource, checkoutSource, createServer, DEFAULT_PORT, serveHttp } from "../mcp/index.js";
|
|
13
|
+
import { authoringGuide } from "../guide/index.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 { diff } from "../core/index.js";
|
|
18
|
+
import { bundleAt, buildHistory, DEFAULT_KEEP, defaultBaseBranch, history, previewSides, publishHistory, publishPreview, resolvePoint } from "../history/index.js";
|
|
19
|
+
import { SCHEMA_VERSION } from "../schema/bundle.js";
|
|
20
|
+
import { diffFormats, formatDiff } from "./diff-format.js";
|
|
21
|
+
/** Exit codes: 0 no errors, 1 errors found (or any warning with `--strict`), 2 could not run. */
|
|
22
|
+
const OK = 0;
|
|
23
|
+
const FOUND_ERRORS = 1;
|
|
24
|
+
const COULD_NOT_RUN = 2;
|
|
25
|
+
class UsageError extends Error {
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The prebuilt viewer, which `build --out` copies as is. The CLI runs from
|
|
29
|
+
* dist/cli/ when installed and from src/cli/ in this repo; both sit two
|
|
30
|
+
* levels below the package root, whose dist/viewer/ holds the viewer.
|
|
31
|
+
*/
|
|
32
|
+
const VIEWER_DIR = fileURLToPath(new URL("../../dist/viewer/", import.meta.url));
|
|
33
|
+
/** The package's own package.json, two levels up from dist/cli/ or src/cli/ like the viewer. */
|
|
34
|
+
const PACKAGE_JSON = fileURLToPath(new URL("../../package.json", import.meta.url));
|
|
35
|
+
const usage = `Usage:
|
|
36
|
+
archidocs version [--format text|json]
|
|
37
|
+
archidocs init [--skill [--workspace <dir>]]
|
|
38
|
+
archidocs guide [topic]
|
|
39
|
+
archidocs check [--format text|json|github] [--strict]
|
|
40
|
+
archidocs build [--out <dir>] [--bundle-only] [--keep <n|all>]
|
|
41
|
+
archidocs build --preview [--base <branch>] [--out <dir>]
|
|
42
|
+
archidocs dev [--workspace <dir>] [--port <n>] [--host <host>]
|
|
43
|
+
archidocs export <view-id> [--format svg|png] [--out <file>] [--direction TB|BT|LR|RL]
|
|
44
|
+
archidocs export --all-saved --out <dir> [--format svg|png] [--direction TB|BT|LR|RL]
|
|
45
|
+
archidocs diff <from> [<to>] [--format text|json|markdown]
|
|
46
|
+
archidocs history build [--since <ref|date>]
|
|
47
|
+
archidocs mcp [--workspace <dir> | --bundle <url|path>] [--viewer-url <url>]
|
|
48
|
+
[--http [--host <loopback>] [--port <n>] [--allow-writes]]
|
|
49
|
+
`;
|
|
50
|
+
async function main(argv) {
|
|
51
|
+
const [command, ...rest] = argv;
|
|
52
|
+
if (command === "init") {
|
|
53
|
+
const { values } = parseArgs({ args: rest, options: { skill: { type: "boolean", default: false }, workspace: { type: "string" } }, strict: true });
|
|
54
|
+
if (values.workspace !== undefined && !values.skill)
|
|
55
|
+
throw new UsageError("--workspace only applies with --skill; without it, init uses or creates this repo's Workspace.");
|
|
56
|
+
const cwd = await realpath(process.cwd());
|
|
57
|
+
const repoRoot = (await gitTopLevel(cwd)) ?? cwd;
|
|
58
|
+
const lines = await init({ repoRoot, cwd, skillOnly: values.skill, ...(values.workspace === undefined ? {} : { workspace: values.workspace }) });
|
|
59
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
60
|
+
return OK;
|
|
61
|
+
}
|
|
62
|
+
if (command === "version") {
|
|
63
|
+
const { values } = parseArgs({ args: rest, options: { format: { type: "string", default: "text" } }, strict: true });
|
|
64
|
+
if (values.format !== "text" && values.format !== "json")
|
|
65
|
+
throw new UsageError(`Unknown format "${values.format}"; use text or json.`);
|
|
66
|
+
const { version } = JSON.parse(await readFile(PACKAGE_JSON, "utf8"));
|
|
67
|
+
process.stdout.write(values.format === "json" ? JSON.stringify({ version, schemaVersion: SCHEMA_VERSION }) + "\n" : `archidocs ${version} (Bundle schemaVersion ${SCHEMA_VERSION})\n`);
|
|
68
|
+
return OK;
|
|
69
|
+
}
|
|
70
|
+
if (command === "guide") {
|
|
71
|
+
const { positionals } = parseArgs({ args: rest, options: {}, allowPositionals: true, strict: true });
|
|
72
|
+
if (positionals.length > 1)
|
|
73
|
+
throw new UsageError(`Give one topic at a time; got ${positionals.join(", ")}.`);
|
|
74
|
+
const guide = await authoringGuide(positionals[0]);
|
|
75
|
+
if (!guide.ok)
|
|
76
|
+
throw new UsageError(guide.message);
|
|
77
|
+
process.stdout.write(guide.text);
|
|
78
|
+
return OK;
|
|
79
|
+
}
|
|
80
|
+
if (command === "check") {
|
|
81
|
+
const { values } = parseArgs({
|
|
82
|
+
args: rest,
|
|
83
|
+
options: { format: { type: "string", default: "text" }, strict: { type: "boolean", default: false } },
|
|
84
|
+
strict: true,
|
|
85
|
+
});
|
|
86
|
+
const format = values.format;
|
|
87
|
+
if (!formats.includes(format))
|
|
88
|
+
throw new UsageError(`Unknown format "${values.format}"; use ${formats.join(", ")}.`);
|
|
89
|
+
const { issues } = await loadFromCwd();
|
|
90
|
+
process.stdout.write(formatIssues(issues, format, { color: useColor() }));
|
|
91
|
+
return exitCodeFor(issues, { strict: values.strict });
|
|
92
|
+
}
|
|
93
|
+
if (command === "build") {
|
|
94
|
+
const { values } = parseArgs({
|
|
95
|
+
args: rest,
|
|
96
|
+
options: {
|
|
97
|
+
"bundle-only": { type: "boolean" },
|
|
98
|
+
out: { type: "string", default: "dist" },
|
|
99
|
+
keep: { type: "string" },
|
|
100
|
+
preview: { type: "boolean", default: false },
|
|
101
|
+
base: { type: "string" },
|
|
102
|
+
},
|
|
103
|
+
strict: true,
|
|
104
|
+
});
|
|
105
|
+
if (values.preview && values.keep !== undefined)
|
|
106
|
+
throw new UsageError("--keep doesn't apply to --preview, whose site holds just the base and the PR head.");
|
|
107
|
+
if (values.preview && values["bundle-only"])
|
|
108
|
+
throw new UsageError("--bundle-only doesn't apply to --preview, which writes a site.");
|
|
109
|
+
if (values.base !== undefined && !values.preview)
|
|
110
|
+
throw new UsageError("--base only applies with --preview.");
|
|
111
|
+
const keep = values.keep === undefined ? DEFAULT_KEEP : values.keep === "all" ? "all" : Number(values.keep);
|
|
112
|
+
if (keep !== "all" && !(Number.isInteger(keep) && keep >= 0))
|
|
113
|
+
throw new UsageError(`--keep "${values.keep}" is not a count or all.`);
|
|
114
|
+
if (values["bundle-only"] && values.keep !== undefined)
|
|
115
|
+
throw new UsageError("--keep only applies to a site; --bundle-only writes no past Bundles.");
|
|
116
|
+
const { bundle, issues } = await loadFromCwd();
|
|
117
|
+
if (issues.some((i) => i.severity === "error")) {
|
|
118
|
+
process.stdout.write(formatText(issues, { color: useColor() }));
|
|
119
|
+
process.stderr.write(`Not writing the ${values["bundle-only"] ? "Bundle" : "site"}: the Workspace has errors.\n`);
|
|
120
|
+
return FOUND_ERRORS;
|
|
121
|
+
}
|
|
122
|
+
// A preview finds both sides before writing anything, so a missing base writes no site.
|
|
123
|
+
let preview;
|
|
124
|
+
if (values.preview) {
|
|
125
|
+
const h = await historyFromCwd();
|
|
126
|
+
preview = { h, sides: await previewSides(h, values.base ?? (await defaultBaseBranch(h.repoRoot))) };
|
|
127
|
+
}
|
|
128
|
+
const out = resolve(values.out);
|
|
129
|
+
if (!values["bundle-only"]) {
|
|
130
|
+
if (!existsSync(join(VIEWER_DIR, "index.html")))
|
|
131
|
+
throw new Error(`The viewer is not built (no ${VIEWER_DIR}); run \`pnpm build\` first.`);
|
|
132
|
+
await cp(VIEWER_DIR, out, { recursive: true });
|
|
133
|
+
// The viewer's exports name the Workspace as `archidocs export` does: by its repo's folder.
|
|
134
|
+
const root = await workspaceRoot(process.cwd());
|
|
135
|
+
await writeFile(join(out, "site.json"), JSON.stringify({ workspace: await workspaceName(root) }) + "\n");
|
|
136
|
+
}
|
|
137
|
+
await mkdir(out, { recursive: true });
|
|
138
|
+
await writeFile(join(out, "workspace.bundle.json"), serializeBundle(bundle));
|
|
139
|
+
if (preview) {
|
|
140
|
+
const { base, baseSha, headSha } = await publishPreview(preview.h, out, preview.sides, bundle);
|
|
141
|
+
process.stdout.write(`Wrote the preview site to ${values.out}: Compare origin/${base} (${baseSha.slice(0, 7)}) → PR (${headSha.slice(0, 7)})\n`);
|
|
142
|
+
return OK;
|
|
143
|
+
}
|
|
144
|
+
if (!values["bundle-only"])
|
|
145
|
+
await writeSiteHistory(out, keep);
|
|
146
|
+
process.stdout.write(values["bundle-only"] ? `Wrote ${join(values.out, "workspace.bundle.json")}\n` : `Wrote the site to ${values.out}\n`);
|
|
147
|
+
return OK;
|
|
148
|
+
}
|
|
149
|
+
if (command === "dev") {
|
|
150
|
+
const { values } = parseArgs({ args: rest, options: { port: { type: "string" }, host: { type: "string" }, workspace: { type: "string" } }, strict: true });
|
|
151
|
+
const port = values.port === undefined ? DEFAULT_DEV_PORT : Number(values.port);
|
|
152
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
153
|
+
throw new UsageError(`--port "${values.port}" is not a port.`);
|
|
154
|
+
if (!existsSync(join(VIEWER_DIR, "index.html")))
|
|
155
|
+
throw new Error(`The viewer is not built (no ${VIEWER_DIR}); run \`pnpm build\` first.`);
|
|
156
|
+
const root = await workspaceRoot(values.workspace === undefined ? process.cwd() : resolve(values.workspace));
|
|
157
|
+
const color = useColor();
|
|
158
|
+
const dev = await serveDev({
|
|
159
|
+
root,
|
|
160
|
+
viewerDir: VIEWER_DIR,
|
|
161
|
+
workspace: await workspaceName(root),
|
|
162
|
+
port,
|
|
163
|
+
...(values.host === undefined ? {} : { host: values.host }),
|
|
164
|
+
onLoad: ({ issues, kept, first }) => {
|
|
165
|
+
const shown = issues.filter((i) => i.severity === "error" || first);
|
|
166
|
+
if (shown.length > 0)
|
|
167
|
+
process.stdout.write(formatText(shown, { color }));
|
|
168
|
+
if (kept)
|
|
169
|
+
process.stderr.write("The Workspace has errors; still serving the last good Bundle.\n");
|
|
170
|
+
else if (!first)
|
|
171
|
+
process.stderr.write(`Reloaded the Workspace (${new Date().toLocaleTimeString()})\n`);
|
|
172
|
+
},
|
|
173
|
+
}).catch((e) => {
|
|
174
|
+
if (e.code === "EADDRINUSE")
|
|
175
|
+
throw new UsageError(`Port ${port} is in use; pick another with --port.`);
|
|
176
|
+
throw e;
|
|
177
|
+
});
|
|
178
|
+
process.stderr.write(`Archidocs dev server on ${dev.url} (watching ${root}; Ctrl+C to stop)\n`);
|
|
179
|
+
return OK;
|
|
180
|
+
}
|
|
181
|
+
if (command === "export") {
|
|
182
|
+
const { values, positionals } = parseArgs({
|
|
183
|
+
args: rest,
|
|
184
|
+
options: { format: { type: "string", default: "svg" }, out: { type: "string" }, direction: { type: "string" }, "all-saved": { type: "boolean", default: false } },
|
|
185
|
+
allowPositionals: true,
|
|
186
|
+
strict: true,
|
|
187
|
+
});
|
|
188
|
+
const allSaved = values["all-saved"];
|
|
189
|
+
const [viewId, ...extra] = positionals;
|
|
190
|
+
if (allSaved && viewId !== undefined)
|
|
191
|
+
throw new UsageError("Give a View or --all-saved, not both.");
|
|
192
|
+
if (allSaved && values.out === undefined)
|
|
193
|
+
throw new UsageError("--all-saved needs --out <dir> for the pictures.");
|
|
194
|
+
if (!allSaved && viewId === undefined)
|
|
195
|
+
throw new UsageError("Give the View to export, such as c1 or c2/<system>, or --all-saved.");
|
|
196
|
+
if (extra.length > 0)
|
|
197
|
+
throw new UsageError(`Export one View at a time; got ${positionals.join(", ")}.`);
|
|
198
|
+
const format = values.format;
|
|
199
|
+
if (format !== "svg" && format !== "png")
|
|
200
|
+
throw new UsageError(`Unknown format "${format}"; use svg or png.`);
|
|
201
|
+
const direction = values.direction;
|
|
202
|
+
if (direction !== undefined && !directions.includes(direction))
|
|
203
|
+
throw new UsageError(`Unknown direction "${direction}"; use ${directions.join(", ")}.`);
|
|
204
|
+
const root = await workspaceRoot(process.cwd());
|
|
205
|
+
const { bundle, issues } = await loadFromCwd();
|
|
206
|
+
if (issues.some((i) => i.severity === "error")) {
|
|
207
|
+
process.stdout.write(formatText(issues, { color: useColor() }));
|
|
208
|
+
process.stderr.write("Not exporting: the Workspace has errors.\n");
|
|
209
|
+
return FOUND_ERRORS;
|
|
210
|
+
}
|
|
211
|
+
const workspace = await workspaceName(root);
|
|
212
|
+
const fileName = (id) => `${id.replace(/[/:]/g, "-")}.${format}`;
|
|
213
|
+
/** Lays out and draws one View; `--direction` wins over a Saved View's own. */
|
|
214
|
+
const source = { workspace, commit: bundle.commit, date: bundle.builtAt };
|
|
215
|
+
const write = async (svg, out) => {
|
|
216
|
+
await writeFile(resolve(out), format === "svg" ? svg : await renderPngInNode(svg));
|
|
217
|
+
process.stdout.write(`Wrote ${out}\n`);
|
|
218
|
+
};
|
|
219
|
+
/** Lays out and draws one View: a Dynamic View as a sequence chart, any other as a diagram. */
|
|
220
|
+
const draw = async (view, out) => {
|
|
221
|
+
if (view.kind === "dynamic")
|
|
222
|
+
return write(renderSequenceSvg({ bundle, view, source }), out);
|
|
223
|
+
const chosen = direction ?? view.direction;
|
|
224
|
+
const layout = await layoutView(view, chosen === undefined ? {} : { direction: chosen });
|
|
225
|
+
await write(renderSvg({ bundle, view, layout, source }), out);
|
|
226
|
+
};
|
|
227
|
+
const resolveAny = (id) => resolveDynamicView(bundle, id) ?? resolveView(bundle, id);
|
|
228
|
+
if (allSaved) {
|
|
229
|
+
await mkdir(resolve(values.out), { recursive: true });
|
|
230
|
+
for (const saved of bundle.views) {
|
|
231
|
+
const view = resolveAny(saved.id);
|
|
232
|
+
if (view)
|
|
233
|
+
await draw(view, join(values.out, fileName(saved.id)));
|
|
234
|
+
}
|
|
235
|
+
return OK;
|
|
236
|
+
}
|
|
237
|
+
const view = resolveAny(viewId);
|
|
238
|
+
if (!view)
|
|
239
|
+
throw new UsageError(`Unknown View "${viewId}"; Views are c1, c2, c2/<system>, c3/<service with Components>, deployment/<environment> and Saved Views (project:view-id).`);
|
|
240
|
+
await draw(view, values.out ?? fileName(viewId));
|
|
241
|
+
return OK;
|
|
242
|
+
}
|
|
243
|
+
if (command === "diff") {
|
|
244
|
+
const { values, positionals } = parseArgs({ args: rest, options: { format: { type: "string", default: "text" } }, allowPositionals: true, strict: true });
|
|
245
|
+
const format = values.format;
|
|
246
|
+
if (!diffFormats.includes(format))
|
|
247
|
+
throw new UsageError(`Unknown format "${values.format}"; use ${diffFormats.join(", ")}.`);
|
|
248
|
+
const [fromPoint, toPoint, ...extra] = positionals;
|
|
249
|
+
if (fromPoint === undefined)
|
|
250
|
+
throw new UsageError("Give the point to diff from: a ref or a date.");
|
|
251
|
+
if (extra.length > 0)
|
|
252
|
+
throw new UsageError(`Give at most two points; got ${positionals.join(", ")}.`);
|
|
253
|
+
const h = await historyFromCwd();
|
|
254
|
+
/** A point's Bundle; with no point, the working tree's. */
|
|
255
|
+
const side = async (point) => {
|
|
256
|
+
if (point === undefined)
|
|
257
|
+
return [{ point: "working tree", commit: null }, (await loadFromCwd()).bundle];
|
|
258
|
+
const commit = await resolvePoint(h.repoRoot, point);
|
|
259
|
+
if (!commit)
|
|
260
|
+
throw new UsageError(`Unknown ref or date "${point}"; a date resolves to the last default-branch commit at or before it.`);
|
|
261
|
+
return [{ point, commit }, (await bundleAt(h, commit)).bundle];
|
|
262
|
+
};
|
|
263
|
+
const [from, before] = await side(fromPoint);
|
|
264
|
+
const [to, after] = await side(toPoint);
|
|
265
|
+
process.stdout.write(formatDiff(diff(before, after), from, to, format));
|
|
266
|
+
return OK;
|
|
267
|
+
}
|
|
268
|
+
if (command === "history") {
|
|
269
|
+
const [sub, ...args] = rest;
|
|
270
|
+
if (sub !== "build")
|
|
271
|
+
throw new UsageError(sub ? `Unknown history command "${sub}".` : "Give a history command: build.");
|
|
272
|
+
const { values } = parseArgs({ args, options: { since: { type: "string" } }, strict: true });
|
|
273
|
+
const h = await historyFromCwd();
|
|
274
|
+
const { revisions, built } = await buildHistory(h, values.since === undefined ? {} : { since: values.since });
|
|
275
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
276
|
+
process.stdout.write(`Built ${plural(built, "Revision")}; ${revisions - built} of ${revisions} already built.\n`);
|
|
277
|
+
return OK;
|
|
278
|
+
}
|
|
279
|
+
if (command === "mcp") {
|
|
280
|
+
const { values } = parseArgs({
|
|
281
|
+
args: rest,
|
|
282
|
+
options: {
|
|
283
|
+
workspace: { type: "string" },
|
|
284
|
+
bundle: { type: "string" },
|
|
285
|
+
"viewer-url": { type: "string" },
|
|
286
|
+
http: { type: "boolean", default: false },
|
|
287
|
+
host: { type: "string" },
|
|
288
|
+
port: { type: "string" },
|
|
289
|
+
"allow-writes": { type: "boolean", default: false },
|
|
290
|
+
},
|
|
291
|
+
strict: true,
|
|
292
|
+
});
|
|
293
|
+
const viewerUrl = values["viewer-url"];
|
|
294
|
+
if (viewerUrl !== undefined && !URL.canParse(viewerUrl))
|
|
295
|
+
throw new UsageError(`--viewer-url "${viewerUrl}" is not a URL.`);
|
|
296
|
+
if (values.workspace !== undefined && values.bundle !== undefined)
|
|
297
|
+
throw new UsageError("Give --workspace or --bundle, not both.");
|
|
298
|
+
if (!values.http && values["allow-writes"])
|
|
299
|
+
throw new UsageError("--allow-writes only applies with --http; over stdio a checkout already takes writes.");
|
|
300
|
+
if (!values.http && (values.host !== undefined || values.port !== undefined))
|
|
301
|
+
throw new UsageError("--host and --port only apply with --http.");
|
|
302
|
+
const port = values.port === undefined ? DEFAULT_PORT : Number(values.port);
|
|
303
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
304
|
+
throw new UsageError(`--port "${values.port}" is not a port.`);
|
|
305
|
+
const source = values.bundle !== undefined
|
|
306
|
+
? bundleSource({ location: values.bundle })
|
|
307
|
+
: checkoutSource({ root: await workspaceRoot(values.workspace === undefined ? process.cwd() : resolve(values.workspace)) });
|
|
308
|
+
const options = { source, ...(viewerUrl === undefined ? {} : { viewerUrl }) };
|
|
309
|
+
if (values.http) {
|
|
310
|
+
const http = await serveHttp({ ...options, port, allowWrites: values["allow-writes"], ...(values.host === undefined ? {} : { host: values.host }) });
|
|
311
|
+
process.stderr.write(`Archidocs MCP server on ${http.url} (writes ${values["allow-writes"] && source.writesAllowed ? "allowed" : "off"})\n`);
|
|
312
|
+
return OK;
|
|
313
|
+
}
|
|
314
|
+
// stdout carries the protocol; the server runs until the client closes stdin.
|
|
315
|
+
serveStdio(() => createServer(options));
|
|
316
|
+
return OK;
|
|
317
|
+
}
|
|
318
|
+
throw new UsageError(command ? `Unknown command "${command}".` : "No command given.");
|
|
319
|
+
}
|
|
320
|
+
/** Colour only on a terminal; `NO_COLOR` turns it off and `FORCE_COLOR` on. */
|
|
321
|
+
function useColor() {
|
|
322
|
+
const { NO_COLOR, FORCE_COLOR } = process.env;
|
|
323
|
+
if (NO_COLOR)
|
|
324
|
+
return false;
|
|
325
|
+
if (FORCE_COLOR !== undefined)
|
|
326
|
+
return FORCE_COLOR !== "0";
|
|
327
|
+
return process.stdout.isTTY === true;
|
|
328
|
+
}
|
|
329
|
+
/** How a picture's source line names the Workspace: its git repo's folder, else the Workspace root's. */
|
|
330
|
+
async function workspaceName(root) {
|
|
331
|
+
return basename((await gitTopLevel(root)) ?? root);
|
|
332
|
+
}
|
|
333
|
+
async function workspaceRoot(start) {
|
|
334
|
+
const root = await findWorkspaceRoot(nodeFileSystem(), start);
|
|
335
|
+
if (!root)
|
|
336
|
+
throw new UsageError("No workspace.yaml found in this folder, its archidocs/ folder, or any folder above.");
|
|
337
|
+
return root;
|
|
338
|
+
}
|
|
339
|
+
/** The history of the Workspace found from the current folder; it must be in a git repo. */
|
|
340
|
+
async function historyFromCwd() {
|
|
341
|
+
const root = await workspaceRoot(process.cwd());
|
|
342
|
+
const repoRoot = await gitTopLevel(root);
|
|
343
|
+
if (!repoRoot)
|
|
344
|
+
throw new UsageError("History needs the Workspace in a git repository.");
|
|
345
|
+
return history(repoRoot, await realpath(root));
|
|
346
|
+
}
|
|
347
|
+
/** The site's past Bundles and Revision index; outside git, an empty index, so the viewer knows there is no history. */
|
|
348
|
+
async function writeSiteHistory(out, keep) {
|
|
349
|
+
const root = await workspaceRoot(process.cwd());
|
|
350
|
+
const repoRoot = await gitTopLevel(root);
|
|
351
|
+
if (repoRoot)
|
|
352
|
+
await publishHistory(history(repoRoot, await realpath(root)), out, { keep });
|
|
353
|
+
else {
|
|
354
|
+
await mkdir(join(out, "bundles"), { recursive: true });
|
|
355
|
+
await writeFile(join(out, "bundles", "index.json"), JSON.stringify({ schemaVersion: SCHEMA_VERSION, revisions: [] }, null, 2) + "\n");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async function loadFromCwd() {
|
|
359
|
+
const root = await workspaceRoot(process.cwd());
|
|
360
|
+
const { commit, builtAt } = await gitHead(root);
|
|
361
|
+
return load({ fs: nodeFileSystem(), root, commit, builtAt });
|
|
362
|
+
}
|
|
363
|
+
main(process.argv.slice(2)).then((code) => {
|
|
364
|
+
process.exitCode = code;
|
|
365
|
+
}, (error) => {
|
|
366
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
367
|
+
process.stderr.write(`archidocs: ${message}\n`);
|
|
368
|
+
if (error instanceof UsageError || error.code?.startsWith("ERR_PARSE_ARGS"))
|
|
369
|
+
process.stderr.write(usage);
|
|
370
|
+
process.exitCode = COULD_NOT_RUN;
|
|
371
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AdrDecl, Project } from "./model.ts";
|
|
2
|
+
/** The file a Project's ADR template lives in, inside its `adr/` folder; it is not an ADR. */
|
|
3
|
+
export declare const PROJECT_TEMPLATE = "template.md";
|
|
4
|
+
/** The Workspace's ADR template, beside `workspace.yaml`. */
|
|
5
|
+
export declare const WORKSPACE_TEMPLATE = "adr-template.md";
|
|
6
|
+
/** Splits markdown into its frontmatter YAML (between `---` lines at the top) and the rest. */
|
|
7
|
+
export declare function splitFrontmatter(text: string): {
|
|
8
|
+
yaml?: string;
|
|
9
|
+
body: string;
|
|
10
|
+
bodyLine: number;
|
|
11
|
+
};
|
|
12
|
+
/** Reads one ADR file: its number, frontmatter and title. */
|
|
13
|
+
export declare function readAdr(text: string, at: {
|
|
14
|
+
project: Project;
|
|
15
|
+
path: string;
|
|
16
|
+
filename: string;
|
|
17
|
+
}): AdrDecl;
|
|
18
|
+
/** An ADR reference written in `project`, qualified as `project:NNNN`; undefined when malformed or the Project has no id. */
|
|
19
|
+
export declare function qualifyAdr(ref: unknown, project: Project): string | undefined;
|
|
20
|
+
/** The default template: MADR minimal. */
|
|
21
|
+
export declare const MADR_MINIMAL = "---\nstatus: proposed\ndate: {{date}}\n---\n\n# {{title}}\n\n## Context and Problem Statement\n\n{Describe the context and problem statement in two or three sentences.}\n\n## Considered Options\n\n* {title of option 1}\n* {title of option 2}\n\n## Decision Outcome\n\nChosen option: \"{title of option 1}\", because {justification}.\n\n### Consequences\n\n* Good, because {positive consequence}\n* Bad, because {negative consequence}\n";
|
|
22
|
+
/** Fills a template's `{{title}}`, `{{date}}`, `{{elements}}` and `{{views}}`; lists are comma-separated. */
|
|
23
|
+
export declare function fillTemplate(template: string, values: {
|
|
24
|
+
title: string;
|
|
25
|
+
date: string;
|
|
26
|
+
elements: readonly string[];
|
|
27
|
+
views: readonly string[];
|
|
28
|
+
}): string;
|
package/dist/core/adr.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ADR_FILENAME, AdrRef } from "../schema/adr.js";
|
|
2
|
+
import { parseYaml } from "./yaml.js";
|
|
3
|
+
/** The file a Project's ADR template lives in, inside its `adr/` folder; it is not an ADR. */
|
|
4
|
+
export const PROJECT_TEMPLATE = "template.md";
|
|
5
|
+
/** The Workspace's ADR template, beside `workspace.yaml`. */
|
|
6
|
+
export const WORKSPACE_TEMPLATE = "adr-template.md";
|
|
7
|
+
/** Splits markdown into its frontmatter YAML (between `---` lines at the top) and the rest. */
|
|
8
|
+
export function splitFrontmatter(text) {
|
|
9
|
+
const lines = text.split(/\r?\n/);
|
|
10
|
+
if (lines[0]?.trim() !== "---")
|
|
11
|
+
return { body: text, bodyLine: 1 };
|
|
12
|
+
const end = lines.findIndex((l, i) => i > 0 && (l.trim() === "---" || l.trim() === "..."));
|
|
13
|
+
if (end === -1)
|
|
14
|
+
return { body: text, bodyLine: 1 };
|
|
15
|
+
let start = end + 1;
|
|
16
|
+
while (start < lines.length - 1 && lines[start].trim() === "")
|
|
17
|
+
start++;
|
|
18
|
+
return { yaml: lines.slice(1, end).join("\n") + "\n", body: lines.slice(start).join("\n"), bodyLine: start + 1 };
|
|
19
|
+
}
|
|
20
|
+
/** The first `# ` heading outside a fenced code block, with its 1-based line within `body`. */
|
|
21
|
+
function firstHeading(body) {
|
|
22
|
+
let fenced = false;
|
|
23
|
+
for (const [i, line] of body.split(/\r?\n/).entries()) {
|
|
24
|
+
if (/^\s*(```|~~~)/.test(line))
|
|
25
|
+
fenced = !fenced;
|
|
26
|
+
const m = !fenced && /^# +(.*\S)\s*$/.exec(line);
|
|
27
|
+
if (m)
|
|
28
|
+
return { text: m[1], line: i + 1 };
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Reads one ADR file: its number, frontmatter and title. */
|
|
33
|
+
export function readAdr(text, at) {
|
|
34
|
+
const { yaml, body, bodyLine } = splitFrontmatter(text);
|
|
35
|
+
const frontmatter = yaml === undefined ? undefined : parseYaml(yaml);
|
|
36
|
+
const data = frontmatter?.data;
|
|
37
|
+
const heading = firstHeading(body);
|
|
38
|
+
return {
|
|
39
|
+
...at,
|
|
40
|
+
...(ADR_FILENAME.test(at.filename) ? { number: at.filename.slice(0, 4) } : {}),
|
|
41
|
+
...(frontmatter ? { frontmatter } : {}),
|
|
42
|
+
lineOffset: 1,
|
|
43
|
+
data: data !== null && typeof data === "object" && !Array.isArray(data) ? data : {},
|
|
44
|
+
...(heading ? { title: { text: heading.text, line: heading.line + bodyLine - 1 } } : {}),
|
|
45
|
+
body,
|
|
46
|
+
bodyLine,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** An ADR reference written in `project`, qualified as `project:NNNN`; undefined when malformed or the Project has no id. */
|
|
50
|
+
export function qualifyAdr(ref, project) {
|
|
51
|
+
if (!AdrRef.safeParse(ref).success)
|
|
52
|
+
return undefined;
|
|
53
|
+
const text = ref;
|
|
54
|
+
if (text.includes(":"))
|
|
55
|
+
return text;
|
|
56
|
+
return project.id === undefined ? undefined : `${project.id}:${text}`;
|
|
57
|
+
}
|
|
58
|
+
/** The default template: MADR minimal. */
|
|
59
|
+
export const MADR_MINIMAL = `---
|
|
60
|
+
status: proposed
|
|
61
|
+
date: {{date}}
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
# {{title}}
|
|
65
|
+
|
|
66
|
+
## Context and Problem Statement
|
|
67
|
+
|
|
68
|
+
{Describe the context and problem statement in two or three sentences.}
|
|
69
|
+
|
|
70
|
+
## Considered Options
|
|
71
|
+
|
|
72
|
+
* {title of option 1}
|
|
73
|
+
* {title of option 2}
|
|
74
|
+
|
|
75
|
+
## Decision Outcome
|
|
76
|
+
|
|
77
|
+
Chosen option: "{title of option 1}", because {justification}.
|
|
78
|
+
|
|
79
|
+
### Consequences
|
|
80
|
+
|
|
81
|
+
* Good, because {positive consequence}
|
|
82
|
+
* Bad, because {negative consequence}
|
|
83
|
+
`;
|
|
84
|
+
/** Fills a template's `{{title}}`, `{{date}}`, `{{elements}}` and `{{views}}`; lists are comma-separated. */
|
|
85
|
+
export function fillTemplate(template, values) {
|
|
86
|
+
const fill = { title: values.title, date: values.date, elements: values.elements.join(", "), views: values.views.join(", ") };
|
|
87
|
+
return template.replace(/\{\{\s*(title|date|elements|views)\s*\}\}/g, (_, key) => fill[key]);
|
|
88
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Bundle, BundleAdr } from "../schema/bundle.ts";
|
|
2
|
+
import type { LoadedWorkspace } from "./model.ts";
|
|
3
|
+
/** The Bundle's `adrs` slot, by id, with `supersededBy` and the effective status derived from accepted ADRs. */
|
|
4
|
+
export declare function bundleAdrs(ws: LoadedWorkspace): BundleAdr[];
|
|
5
|
+
export interface ListAdrsOptions {
|
|
6
|
+
/** Only ADRs that link this Element or Deployment Target, or any of its descendants (not its ancestors). */
|
|
7
|
+
element?: string;
|
|
8
|
+
/** Only ADRs with this effective status. */
|
|
9
|
+
status?: BundleAdr["status"];
|
|
10
|
+
/** Only ADRs with this tag. */
|
|
11
|
+
tag?: string;
|
|
12
|
+
}
|
|
13
|
+
/** An ADR as `listAdrs` returns it; with `element`, `matchedVia` holds the linked ids that matched it. */
|
|
14
|
+
export type ListedAdr = BundleAdr & {
|
|
15
|
+
matchedVia?: string[];
|
|
16
|
+
};
|
|
17
|
+
/** ADRs newest first, by `date`, then by number, then by id. */
|
|
18
|
+
export declare function listAdrs(bundle: Bundle, options?: ListAdrsOptions): ListedAdr[];
|
|
19
|
+
/** The ADRs linked to an Element or Target directly or through its descendants, as `listAdrs` gives them. */
|
|
20
|
+
export declare const adrsFor: (bundle: Bundle, id: string) => ListedAdr[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AdrFrontmatter } from "../schema/adr.js";
|
|
2
|
+
import { qualifyAdr } from "./adr.js";
|
|
3
|
+
import { qualify } from "./refs.js";
|
|
4
|
+
/** ADRs that make it into the Bundle: a usable Project, an `NNNN-slug.md` name, valid frontmatter, and the first file with its number. */
|
|
5
|
+
function bundledAdrs(ws) {
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
return ws.adrs.flatMap((decl) => {
|
|
8
|
+
if (decl.project.id === undefined || decl.project.duplicateOf || decl.number === undefined || !decl.frontmatter)
|
|
9
|
+
return [];
|
|
10
|
+
const parsed = AdrFrontmatter.safeParse(decl.data);
|
|
11
|
+
const id = `${decl.project.id}:${decl.number}`;
|
|
12
|
+
if (!parsed.success || seen.has(id))
|
|
13
|
+
return [];
|
|
14
|
+
seen.add(id);
|
|
15
|
+
return [{ decl, id, frontmatter: parsed.data }];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** The Bundle's `adrs` slot, by id, with `supersededBy` and the effective status derived from accepted ADRs. */
|
|
19
|
+
export function bundleAdrs(ws) {
|
|
20
|
+
const adrs = bundledAdrs(ws).map(({ decl, id, frontmatter: f }) => {
|
|
21
|
+
const ref = (r) => qualify(r, decl.project) ?? r;
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
project: decl.project.id,
|
|
25
|
+
title: decl.title?.text ?? id,
|
|
26
|
+
status: f.status,
|
|
27
|
+
effectiveStatus: f.status,
|
|
28
|
+
date: f.date,
|
|
29
|
+
elements: (f.elements ?? []).map(ref),
|
|
30
|
+
views: (f.views ?? []).map(ref),
|
|
31
|
+
supersedes: (f.supersedes ?? []).map((r) => qualifyAdr(r, decl.project) ?? r),
|
|
32
|
+
supersededBy: [],
|
|
33
|
+
decisionMakers: f["decision-makers"] ?? [],
|
|
34
|
+
consulted: f.consulted ?? [],
|
|
35
|
+
informed: f.informed ?? [],
|
|
36
|
+
tags: f.tags ?? [],
|
|
37
|
+
body: decl.body,
|
|
38
|
+
source: { file: decl.path, line: 1 },
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const byId = new Map(adrs.map((a) => [a.id, a]));
|
|
42
|
+
for (const a of adrs) {
|
|
43
|
+
if (a.status !== "accepted")
|
|
44
|
+
continue;
|
|
45
|
+
for (const old of a.supersedes)
|
|
46
|
+
byId.get(old)?.supersededBy.push(a.id);
|
|
47
|
+
}
|
|
48
|
+
for (const a of adrs) {
|
|
49
|
+
a.supersededBy.sort(cmp);
|
|
50
|
+
if (a.supersededBy.length > 0)
|
|
51
|
+
a.effectiveStatus = "superseded";
|
|
52
|
+
}
|
|
53
|
+
return adrs.sort((a, b) => cmp(a.id, b.id));
|
|
54
|
+
}
|
|
55
|
+
/** ADRs newest first, by `date`, then by number, then by id. */
|
|
56
|
+
export function listAdrs(bundle, options = {}) {
|
|
57
|
+
const covered = options.element === undefined ? undefined : subtree(bundle, options.element);
|
|
58
|
+
return bundle.adrs
|
|
59
|
+
.flatMap((a) => {
|
|
60
|
+
if (options.status !== undefined && a.effectiveStatus !== options.status)
|
|
61
|
+
return [];
|
|
62
|
+
if (options.tag !== undefined && !a.tags.includes(options.tag))
|
|
63
|
+
return [];
|
|
64
|
+
if (!covered)
|
|
65
|
+
return [a];
|
|
66
|
+
const matchedVia = a.elements.filter((id) => covered.has(id));
|
|
67
|
+
return matchedVia.length ? [{ ...a, matchedVia }] : [];
|
|
68
|
+
})
|
|
69
|
+
.sort((a, b) => cmp(b.date, a.date) || cmp(numberOf(b), numberOf(a)) || cmp(a.id, b.id));
|
|
70
|
+
}
|
|
71
|
+
/** The ADRs linked to an Element or Target directly or through its descendants, as `listAdrs` gives them. */
|
|
72
|
+
export const adrsFor = (bundle, id) => listAdrs(bundle, { element: id });
|
|
73
|
+
/** `id` and every Element or Target nested under it. */
|
|
74
|
+
function subtree(bundle, id) {
|
|
75
|
+
const items = [...bundle.elements, ...bundle.targets];
|
|
76
|
+
const out = new Set([id]);
|
|
77
|
+
for (let grew = true; grew;) {
|
|
78
|
+
grew = false;
|
|
79
|
+
for (const i of items)
|
|
80
|
+
if (i.parent !== null && out.has(i.parent) && !out.has(i.id))
|
|
81
|
+
grew = Boolean(out.add(i.id));
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
const numberOf = (a) => a.id.slice(a.id.indexOf(":") + 1);
|
|
86
|
+
const cmp = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type RuleDefinition } from "./rules.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The rule catalogue as Markdown, generated from the rule registry: each
|
|
4
|
+
* rule's id, severity, meaning, a failing example and the fix. Examples show
|
|
5
|
+
* only the files the fix changes; paths are relative to the Workspace root.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ruleCatalogue(rules?: readonly RuleDefinition[]): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { rules as registry } from "./rules.js";
|
|
2
|
+
/**
|
|
3
|
+
* The rule catalogue as Markdown, generated from the rule registry: each
|
|
4
|
+
* rule's id, severity, meaning, a failing example and the fix. Examples show
|
|
5
|
+
* only the files the fix changes; paths are relative to the Workspace root.
|
|
6
|
+
*/
|
|
7
|
+
export function ruleCatalogue(rules = registry) {
|
|
8
|
+
const out = [
|
|
9
|
+
"# Check rules",
|
|
10
|
+
"",
|
|
11
|
+
"<!-- Generated from the rule registry in src/core/rules.ts by `pnpm rules:catalogue`. Do not edit by hand. -->",
|
|
12
|
+
"",
|
|
13
|
+
"`archidocs check` reports each issue with one of these rule ids. Errors fail the check; warnings fail it only with `--strict`.",
|
|
14
|
+
"",
|
|
15
|
+
"| Rule | Severity | Meaning |",
|
|
16
|
+
"| --- | --- | --- |",
|
|
17
|
+
...rules.map((r) => `| [\`${r.id}\`](#${r.id}) | ${r.severity} | ${r.summary.replace(/\|/g, "\\|")} |`),
|
|
18
|
+
];
|
|
19
|
+
for (const r of rules) {
|
|
20
|
+
const { failing, passing } = r.example;
|
|
21
|
+
out.push("", `## \`${r.id}\``, "", `**Severity:** ${r.severity}`, "", r.summary, "", "**Failing example**", "");
|
|
22
|
+
out.push(...changedFiles(failing, passing).flatMap((path) => fileBlock(path, failing[path])));
|
|
23
|
+
out.push(`**Fix:** ${r.fix}`, "", "**Fixed**", "");
|
|
24
|
+
out.push(...changedFiles(passing, failing).flatMap((path) => fileBlock(path, passing[path])), ...Object.keys(failing)
|
|
25
|
+
.filter((path) => !(path in passing))
|
|
26
|
+
.sort()
|
|
27
|
+
.flatMap((path) => [`\`${path}\`: removed.`, ""]));
|
|
28
|
+
}
|
|
29
|
+
return out.join("\n").replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
|
|
30
|
+
}
|
|
31
|
+
/** Paths in `files` whose text differs in (or is missing from) `other`. */
|
|
32
|
+
const changedFiles = (files, other) => Object.keys(files)
|
|
33
|
+
.filter((path) => files[path] !== other[path])
|
|
34
|
+
.sort();
|
|
35
|
+
const fileBlock = (path, text) => [`\`${path}\`:`, "", path.endsWith(".md") ? "````markdown" : "```yaml", text.trimEnd(), path.endsWith(".md") ? "````" : "```", ""];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Bundle } from "../schema/bundle.ts";
|
|
2
|
+
import { type ResolveOptions, type ResolvedView } from "./views.ts";
|
|
3
|
+
/** How Compare marks a node or edge of a View between two Bundles. */
|
|
4
|
+
export type CompareMark = "added" | "removed" | "changed" | "unchanged";
|
|
5
|
+
/**
|
|
6
|
+
* One Bundle holding everything either side holds, the later side's version
|
|
7
|
+
* where both do, so a View drawn from it keeps removed things in place.
|
|
8
|
+
* Relationships are matched by their whole content, so a changed one shows
|
|
9
|
+
* at both sides; each lands on the same edge.
|
|
10
|
+
*/
|
|
11
|
+
export declare function unionBundle(before: Bundle, after: Bundle): Bundle;
|
|
12
|
+
/**
|
|
13
|
+
* A View for Compare: laid out over the union of both sides, with every node
|
|
14
|
+
* and edge marked. A node or edge only the later side's View shows is
|
|
15
|
+
* added, one only the earlier side's shows is removed. One both show is
|
|
16
|
+
* changed when its Element changed, or for a collapsed box when anything
|
|
17
|
+
* inside it was added, removed or changed; an edge when its Relationships
|
|
18
|
+
* did. A View that exists at one side only is drawn from that side.
|
|
19
|
+
* Undefined when neither side has the View.
|
|
20
|
+
*/
|
|
21
|
+
export declare function compareView(before: Bundle, after: Bundle, id: string, options?: Pick<ResolveOptions, "expand">): ResolvedView | undefined;
|