codebase

tcmts.cli.test.e2e.history.codebase · #k7grxn4c · term · runs on the server

uses node:path

A new directory name in root, and ways to run tcm in it.

import { tcmIn } from "#codebase/tcmts/cli/test/e2e/harness";
import fs from "node:fs";
import path from "node:path";

export function codebase(root: string, name: string) {
  const dir = path.join(root, name);
  fs.mkdirSync(dir);
  const tcm = (...args: string[]) => {
    const r = tcmIn(dir, ...args);
    if (r.status !== 0) throw new Error(`tcm ${args.join(" ")} (in ${name}) exited ${r.status}:\n${r.out}`);
    return r.out;
  };
  const write = (text: string) => fs.writeFileSync(path.join(dir, "scratch.ts"), text);
  /** History entry hashes, newest first. */
  const entries = () => [...tcm("history", "100").matchAll(/^#([a-z2-7]{8}) /gm)].map((m) => m[1]!);
  return { dir, tcm, write, entries };
}

uses

used by