runExport

tcmts.cli.run.runExport · #va6fw3nv · term · runs on the server

uses node:path

Runs tcm export.

import { routeExport } from "#codebase/tcmts/cli/commands";
import { exportFiles } from "#codebase/tcmts/cli/files";
import { execute } from "#codebase/tcmts/cli/main";
import type { Context } from "#codebase/tcmts/cli/run";
import { UsageError } from "#codebase/tcmts/cli/ui";
import { parse } from "@bomb.sh/router";
import path_1 from "node:path";

export function runExport({ cb, cmd, rest, cwd }: Context): number {
  const { model } = execute(cmd, parse(routeExport(), { argv: rest }));
  if (!model.namespace || !model.dir)
    throw new UsageError("usage: tcm export <namespace> <dir>, e.g. `tcm export docs site/docs`");
  const n = exportFiles(cb, model.namespace, path_1.resolve(cwd, model.dir));
  if (!n) throw new UsageError(`no files under ${model.namespace}`);
  console.log(`wrote ${n} file${n > 1 ? "s" : ""} from ${model.namespace} to ${model.dir}`);
  return 0;
}

uses

used by