keptFile
uses node:fs
The name the scratch file at abs goes back to, if it's a file kept as written being edited: a Markdown file's
first line (<!-- tcm: path a.b -->), or what the studio kept when it wrote it (keptInto).
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { keptInto } from "#codebase/tcmts/studio"; import fs from "node:fs"; export function keptFile(cb: Codebase, abs: string, text?: string): string | undefined { if (abs.endsWith(".md")) { const first = (text ?? (fs.existsSync(abs) ? fs.readFileSync(abs, "utf8") : "")).split( "\n", 1, )[0]!; const m = /^<!-- tcm: path (\S+) -->/.exec(first); if (m) return m[1]; } return keptInto(cb)[abs]; }