printBuilds
uses tcmts.cli.style.dim, which uses node:util
tcm builds: the builds kept in root, newest first, each with its name (what --build takes), the history
entry it was made from (with cb, the codebase's: how far back on this branch, and its command), when, what
changed in it (the entries since the build before it in history), and its tcm.js.
import { keptBuilds } from "#codebase/tcmts/cli/builds"; import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { cyan, dim, yellow } from "#codebase/tcmts/cli/style"; import { shortHash } from "#codebase/tcmts/core/hash"; import { entryTitle } from "#codebase/tcmts/store"; export function printBuilds(root: string | undefined, cb: Codebase | undefined): void { if (!root) { console.log( dim( "no builds are kept here: TCM_BUILDS names the directory they're in (in tcm's repository, dist/, where `pnpm verify` keeps them)", ), ); return; } const builds = keptBuilds(root); if (!builds.length) { console.log(dim(`no builds in ${root}`)); return; } const log = cb ? cb.store.causalLog(10_000) : []; const back = new Map(log.map((c, i) => [c.hash, i])); const short = (s: string) => (s.length > 70 ? `${s.slice(0, 69)}…` : s); const width = Math.max(...builds.map((b) => b.name.length)); const indent = " ".repeat(width + 2); for (const b of builds) { const n = b.head === undefined ? undefined : back.get(b.head); const entry = b.head === undefined ? undefined : cb?.store.causal(b.head); const from = b.head === undefined ? dim("(it doesn't say what it was made from)") : n !== undefined ? `${dim(`${n} back:`)} ${short(log[n]!.command)}` : entry ? `${short(entry.command)} ${dim("(not on this branch)")}` : cb ? dim("(not in this codebase's history)") : ""; console.log( `${cyan(b.name.padEnd(width))} ${yellow(b.head ? shortHash(b.head) : "#?")} ${dim(`${b.how}${b.when ? ` ${b.when}` : ""}`)} ${from}`, ); // what changed in it: the entries since the build made from the entry before its, on this branch if (n !== undefined) { const before = builds .map((o) => (o.head === undefined ? undefined : back.get(o.head))) .filter((i): i is number => i !== undefined && i > n) .sort((x, y) => x - y)[0]; const since = before === undefined ? [] : log.slice(n, before); if (since.length) console.log( `${indent}${dim(`since ${shortHash(log[before!]!.hash)}:`)} ${since .slice(0, 3) .map((c) => short(entryTitle(c))) .join("; ")}${since.length > 3 ? dim(`; and ${since.length - 3} more`) : ""}`, ); } console.log(`${indent}${dim(b.bin)}`); } console.log( dim( "\n`tcm --build <name> <command>` runs one (`tcm -C <dir> --build <name> …`, on a codebase made for a repro); `tcm test --bin tcm=<name>` runs the suites against it", ), ); }
uses
- tcmts.cli.builds.keptBuilds
- tcmts.cli.codebase.Codebase
- tcmts.cli.style.cyan
- tcmts.cli.style.dim
- tcmts.cli.style.yellow
- tcmts.core.hash.shortHash
- tcmts.store.entryTitle