UNPKG

cfn-forge

Version:

CloudFormation deployment automation tool with git-based workflows

116 lines (98 loc) 3.08 kB
/** * REPL Mode for CFN-Forge * * Provides a simple command prompt that stays open */ const readline = require('readline'); const chalk = require('chalk'); const { execSync } = require('child_process'); const path = require('path'); const { displayWelcomeBanner } = require('./welcome'); /** * Simple REPL (Read-Eval-Print-Loop) implementation */ async function startREPL() { displayWelcomeBanner(); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, prompt: chalk.cyan('cfn-forge> '), }); console.log(chalk.white('Type "help" for commands, "exit" to quit\n')); rl.prompt(); rl.on('line', (line) => { const input = line.trim(); switch (input) { case 'exit': case 'quit': case 'q': console.log(chalk.white('\nGoodbye! 👋\n')); rl.close(); process.exit(0); break; case 'help': case 'h': case '?': showHelp(); break; case 'clear': case 'cls': console.clear(); displayWelcomeBanner(); break; case '': // Empty line, just show prompt again break; default: // Try to execute as cfn-forge command executeCommand(input); break; } rl.prompt(); }); rl.on('close', () => { process.exit(0); }); } /** * Show available commands */ function showHelp() { console.log(chalk.yellow('\nAvailable commands:')); console.log(`${chalk.white(' init [name] ')}Initialize a new project`); console.log(`${chalk.white(' deploy ')}Deploy the CloudFormation stack`); console.log(`${chalk.white(' watch ')}Watch for changes and auto-deploy`); console.log(`${chalk.white(' cost ')}Estimate stack costs`); console.log(`${chalk.white(' parameters ')}Manage stack parameters`); console.log(`${chalk.white(' validate ')}Validate CloudFormation templates`); console.log(`${chalk.white(' templates ')}List available templates`); console.log(); console.log(chalk.yellow('REPL commands:')); console.log(`${chalk.white(' help ')}Show this help message`); console.log(`${chalk.white(' clear ')}Clear the screen`); console.log(`${chalk.white(' exit ')}Exit interactive mode`); console.log(); console.log(chalk.white('You can also run any cfn-forge command directly')); console.log(chalk.white('Example: ') + chalk.white('deploy --environment prod')); console.log(); } /** * Execute a cfn-forge command */ function executeCommand(input) { const binPath = path.join(__dirname, '../../../bin/cfn-forge'); try { console.log(); // Add spacing execSync(`node ${binPath} ${input}`, { stdio: 'inherit', env: { ...process.env, CFN_FORGE_IN_REPL: 'true' }, }); console.log(); // Add spacing after command } catch (error) { // Command failed or was cancelled, that's ok console.log(); // Still add spacing } } module.exports = { startREPL, };