railwayProject

tcmts.dev.railwayProject · #s5t4sbnj · term · runs on the server

uses tcmts.dev.sh, which uses node:child_process

The Railway project and production environment the repository is linked to (railway link), which railway up from elsewhere needs said.

import { repository, sh } from "#codebase/tcmts/dev";

export function railwayProject(): { project: string; environment: string } {
  const status = sh("railway", ["status", "--json"], repository());
  if (!status.ok)
    throw new Error(
      `railway status: ${status.out.trim()} (link the repository with \`railway link\`)`,
    );
  const linked = JSON.parse(status.out.slice(status.out.indexOf("{"))) as {
    id: string;
    environments: { edges: { node: { id: string; name: string } }[] };
  };
  const environment = linked.environments.edges.find((e) => e.node.name === "production")?.node.id;
  if (!environment) throw new Error("the linked Railway project has no production environment");
  return { project: linked.id, environment };
}

uses

used by