UNPKG

@starship-ci/cli

Version:
114 lines (113 loc) 3.73 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const client_1 = require("@starship-ci/client"); // Adjust the import path as necessary const inquirerer_1 = require("inquirerer"); const minimist_1 = __importDefault(require("minimist")); const utils_1 = require("./utils"); const argv = (0, minimist_1.default)(process.argv.slice(2), { alias: { v: 'version' } }); if (!('tty' in argv)) { argv.tty = true; } if (argv.version) { (0, utils_1.displayVersion)(); process.exit(0); } const prompter = new inquirerer_1.Inquirerer({ noTty: !argv.tty }); const questions = utils_1.params.map((name) => ({ name, type: 'text' })); // Filter questions based on the command function getQuestionsForCommand(command) { const commonQuestions = questions.filter((q) => q.name !== 'config'); if (['start', 'deploy', 'start-ports', 'wait-for-pods'].includes(command)) { return questions; // Include all questions, including config } else { return commonQuestions; // Exclude config } } // Main function to run the application async function main() { const command = argv._[0]; // Display usage and exit early if no command or help command is provided if (!command || command === 'help') { (0, utils_1.displayUsage)(); prompter.close(); return; } // Load configuration and prompt for missing parameters const config = (0, utils_1.loadConfig)(argv); const commandQuestions = getQuestionsForCommand(command); const args = await prompter.prompt({ ...config.context }, commandQuestions, { usageText: utils_1.usageText }); const client = new client_1.StarshipClient(args); client.setConfig(config.starship); const installer = new client_1.StarshipInstaller(); // Execute command based on input switch (command) { case 'install': installer.checkAndInstallDependencies().catch((err) => { console.error('An error occurred during start:', err); process.exit(1); }); break; case 'start': client.start().catch((err) => { console.error('An error occurred during start:', err); process.exit(1); }); break; case 'deploy': client.deploy(); break; case 'setup': client.setup(); break; case 'start-ports': client.startPortForward(); break; case 'get-pods': client.getPods(); break; case 'wait-for-pods': client.waitForPods().catch((err) => { console.error('An error occurred during wait-for-pods:', err); process.exit(1); }); break; case 'port-pids': client.printForwardPids(); break; case 'stop-ports': client.stopPortForward(); break; case 'stop': client.stop().catch((err) => { console.error('An error occurred during stop:', err); process.exit(1); }); break; case 'undeploy': client.deleteHelm(); break; default: console.log(`Unknown command: ${command}`); (0, utils_1.displayUsage)(); } prompter.close(); } // Improved error handling main().catch((err) => { console.error('An error occurred:', err); prompter.close(); process.exit(1); });