UNPKG

@re-shell/cli

Version:

Full-stack development platform uniting microservices and microfrontends. Build complete applications with .NET (ASP.NET Core Web API, Minimal API), Java (Spring Boot, Quarkus, Micronaut, Vert.x), Rust (Actix-Web, Warp, Rocket, Axum), Python (FastAPI, Dja

366 lines (365 loc) • 15.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.manageEnvironment = manageEnvironment; const chalk_1 = __importDefault(require("chalk")); const prompts_1 = __importDefault(require("prompts")); const environment_1 = require("../utils/environment"); async function manageEnvironment(options = {}) { const { spinner, verbose, json } = options; try { if (options.list) { await listEnvironments(options, spinner); return; } if (options.active) { await showActiveEnvironment(options, spinner); return; } if (options.set) { await setEnvironment(options.set, options, spinner); return; } if (options.create) { await createEnvironment(options.create, options, spinner); return; } if (options.delete) { await deleteEnvironment(options.delete, options, spinner); return; } if (options.update) { await updateEnvironment(options.update, options, spinner); return; } if (options.compare && options.compare.length === 2) { await compareEnvironments(options.compare[0], options.compare[1], options, spinner); return; } if (options.generate) { await generateEnvFile(options.generate, options, spinner); return; } if (options.interactive) { await interactiveEnvironmentManagement(options, spinner); return; } // Default: show environment status await showEnvironmentStatus(options, spinner); } catch (error) { if (spinner) spinner.fail(chalk_1.default.red('Environment operation failed')); throw error; } } async function listEnvironments(options, spinner) { if (spinner) spinner.setText('Loading environments...'); const environments = await environment_1.environmentManager.listEnvironments(); if (spinner) spinner.stop(); if (options.json) { console.log(JSON.stringify(environments, null, 2)); } else { console.log(chalk_1.default.cyan('\nšŸŒ Available Environments:')); console.log(chalk_1.default.gray('═'.repeat(40))); if (environments.length === 0) { console.log(chalk_1.default.yellow('No environments found. Creating defaults...')); await environment_1.environmentManager.createDefaultEnvironments(); return listEnvironments(options, spinner); } for (const env of environments) { const activeIndicator = env.active ? chalk_1.default.green('ā—') : chalk_1.default.gray('ā—‹'); const lastUsed = env.lastUsed ? ` (last used: ${new Date(env.lastUsed).toLocaleDateString()})` : ''; const extends_ = env.extends ? chalk_1.default.gray(` extends ${env.extends}`) : ''; console.log(`${activeIndicator} ${chalk_1.default.cyan(env.name)}${extends_}${chalk_1.default.gray(lastUsed)}`); if (options.verbose) { console.log(chalk_1.default.gray(` Mode: ${env.build.mode}`)); console.log(chalk_1.default.gray(` Variables: ${Object.keys(env.variables).length}`)); console.log(chalk_1.default.gray(` Provider: ${env.deployment.provider || 'none'}`)); } } } } async function showActiveEnvironment(options, spinner) { if (spinner) spinner.setText('Getting active environment...'); const activeEnv = await environment_1.environmentManager.getActiveEnvironment(); if (spinner) spinner.stop(); if (!activeEnv) { console.log(chalk_1.default.yellow('No active environment. Use `re-shell env set <name>` to activate one.')); return; } if (options.json) { console.log(JSON.stringify(activeEnv, null, 2)); } else { console.log(chalk_1.default.cyan(`\nšŸŒ Active Environment: ${chalk_1.default.bold(activeEnv.name)}`)); console.log(chalk_1.default.gray('═'.repeat(40))); if (activeEnv.extends) { console.log(chalk_1.default.gray(`Extends: ${activeEnv.extends}`)); } console.log(chalk_1.default.cyan('\nšŸ“‹ Variables:')); for (const [key, value] of Object.entries(activeEnv.variables)) { console.log(` ${chalk_1.default.cyan(key)}: ${value}`); } console.log(chalk_1.default.cyan('\nšŸ”§ Build Configuration:')); console.log(` Mode: ${activeEnv.build.mode}`); console.log(` Optimization: ${activeEnv.build.optimization}`); console.log(` Source maps: ${activeEnv.build.sourcemaps}`); if (activeEnv.deployment.provider) { console.log(chalk_1.default.cyan('\nšŸš€ Deployment:')); console.log(` Provider: ${activeEnv.deployment.provider}`); console.log(` Target: ${activeEnv.deployment.target || 'default'}`); } } } async function setEnvironment(name, options, spinner) { if (spinner) spinner.setText(`Setting active environment to ${name}...`); await environment_1.environmentManager.setActiveEnvironment(name); if (spinner) { spinner.succeed(chalk_1.default.green(`Environment '${name}' is now active!`)); } } async function createEnvironment(name, options, spinner) { if (spinner) spinner.setText(`Creating environment ${name}...`); // Basic environment creation - can be enhanced with prompts const config = { name, variables: { NODE_ENV: name, DEBUG: name === 'development' ? 'true' : 'false' }, build: { mode: name, optimization: name !== 'development', sourcemaps: true }, deployment: {} }; await environment_1.environmentManager.createEnvironment(name, config, options.extends); if (spinner) { spinner.succeed(chalk_1.default.green(`Environment '${name}' created successfully!`)); } } async function deleteEnvironment(name, options, spinner) { if (spinner) spinner.setText(`Deleting environment ${name}...`); await environment_1.environmentManager.deleteEnvironment(name); if (spinner) { spinner.succeed(chalk_1.default.green(`Environment '${name}' deleted successfully!`)); } } async function updateEnvironment(name, options, spinner) { if (spinner) spinner.setText(`Updating environment ${name}...`); // This would be enhanced with interactive prompts or CLI options console.log(chalk_1.default.cyan(`Interactive update for environment '${name}' coming soon...`)); if (spinner) { spinner.succeed(chalk_1.default.green(`Environment '${name}' updated!`)); } } async function compareEnvironments(env1, env2, options, spinner) { if (spinner) spinner.setText(`Comparing environments ${env1} and ${env2}...`); const comparison = await environment_1.environmentManager.compareEnvironments(env1, env2); if (spinner) spinner.stop(); if (options.json) { console.log(JSON.stringify(comparison, null, 2)); } else { console.log(chalk_1.default.cyan(`\nšŸ” Environment Comparison: ${env1} vs ${env2}`)); console.log(chalk_1.default.gray('═'.repeat(50))); console.log(chalk_1.default.cyan('\nšŸ“‹ Variables:')); if (comparison.variables.added.length > 0) { console.log(chalk_1.default.green(` Added in ${env2}: ${comparison.variables.added.join(', ')}`)); } if (comparison.variables.removed.length > 0) { console.log(chalk_1.default.red(` Removed from ${env2}: ${comparison.variables.removed.join(', ')}`)); } if (comparison.variables.changed.length > 0) { console.log(chalk_1.default.yellow(' Changed:')); for (const change of comparison.variables.changed) { console.log(` ${change.key}: ${chalk_1.default.red(change.from)} → ${chalk_1.default.green(change.to)}`); } } if (Object.keys(comparison.build).length > 0) { console.log(chalk_1.default.cyan('\nšŸ”§ Build Configuration:')); for (const [key, diff] of Object.entries(comparison.build)) { console.log(` ${key}: ${chalk_1.default.red(diff.from)} → ${chalk_1.default.green(diff.to)}`); } } if (Object.keys(comparison.deployment).length > 0) { console.log(chalk_1.default.cyan('\nšŸš€ Deployment Configuration:')); for (const [key, diff] of Object.entries(comparison.deployment)) { console.log(` ${key}: ${chalk_1.default.red(diff.from)} → ${chalk_1.default.green(diff.to)}`); } } } } async function generateEnvFile(environmentName, options, spinner) { if (spinner) spinner.setText(`Generating .env file for ${environmentName}...`); const filePath = await environment_1.environmentManager.generateEnvFile(environmentName, options.output); if (spinner) { spinner.succeed(chalk_1.default.green(`Environment file generated: ${filePath}`)); } } async function showEnvironmentStatus(options, spinner) { if (spinner) spinner.setText('Loading environment status...'); const activeEnv = await environment_1.environmentManager.getActiveEnvironment(); const environments = await environment_1.environmentManager.listEnvironments(); if (spinner) spinner.stop(); if (options.json) { console.log(JSON.stringify({ active: activeEnv, environments: environments }, null, 2)); } else { console.log(chalk_1.default.cyan('\nšŸŒ Environment Status')); console.log(chalk_1.default.gray('═'.repeat(30))); if (activeEnv) { console.log(chalk_1.default.green(`Active: ${activeEnv.name}`)); } else { console.log(chalk_1.default.yellow('No active environment')); } console.log(chalk_1.default.cyan(`Total environments: ${environments.length}`)); if (environments.length > 0) { console.log(chalk_1.default.cyan('\nQuick actions:')); console.log('• re-shell env list - List all environments'); console.log('• re-shell env set <name> - Switch environment'); console.log('• re-shell env create <name> - Create new environment'); console.log('• re-shell env generate <name> - Generate .env file'); } } } async function interactiveEnvironmentManagement(options, spinner) { if (spinner) spinner.stop(); const response = await (0, prompts_1.default)([ { type: 'select', name: 'action', message: 'What would you like to do?', choices: [ { title: 'šŸ“‹ List Environments', value: 'list' }, { title: 'šŸŒ Show Active Environment', value: 'active' }, { title: 'šŸ”„ Switch Environment', value: 'switch' }, { title: 'āž• Create New Environment', value: 'create' }, { title: 'šŸ”§ Update Environment', value: 'update' }, { title: 'šŸ” Compare Environments', value: 'compare' }, { title: 'šŸ“„ Generate .env File', value: 'generate' }, { title: 'šŸ—‘ļø Delete Environment', value: 'delete' } ] } ]); if (!response.action) return; switch (response.action) { case 'list': await listEnvironments(options); break; case 'active': await showActiveEnvironment(options); break; case 'switch': await interactiveSwitchEnvironment(); break; case 'create': await interactiveCreateEnvironment(); break; // Add other interactive actions... default: console.log(chalk_1.default.cyan(`${response.action} functionality coming soon...`)); } } async function interactiveSwitchEnvironment() { const environments = await environment_1.environmentManager.listEnvironments(); if (environments.length === 0) { console.log(chalk_1.default.yellow('No environments available. Create one first.')); return; } const response = await (0, prompts_1.default)([ { type: 'select', name: 'environment', message: 'Select environment to activate:', choices: environments.map(env => ({ title: `${env.name}${env.active ? ' (current)' : ''}`, value: env.name, description: `Mode: ${env.build.mode}, Provider: ${env.deployment.provider || 'none'}` })) } ]); if (response.environment) { await environment_1.environmentManager.setActiveEnvironment(response.environment); console.log(chalk_1.default.green(`āœ… Environment '${response.environment}' is now active!`)); } } async function interactiveCreateEnvironment() { const environments = await environment_1.environmentManager.listEnvironments(); const response = await (0, prompts_1.default)([ { type: 'text', name: 'name', message: 'Environment name:', validate: (value) => { if (!value.trim()) return 'Name is required'; if (environments.some(env => env.name === value)) return 'Environment already exists'; return true; } }, { type: 'select', name: 'extends', message: 'Inherit from existing environment?', choices: [ { title: 'None (start fresh)', value: null }, ...environments.map(env => ({ title: env.name, value: env.name })) ] }, { type: 'select', name: 'mode', message: 'Build mode:', choices: [ { title: 'Development', value: 'development' }, { title: 'Staging', value: 'staging' }, { title: 'Production', value: 'production' } ] } ]); if (response.name) { const config = { name: response.name, variables: { NODE_ENV: response.mode || 'development' }, build: { mode: response.mode || 'development', optimization: response.mode !== 'development', sourcemaps: true }, deployment: {} }; await environment_1.environmentManager.createEnvironment(response.name, config, response.extends); console.log(chalk_1.default.green(`āœ… Environment '${response.name}' created successfully!`)); } }