deployStage

tcmts.dev.deployStage · #b4qedgxl · term · runs on the server

uses node:fs

A directory to upload: the files kept under a namespace of tcmts.deploy, and the known-good tcm's package beside them as tcm-ts.tgz.

import { codebaseDir, sh } from "#codebase/tcmts/dev";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

export function deployStage(ns: string, { good, tgz }: { good: string; tgz: string }): string {
  const tcm = process.env.TCM_BIN;
  if (!tcm)
    throw new Error("run this with `tcm run`, which gives it the codebase's own tcm (TCM_BIN)");
  const stage = fs.mkdtempSync(path.join(os.tmpdir(), `tcm-${ns.split(".").at(-1)}-`));
  const files = sh(process.execPath, [tcm, "export", ns, stage], codebaseDir());
  if (!files.ok) throw new Error(`tcm export ${ns}: ${files.out.trim()}`);
  fs.copyFileSync(path.join(good, tgz), path.join(stage, "tcm-ts.tgz"));
  return stage;
}

uses

used by