scratchText
uses tcmts.cli.files.fileContent, which uses Buffer
A definition as a scratch file holds it at name (tcm edit's text, without its namespace line; a file kept as
written: its content), using what it uses by its current name, or a replaced version by what replaced it: so each
side of a merge, and the base's, read as one another do. ns: the namespace of the file it's in, if not its own
(then it says where it goes).
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { fileContent } from "#codebase/tcmts/cli/files"; import { joinName } from "#codebase/tcmts/cli/mirror"; import type { DefRecord } from "#codebase/tcmts/core/types"; import { render } from "#codebase/tcmts/loader"; export function scratchText( cb: Codebase, rec: DefRecord, name: string, ns = name.slice(0, Math.max(0, name.lastIndexOf("."))), ): string { if (rec.kind === "file") return fileContent(cb, rec, ns).toString("utf8"); return render([rec], cb.source(), cb.lay, { style: "scratch", exportDeclarations: true, remap: (h) => cb.store.patched(h), annotate: (_h, declaredAs) => joinName(ns, declaredAs) !== name ? `// tcm: path ${name}` : undefined, }).text; }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.files.fileContent
- tcmts.cli.mirror.joinName
- tcmts.core.types.DefRecord
- tcmts.loader.render