codebase

tcmts.cli.test.e2e.contributions.codebase · #hoivbbnc · term · runs on the server

uses node:path

import { env } from "#codebase/tcmts/cli/test/e2e/contributions";
import { strip, tcmBin } from "#codebase/tcmts/cli/test/e2e/harness";
import { spawnSync } from "node:child_process";
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 run = (...args: string[]) => {
    const r = spawnSync(process.execPath, [tcmBin(), ...args], { cwd: dir, encoding: "utf8", env: env() });
    return { status: r.status, out: strip(r.stdout + r.stderr) };
  };
  const tcm = (...args: string[]) => {
    const r = run(...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);
  tcm("init");
  return { dir, run, tcm, write };
}

uses

used by