import { listTransactions } from "@olenbetong/appframe-updater"; import chalk from "chalk"; import inquirer from "inquirer"; import { renderTransactionsEditor } from "./editor/TransactionsEditor.js"; import { Command } from "./lib/Command.js"; import { getServerFromOptions } from "./lib/getServerFromOptions.js"; import { importJson } from "./lib/importJson.js"; import { Server } from "./lib/Server.js"; const isInteractive = process.stdout.isTTY; async function deployTransactions(namespaceArg: string, options: { server: string }) { try { await getServerFromOptions(options); let server = new Server(options.server); let namespace = await server.getNamespaceArgument(namespaceArg, options); while (true) { let transactions = await server.getTransactions("deploy", namespace); if (transactions.length === 0) { console.error(chalk.yellow("No transactions available to deploy.")); process.exit(0); } listTransactions(transactions); if (!isInteractive) { break; } let { action } = await inquirer.prompt({ type: "select", name: "action", message: "Are you sure you want to deploy these transactions? (n)", choices: [ { name: "Yes", value: "yes" }, { name: "No", value: "no" }, { name: "Edit transactions", value: "edit" }, ], default: "no", }); if (action === "yes") { break; } if (action === "no") { process.exit(0); } let instance = await renderTransactionsEditor({ filter: "deployEdit", server, namespace }); await instance.waitUntilExit(); } await server.deploy(namespace); server.logServerMessage("Done."); } catch (error: any) { console.log(chalk.red(error.message)); process.exit(1); } } const appPkg = await importJson("../package.json"); const program = new Command(); program .version(appPkg.version) .addNamespaceArgument() .addServerOption() .action(deployTransactions) .parseAsync(process.argv);