pruneKeptBuilds

tcmts.cli.builds.pruneKeptBuilds · #am77yy43 · term · runs on the server

uses node:path

The older builds (builds/) but the newest keep, removed: their names.

import { KEEP_BUILDS, keptBuilds } from "#codebase/tcmts/cli/builds";
import fs from "node:fs";
import path from "node:path";

export function pruneKeptBuilds(root: string, keep = KEEP_BUILDS): string[] {
  const older = keptBuilds(root).filter((b) => path.dirname(b.dir) === path.join(root, "builds"));
  const gone = older.slice(keep);
  for (const b of gone) fs.rmSync(b.dir, { recursive: true, force: true });
  return gone.map((b) => b.name);
}

uses

used by