UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

86 lines (84 loc) • 2.79 kB
import { pluginEvents } from "../../services/dev/progress.mjs"; import { exitCodeFor } from "../exit-codes.mjs"; import { clearSpinnerStopLine, printStartSummary } from "../render/dev.mjs"; import * as p from "@clack/prompts"; //#region src/cli/commands/dev.ts const mountSession = async (projectDir, session) => { const [{ devApp }, { DevRendererCliLive }] = await Promise.all([import("../../services/dev/session.mjs"), import("../render/dev-render.mjs")]); devApp(projectDir ?? process.cwd(), session, DevRendererCliLive); }; const runDev = async (ctx) => { const client = ctx.client; const input = ctx.input; ctx.outdatedWarning; const projectDir = ctx.projectDir; const devSpinner = p.spinner(); devSpinner.start("Starting dev environment"); const devPhaseLabels = { "shared deps": "Preparing config...", install: "Installing dependencies...", build: "Building...", "resolve config": "Resolving config...", ports: "Finding available ports...", "docker compose up": "Starting local Postgres...", "generate artifacts": "Generating code artifacts..." }; const onDevProgress = (event) => { const label = devPhaseLabels[event.phase] ?? event.phase; if (event.status === "running") devSpinner.message(label); }; pluginEvents.on("progress", onDevProgress); let result; try { result = await client.dev(input); } finally { pluginEvents.off("progress", onDevProgress); } if (exitCodeFor(result) === 1) { devSpinner.stop("Failed"); console.error(`[CLI] ${result.description}`); process.exit(1); } devSpinner.stop(); clearSpinnerStopLine(); const session = result.session; if (session) await mountSession(projectDir, session); }; const runStart = async (ctx) => { const client = ctx.client; const input = ctx.input; ctx.outdatedWarning; const projectDir = ctx.projectDir; const startSpinner = p.spinner(); startSpinner.start("Starting production environment"); const startPhaseLabels = { config: "Preparing config...", "generate artifacts": "Generating code artifacts..." }; const onStartProgress = (event) => { const label = startPhaseLabels[event.phase] ?? event.phase; if (event.status === "running") startSpinner.message(label); }; pluginEvents.on("progress", onStartProgress); let result; try { result = await client.start(input); } finally { pluginEvents.off("progress", onStartProgress); } if (exitCodeFor(result) === 1) { startSpinner.stop("Failed"); console.error(`[CLI] ${result.error || "Unknown error"}`); process.exit(1); } startSpinner.stop("Ready"); const session = result.session; const summary = result.summary; if (session) { if (summary) printStartSummary(summary); await mountSession(projectDir, session); } }; //#endregion export { runDev, runStart }; //# sourceMappingURL=dev.mjs.map