addLib

tcmts.studio.addLib · #cvbzy24q · term · runs on the server

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

Add a library, as tcm lib add <source> [what] [--as <name>] does: a release its author announced (@alice.dev/geo), or what a remote, URL, directory or tcm holds (what: <package>[@<version>] or a namespace's hash), fetched with what it uses and mounted read-only. What it said.

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

export async function addLib(source: string, what: string, as: string): Promise<string> {
  const cb = editableCodebase();
  const s = source.trim();
  if (!s || /\s/.test(s))
    throw new HttpError(400, "Say where it comes from: @handle/package, a remote, URL or tcm.");
  return tcmSaid(
    await runTcm(
      cb.lay.root,
      [
        "lib",
        "add",
        s,
        ...(what.trim() ? [what.trim()] : []),
        ...(as.trim() ? ["--as", as.trim()] : []),
      ],
      { branch: true },
    ),
    `tcm lib add ${s}`,
  );
}

uses

used by