runMirror

tcmts.cli.run.runMirror · #iuxlvumo · term · runs on the server

uses node:path

Runs tcm mirror.

import { routeMirror } from "#codebase/tcmts/cli/commands";
import { execute } from "#codebase/tcmts/cli/main";
import { checkMirror, loadMirror, unlinkMirror } from "#codebase/tcmts/cli/mirror";
import type { Context } from "#codebase/tcmts/cli/run";
import { bold, dim, green, red } from "#codebase/tcmts/cli/style";
import { UsageError } from "#codebase/tcmts/cli/ui";
import { parse } from "@bomb.sh/router";
import path_1 from "node:path";

export function runMirror({ cb, cmd, rest, cwd }: Context): number {
  const { model } = execute(cmd, parse(routeMirror(), { argv: rest }));
  const m = loadMirror(cb);
  if (!m)
    throw new UsageError(
      "this codebase has no mirror; link one with `tcm import <dir> --into <ns> --mirror`",
    );
  if (model.unlink) {
    unlinkMirror(cb);
    console.log(`no longer writing back to ${path_1.relative(cwd, m.dir) || "."}`);
    return 0;
  }
  console.log(
    `${bold(m.into || "(root)")} is mirrored to ${path_1.relative(cwd, m.dir) || "."} ${dim(`(${Object.keys(m.files).length} files)`)}`,
  );
  if (!model.check) return 0;
  const problems = checkMirror(cb, m);
  for (const p of problems) console.log(red(`  ${p}`));
  console.log(
    problems.length
      ? red(`${problems.length} difference(s) between the files and the codebase`)
      : green("the files hash to what the codebase holds"),
  );
  return problems.length ? 1 : 0;
}

uses

used by