renameDefinition

tcmts.studio.renameDefinition · #zmxtpk77 · term · runs on the server

uses tcmts.studio.editableCodebase, which uses tcmts.share.servedCodebase, which uses process

Rename (or move) the definition or namespace from to to, as tcm mv does (it's run, on the branch the studio serves): no code changes, and what uses it follows, by hash. What it said.

import { HttpError } from "#codebase/tcmts/server";
import { editableCodebase, runTcm } from "#codebase/tcmts/studio";

export async function renameDefinition(from: string, to: string): Promise<string> {
  const cb = editableCodebase();
  const want = to.trim();
  if (!/^[A-Za-z_$][\w$-]*(\.[A-Za-z_$][\w$-]*)*$/.test(want))
    throw new HttpError(400, `${want} isn't a name (a.b.c).`);
  if (want === from) return "";
  const out = await runTcm(cb.lay.root, ["mv", from, want], { branch: true });
  if (out.code !== 0)
    throw new HttpError(
      400,
      out.text.split("\n").slice(0, 6).join("\n") || `tcm mv ${from} ${want} failed`,
    );
  return out.text.split("\n")[0] ?? "";
}

uses

used by