buildRecord
uses node:fs
What a build's directory says it was made from: build.json (what tcm builds make writes: head, when), or what
pnpm verify leaves (verified.json's head; VERIFIED, "#
import type { TcmBuild } from "#codebase/tcmts/cli/builds"; import fs from "node:fs"; import path from "node:path"; export function buildRecord( dir: string, ): Pick<TcmBuild, "head" | "how" | "when" | "at"> | undefined { const read = (f: string) => { try { return fs.readFileSync(path.join(dir, f), "utf8"); } catch { return undefined; } }; const mtime = (f: string) => fs.statSync(path.join(dir, f)).mtimeMs; const made = read("build.json"); if (made !== undefined) { const r = JSON.parse(made) as { head?: string; when?: string }; return { head: r.head, when: r.when, how: "made", at: mtime("build.json") }; } const said = read("VERIFIED"); const json = read("verified.json"); if (said === undefined && json === undefined) return undefined; const m = /^#([a-z2-7]+), verified (.+)$/.exec(said?.trim() ?? ""); return { head: (json ? (JSON.parse(json) as { head?: string }).head : undefined) ?? m?.[1], when: m?.[2], how: "verified", at: mtime(said !== undefined ? "VERIFIED" : "verified.json"), }; }