everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
75 lines (73 loc) • 3.22 kB
JavaScript
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
const require_theme = require("../utils/theme.cjs");
const require_sync = require("../services/scaffold/sync.cjs");
const require_upgrade = require("../services/scaffold/upgrade.cjs");
let node_process = require("node:process");
node_process = require_runtime.__toESM(node_process, 1);
let _clack_prompts = require("@clack/prompts");
_clack_prompts = require_runtime.__toESM(_clack_prompts, 1);
//#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 (!node_process.default.stdout.isTTY) return {};
const plan = await require_upgrade.upgradeTemplate(projectDir, {
...input,
dryRun: true
});
if (plan.status !== "dry-run" || !plan.updatesAvailable) return {};
const preflight = await require_sync.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 {};
_clack_prompts.log.step(`Upgrade plan — ${plan.packages.filter((pkg) => pkg.from && pkg.from !== pkg.to).map((pkg) => `${pkg.name} ${pkg.from} → ${pkg.to}`).join(", ")}`);
_clack_prompts.log.message(`Release: ${plan.release?.resolved ?? "latest"} (${plan.release?.source ?? "extends chain"})`);
if (plan.changelogUrl) _clack_prompts.log.message(`Changelog: ${plan.changelogUrl}`);
const selected = await _clack_prompts.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 (_clack_prompts.isCancel(selected)) {
_clack_prompts.cancel("Upgrade cancelled — nothing was written");
return null;
}
const cleanAfter = await _clack_prompts.confirm({
message: "Prune logs and caches after the upgrade (bos clean — upgrade backups kept)?",
initialValue: true
});
if (_clack_prompts.isCancel(cleanAfter)) {
_clack_prompts.cancel("Upgrade cancelled — nothing was written");
return null;
}
const go = await _clack_prompts.confirm({
message: "Write?",
initialValue: true
});
if (_clack_prompts.isCancel(go) || !go) {
_clack_prompts.cancel("Upgrade cancelled — nothing was written");
return null;
}
_clack_prompts.log.message(require_theme.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
exports.planUpgradeInteraction = planUpgradeInteraction;
//# sourceMappingURL=upgrade-plan.cjs.map