// `umtool help` AND docs/cli.md's COMMANDS, GENERATED (lane palette, L8a) // from the registry: the verb rows (verbs.mjs) and their prose (groups.mjs). // // node umtool/lib/cli/docs.mjs rewrite docs/cli.md's generated section // node umtool/lib/cli/docs.mjs --check exit 1 when it is stale (verbs.test.mjs says the same) // // The section stands between the two markers below -- the Commands table (each // command's rows, as groups.mjs gives them) and "Every verb" (every row of the // registry, its arguments and whether ⌘K offers it as a form). Everything else // in cli.md is hand-written and left as it is. import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { GROUPS } from "./groups.mjs"; import { VERBS, commandOf } from "./verbs.mjs"; import { synopsis } from "./argv.mjs"; export const DOCS_BEGIN = ""; export const DOCS_END = ""; /** docs/cli.md, beside this checkout's umtool. */ export const CLI_MD = fileURLToPath(new URL("../../docs/cli.md", import.meta.url)); /** * What `umtool help` prints. * @param {{ reportsRoot: string, chainSteps?: string, draftAllSteps?: string }} fill */ export function usageText({ reportsRoot, chainSteps = "", draftAllSteps = "" }) { const lines = GROUPS.flatMap((g) => g.usage).map((l) => l.replace("{chainSteps}", chainSteps).replace("{draftAllSteps}", draftAllSteps)); return [ "umtool — the project tree, from a terminal", "", ...lines, "", `reading ${reportsRoot} (set REPORTS_DIR to move it)`, "", "Run `check` before every build. It is what catches a manifest with no", "siteOrigin — the defect that shipped 19 QR codes reading `undefined/?v=…`.", "", "Every verb, its arguments and its ⌘K form: umtool/docs/cli.md (\"Every verb\").", ].join("\n"); } const code = (s) => `\`${String(s).replace(/\|/g, "\\|")}\``; const cell = (s) => String(s).replace(/\|/g, "\\|").replace(/\n/g, " "); /** The generated section, markers included. */ export function verbsMarkdown() { const out = [DOCS_BEGIN, "## Commands", "", "| | |", "|---|---|"]; for (const g of GROUPS) for (const [syntax, text] of g.docs) out.push(`| ${syntax} | ${text} |`); out.push( "", "### Every verb", "", "Every verb `umtool` dispatches, a sub-verb its own row (`umtool/lib/cli/verbs.mjs`, the registry the ⌘K palette's", "**Commands** are built from). **form**: the palette offers it as a form (its arguments below, the page's project", "and selection filled in; **Copy as CLI**; Run is `POST /api/cli`, which runs only these). **queued**: Run adds it to", "the durable queue (it renders, or holds the heavy slot). Otherwise why it has none. *draft*: it writes the working", "draft (the project's manifest); *project*: a project's other files, or reads; *corpus*: no one project.", "", "| Verb | What it does | ⌘K |", "|---|---|---|", ); for (const r of VERBS) { const ui = r.ui === "form" ? `form${r.queue ? " · queued" : ""} · *${r.target}*` : `none: ${cell(r.reason)}`; out.push(`| ${code(r.ui === "form" ? synopsis(r) : r.verb)} | ${cell(r.summary)} | ${ui} |`); } out.push(DOCS_END); return out.join("\n"); } /** * cli.md with its section replaced: between the markers when they are there, * else from `## Commands` to the end of its table (the first run). */ export function withVerbsSection(text) { const md = verbsMarkdown(); const a = text.indexOf(DOCS_BEGIN); const b = text.indexOf(DOCS_END); if (a >= 0 && b > a) return text.slice(0, a) + md + text.slice(b + DOCS_END.length); const lines = text.split("\n"); const h = lines.indexOf("## Commands"); if (h < 0) throw new Error("cli.md has neither the markers nor a `## Commands` heading"); let end = h + 1; for (let i = h + 1; i < lines.length && !lines[i].startsWith("## "); i += 1) if (lines[i].startsWith("|")) end = i; return [...lines.slice(0, h), md, ...lines.slice(end + 1)].join("\n"); } /** The top-level commands the registry has rows for. */ export const registryCommands = () => [...new Set(VERBS.map((r) => commandOf(r.verb)))]; if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { const text = readFileSync(/* turbopackIgnore: true */ CLI_MD, "utf8"); const next = withVerbsSection(text); if (process.argv.includes("--check")) { if (next !== text) { console.error("umtool/docs/cli.md is stale: run `node umtool/lib/cli/docs.mjs` and commit it"); process.exit(1); } console.log("umtool/docs/cli.md is current"); } else if (next !== text) { writeFileSync(/* turbopackIgnore: true */ CLI_MD, next); console.log("umtool/docs/cli.md rewritten"); } else { console.log("umtool/docs/cli.md is current"); } }