// THE MODULES' DOCS (release 39): umtool/docs/knobs.md's "Modules" section, // generated from each module's own `docs` -- so a module's knobs are written // once, beside its validator, and the page cannot drift from them. // // node umtool/report-to-video/modules/docs.mjs rewrite the section // node umtool/report-to-video/modules/docs.mjs --check exit 1 when it is stale // // The section stands between the two markers below; everything else in // knobs.md is hand-written and left as it is. import { readFileSync, writeFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { MODULES } from "./index.mjs"; export const DOCS_BEGIN = ""; export const DOCS_END = ""; /** knobs.md, beside this checkout's umtool. */ export const KNOBS_MD = fileURLToPath(new URL("../../docs/knobs.md", import.meta.url)); const KIND_WORDS = { "overlay-whole": "a page over the whole cut", "overlay-window": "pages at their own seconds", segment: "a segment cut into the timeline", input: "a filter on the footage", post: "after the master", part: "drawn in the deck's page", }; const cell = (s) => String(s).replace(/\|/g, "\\|").replace(/\n/g, " "); /** The order the section reads in: the deck and its parts, then by z. */ function ordered() { const shell = MODULES.find((m) => m.id === "shell"); const parts = MODULES.filter((m) => m.host === "shell"); const rest = MODULES.filter((m) => m !== shell && m.host !== "shell" && m.docs); return [shell, ...parts, ...rest].filter((m) => m?.docs); } /** The section's markdown, markers included. */ export function modulesMarkdown() { const out = [ DOCS_BEGIN, "## Modules", "", "A report video's chrome is a set of MODULES (`umtool/report-to-video/modules/`), each with its home in the manifest, its", "defaults, its validator and its frame-key rules; the build, the composer and umtool loop over the one registry", "(`modules/index.mjs`). The deck's parts are drawn in its one page; every other module is its own layer, segment or", "filter. A knob absent is its default, and a module whose knobs are all absent draws what it always drew.", "", "| Module | What it is | Its home |", "|---|---|---|", ...ordered().map((m) => `| [${cell(m.docs.heading)}](#${anchor(m.docs.heading)}) \`${m.id}\` | ${cell(m.summary ?? "")} ${KIND_WORDS[m.kind] ? `(${KIND_WORDS[m.kind]})` : ""} | ${m.configKey ? `\`${m.configKey}\`` : "--"} |`), "", "### Play the cut and the live preview", "", "A module's HyperFrames page IS its live preview: the build captures it frame by frame; Play the cut and the clip", "editor's live preview load the same page (composed with `preview: true`, no render) in an iframe at the module's", "region and seek it by message. A module joins them by declaring `play: { clock: \"cut\", ready: \":ready\" }`", "in its definition (`modules/contract.mjs`): its page takes `deck:seek` in the cut's seconds and posts `ready` once", "it can be seeked. `POST /api/report/chrome/preview` returns every such module the cut draws (its own `on`, the", "build's predicate) as `layers: [{id, z, region, clock, ready, geometry, src | windows}]`; the client lays them", "by z over the deck's page, a whole-cut page for the whole cut, a window module's page only inside each window.", "", `Declaring \`play\`: ${MODULES.filter((m) => m.play).map((m) => `\`${m.id}\``).join(", ")}.`, "", "Still drawn by their own paths (the response's `src`, `feed`, `posts`, `stamp` and `finale` keys), and what moving", "each onto `play` needs: the deck (`shell`) -- its typed words patched in live (`deck:text`) and the `deck:ready`", "handshake DeckFrame waits on; the feed -- its footage box and per-segment framing boxes (`feed.footage`,", "`feed.boxes`) that move the picture; the popup posts -- one page per window composed with the posts draft, and", "`posts:ready`; the stamps -- their geometry follows the feed layout (`stampGeometry`) and the HUD reads", "`stampAt`; the finale -- its window is the schedule's `finale` (not a region's) and it is laid over the deck.", "Each is a `play` declaration plus moving its consumers (the live-preview and Play specs' testids) to the layer.", "", ]; for (const m of ordered()) { out.push(`### ${m.docs.heading}`, ""); if (m.docs.intro) out.push(m.docs.intro, ""); if (m.docs.rows?.length) { out.push("| Knob | Range ยท default | From a terminal |", "|---|---|---|"); for (const [knob, range, terminal] of m.docs.rows) out.push(`| ${knob} | ${range} | ${terminal} |`); out.push(""); } if (m.docs.after) out.push(m.docs.after, ""); } out.push(DOCS_END); return out.join("\n"); } /** A heading's GitHub anchor. */ function anchor(h) { return h.toLowerCase().replace(/[^a-z0-9 -]/g, "").trim().replace(/ /g, "-"); } /** knobs.md with its Modules section replaced (or appended, the first time). */ export function withModulesSection(text) { const section = modulesMarkdown(); const a = text.indexOf(DOCS_BEGIN); const b = text.indexOf(DOCS_END); if (a >= 0 && b > a) return text.slice(0, a) + section + text.slice(b + DOCS_END.length); return `${text.replace(/\s*$/, "")}\n\n${section}\n`; } if (import.meta.url === `file://${process.argv[1]}`) { const text = readFileSync(KNOBS_MD, "utf8"); const next = withModulesSection(text); if (process.argv.includes("--check")) { if (next !== text) { console.error("umtool/docs/knobs.md's Modules section is stale: run node umtool/report-to-video/modules/docs.mjs"); process.exit(1); } console.log("knobs.md's Modules section is current"); } else if (next !== text) { writeFileSync(KNOBS_MD, next); console.log("knobs.md: the Modules section rewritten"); } else console.log("knobs.md: the Modules section is current"); }