24 lines
1005 B
TypeScript
24 lines
1005 B
TypeScript
import { readFile, stat } from 'node:fs/promises';
|
|
import {
|
|
cutover,
|
|
nodeCutoverSystem,
|
|
parseCutoverPlan,
|
|
preflight,
|
|
rollback,
|
|
} from './cutover-orchestrator.js';
|
|
|
|
const [action, planPath] = process.argv.slice(2);
|
|
if (!['preflight', 'cutover', 'rollback'].includes(action ?? '') || !planPath) {
|
|
throw new Error('Usage: pnpm cutover <preflight|cutover|rollback> <plan.json>');
|
|
}
|
|
const planInfo = await stat(planPath);
|
|
if (!planInfo.isFile() || (planInfo.mode & 0o077) !== 0) {
|
|
throw new Error('Cutover plan must be a regular file inaccessible to group and other users');
|
|
}
|
|
const plan = parseCutoverPlan(JSON.parse(await readFile(planPath, 'utf8')) as unknown);
|
|
const gatewayToken = process.env.MULTI_SIMADMIN_GATEWAY_TOKEN ?? '';
|
|
if (action === 'preflight') await preflight(plan, nodeCutoverSystem, gatewayToken);
|
|
else if (action === 'cutover') await cutover(plan, nodeCutoverSystem, gatewayToken);
|
|
else await rollback(plan, nodeCutoverSystem);
|
|
process.stdout.write(`${action} completed\n`);
|