openRemote

tcmts.cli.sync.openRemote · #w6shv4pm · term · runs on the server

uses process

A configured remote name (with the token it was added with), an http(s) URL, tcm (the libraries the running tcm ships: #n6g5fsci), or a path to another codebase. A URL that isn't a configured remote is asked with no credentials: a library's sources, an announcement's, are others' to choose, and the environment's token (TCM_TOKEN, a server's own) mustn't go to them.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { DirectoryRemote, HttpRemote, shippedLibraries } from "#codebase/tcmts/cli/sync";
import type { Remote, RemoteConfig } from "#codebase/tcmts/cli/sync";

export function openRemote(cb: Codebase, spec: string): { remote: Remote; name?: string } {
  const configured = cb.store.getSetting(`remote.${spec}`);
  if (configured) {
    const c = JSON.parse(configured) as RemoteConfig;
    return {
      remote: c.url.startsWith("http")
        ? new HttpRemote(c.url, c.token, c.fingerprint)
        : new DirectoryRemote(c.url),
      name: spec,
    };
  }
  if (spec === "tcm") {
    const dir = shippedLibraries(cb);
    if (!dir) throw new Error("this tcm ships no libraries: a tcm installed from its package does");
    return { remote: new DirectoryRemote(dir) };
  }
  if (/^https?:\/\//.test(spec))
    return { remote: new HttpRemote(spec, undefined, process.env.TCM_FINGERPRINT) };
  return { remote: new DirectoryRemote(spec) };
}

uses

used by