UNPKG

everything-dev

Version:

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

72 lines (70 loc) • 2.75 kB
import { colors } from "../utils/theme.mjs"; import { syncTemplate } from "../services/scaffold/sync.mjs"; import { upgradeTemplate } from "../services/scaffold/upgrade.mjs"; import process from "node:process"; import * as p from "@clack/prompts"; //#region src/cli/upgrade-plan.ts /** * `null` — the user explicitly declined (cancel or "Write? no"): nothing was * written, and the caller reports a cancelled result instead of exiting the * runtime from inside an Effect generator. */ async function planUpgradeInteraction(projectDir, input) { if (input.force || input.dryRun || input.check || input.noSync || input.migrationsOnly) return {}; if (!process.stdout.isTTY) return {}; const plan = await upgradeTemplate(projectDir, { ...input, dryRun: true }); if (plan.status !== "dry-run" || !plan.updatesAvailable) return {}; const preflight = await syncTemplate(projectDir, { dryRun: true }); if (preflight.status === "error") return {}; const conflicted = preflight.conflicted; const writable = [ ...preflight.updated, ...preflight.added, ...conflicted ]; if (writable.length === 0) return {}; p.log.step(`Upgrade plan — ${plan.packages.filter((pkg) => pkg.from && pkg.from !== pkg.to).map((pkg) => `${pkg.name} ${pkg.from} → ${pkg.to}`).join(", ")}`); p.log.message(`Release: ${plan.release?.resolved ?? "latest"} (${plan.release?.source ?? "extends chain"})`); if (plan.changelogUrl) p.log.message(`Changelog: ${plan.changelogUrl}`); const selected = await p.multiselect({ message: "Files this upgrade will write (space toggles, enter confirms)", options: writable.map((file) => ({ value: file, label: file, hint: conflicted.includes(file) ? "local edits — template wins (backup kept)" : preflight.added.includes(file) ? "new file" : "template update" })), initialValues: writable, required: false }); if (p.isCancel(selected)) { p.cancel("Upgrade cancelled — nothing was written"); return null; } const cleanAfter = await p.confirm({ message: "Prune logs and caches after the upgrade (bos clean — upgrade backups kept)?", initialValue: true }); if (p.isCancel(cleanAfter)) { p.cancel("Upgrade cancelled — nothing was written"); return null; } const go = await p.confirm({ message: "Write?", initialValue: true }); if (p.isCancel(go) || !go) { p.cancel("Upgrade cancelled — nothing was written"); return null; } p.log.message(colors.dim(selected.length === writable.length ? `Writing all ${writable.length} file(s)` : `Writing ${selected.length} of ${writable.length} — the rest stay as your local copies`)); return { overwrite: [...selected], cleanAfter }; } //#endregion export { planUpgradeInteraction }; //# sourceMappingURL=upgrade-plan.mjs.map