keptCheck
uses Buffer
A file kept as written, being edited at abs (holding text) to go back to name, checked: what updating would
do, it being new there, an update, or as it is.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { fileContent } from "#codebase/tcmts/cli/files"; import type { ScratchCheck } from "#codebase/tcmts/studio"; export function keptCheck(cb: Codebase, name: string, abs: string, text: string): ScratchCheck { const ns = name.slice(0, Math.max(0, name.lastIndexOf("."))); const h = cb.lookup(name).find((x) => cb.store.getDef(x)?.kind === "file"); const rec = h ? cb.store.getDef(h) : undefined; // (a Markdown file's first line says where it goes: it isn't in what's kept) const body = abs.endsWith(".md") ? text.replace(/^<!-- tcm: path \S+ -->\n?/, "") : text; const status = !rec ? "new" : fileContent(cb, rec, ns).equals(Buffer.from(body)) ? "identical" : "update"; return { problems: [], rows: [{ path: name, status, kind: "file" }], ...(ns ? { namespace: ns } : {}), }; }