runMigrate

tcmts.cli.run.runMigrate · #uvxjtoni · term · runs on the server

uses node:path

Runs tcm migrate, without opening the codebase.

import { Codebase } from "#codebase/tcmts/cli/codebase";
import { routeMigrate } from "#codebase/tcmts/cli/commands";
import { execute } from "#codebase/tcmts/cli/main";
import { migrateCodebase } from "#codebase/tcmts/cli/migrate";
import type { Started } from "#codebase/tcmts/cli/run";
import { dim } from "#codebase/tcmts/cli/style";
import { success } from "#codebase/tcmts/cli/ui";
import { IR_VERSION } from "#codebase/tcmts/core/hash";
import { parse } from "@bomb.sh/router";
import path_1 from "node:path";

export function runMigrate({ cmd, rest, cwd }: Started): number {
  // a codebase in another hash format can't be opened: migrating it is what opens it
  const { model } = execute(cmd, parse(routeMigrate(), { argv: rest }));
  const done = migrateCodebase(Codebase.findRoot(cwd));
  if (!done) {
    if (!model["if-needed"])
      console.log(dim(`the codebase is in hash format v${IR_VERSION} already: nothing to do`));
    return 0;
  }
  success(
    `migrated ${done.definitions} definition(s) and ${done.causals} history entr${done.causals === 1 ? "y" : "ies"} from hash format v${done.from.join(", v")} to v${done.to} (${done.rewritten} read differently; ${done.verified} checked)`,
  );
  console.log(dim(`  the codebase as it was: ${path_1.relative(cwd, done.backup)}`));
  return 0;
}

uses

used by