UNPKG

@aerocorp/cli

Version:

AeroCorp CLI 5.1.0 - Future-Proofed Enterprise Infrastructure with Live Preview, Tunneling & Advanced DevOps

238 lines β€’ 11.6 kB
"use strict"; /** * AeroCorp CLI 4.0.0 - Enhanced Deployment Service * Advanced deployment management for hybrid infrastructure */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeploymentService = void 0; const axios_1 = __importDefault(require("axios")); const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = __importDefault(require("inquirer")); const config_1 = require("./config"); const auth_1 = require("./auth"); class DeploymentService { constructor() { this.configService = new config_1.ConfigService(); this.authService = new auth_1.AuthService(); } async listApplications(options = {}) { try { const config = await this.configService.getConfig(); const auth = await this.authService.getAuth(); const params = new URLSearchParams(); if (options.platform) params.append('platform', options.platform); if (options.status) params.append('status', options.status); const response = await axios_1.default.get(`${config.apiUrl}/api/applications?${params}`, { headers: { 'Authorization': `Bearer ${auth.token}`, 'Content-Type': 'application/json' }, timeout: 10000 }); const data = response.data; console.log(chalk_1.default.cyan.bold('\nπŸš€ Applications')); console.log(chalk_1.default.gray(`Total: ${data.total} applications`)); console.log(chalk_1.default.gray(`Coolify: ${data.platforms.coolify} | CapRover: ${data.platforms.caprover}`)); if (data.applications.length === 0) { console.log(chalk_1.default.yellow('No applications found')); return; } console.log('\n' + chalk_1.default.white('Name'.padEnd(25) + 'Status'.padEnd(12) + 'Platform'.padEnd(12) + 'Version'.padEnd(12) + 'Last Deploy')); console.log(chalk_1.default.gray('─'.repeat(80))); data.applications.forEach((app) => { const statusIcon = app.status === 'running' ? 'βœ…' : app.status === 'deploying' ? 'πŸ”„' : app.status === 'failed' ? '❌' : '⏸️'; const statusColor = app.status === 'running' ? chalk_1.default.green : app.status === 'deploying' ? chalk_1.default.blue : app.status === 'failed' ? chalk_1.default.red : chalk_1.default.yellow; console.log(`${statusIcon} ${chalk_1.default.white(app.name.padEnd(22))} ` + `${statusColor(app.status.padEnd(11))} ` + `${chalk_1.default.cyan(app.platform.padEnd(11))} ` + `${chalk_1.default.white(app.version.padEnd(11))} ` + `${chalk_1.default.gray(new Date(app.lastDeploy).toLocaleString())}`); }); } catch (error) { throw new Error(`Failed to list applications: ${error.message}`); } } async deployApplication(uuid, options = {}) { try { const config = await this.configService.getConfig(); const auth = await this.authService.getAuth(); console.log(chalk_1.default.blue('πŸ”„ Starting deployment...')); const response = await axios_1.default.post(`${config.apiUrl}/api/applications/${uuid}/deploy`, options, { headers: { 'Authorization': `Bearer ${auth.token}`, 'Content-Type': 'application/json' }, timeout: 30000 }); const deployment = response.data; console.log(chalk_1.default.green('βœ… Deployment started successfully!')); console.log(chalk_1.default.white(`Deployment ID: ${deployment.deploymentId}`)); console.log(chalk_1.default.white(`Application: ${deployment.application.name}`)); console.log(chalk_1.default.white(`Estimated time: ${deployment.estimatedTime}`)); // Monitor deployment progress await this.monitorDeployment(uuid, deployment.deploymentId); } catch (error) { throw new Error(`Failed to deploy application: ${error.message}`); } } async createApplication(options = {}) { try { let appConfig; if (options.interactive !== false) { appConfig = await inquirer_1.default.prompt([ { type: 'input', name: 'name', message: 'Application name:', default: options.name, validate: (input) => input.length > 0 || 'Name is required' }, { type: 'input', name: 'repository', message: 'Repository URL:', default: options.repository, validate: (input) => input.length > 0 || 'Repository is required' }, { type: 'input', name: 'branch', message: 'Branch:', default: options.branch || 'main' }, { type: 'list', name: 'platform', message: 'Deployment platform:', choices: ['coolify', 'caprover'], default: options.platform || 'coolify' }, { type: 'list', name: 'environment', message: 'Environment:', choices: ['production', 'staging', 'development'], default: options.environment || 'production' } ]); } else { appConfig = options; } const config = await this.configService.getConfig(); const auth = await this.authService.getAuth(); console.log(chalk_1.default.blue('πŸ”„ Creating application...')); const response = await axios_1.default.post(`${config.apiUrl}/api/applications`, appConfig, { headers: { 'Authorization': `Bearer ${auth.token}`, 'Content-Type': 'application/json' }, timeout: 30000 }); const application = response.data.application; console.log(chalk_1.default.green('βœ… Application created successfully!')); console.log(chalk_1.default.white(`Name: ${application.name}`)); console.log(chalk_1.default.white(`UUID: ${application.uuid}`)); console.log(chalk_1.default.white(`Platform: ${application.platform}`)); console.log(chalk_1.default.white(`URL: ${application.url}`)); } catch (error) { throw new Error(`Failed to create application: ${error.message}`); } } async getApplicationLogs(uuid, options = {}) { try { const config = await this.configService.getConfig(); const auth = await this.authService.getAuth(); const params = new URLSearchParams(); if (options.lines) params.append('lines', options.lines.toString()); if (options.deployment) params.append('deployment', options.deployment); const response = await axios_1.default.get(`${config.apiUrl}/api/applications/${uuid}/logs?${params}`, { headers: { 'Authorization': `Bearer ${auth.token}`, 'Content-Type': 'application/json' }, timeout: 10000 }); const data = response.data; console.log(chalk_1.default.cyan.bold(`\nπŸ“‹ Application Logs - ${data.application}`)); console.log(chalk_1.default.gray(`Deployment: ${data.deployment} | Lines: ${data.logs.length}/${data.totalLines}`)); data.logs.forEach((log) => { const levelColor = log.level === 'error' ? chalk_1.default.red : log.level === 'warn' ? chalk_1.default.yellow : chalk_1.default.blue; const timestamp = new Date(log.timestamp).toLocaleTimeString(); console.log(`${chalk_1.default.gray(timestamp)} ${levelColor(log.level.toUpperCase().padEnd(5))} ${log.message}`); }); } catch (error) { throw new Error(`Failed to get application logs: ${error.message}`); } } async stopApplication(uuid) { try { const config = await this.configService.getConfig(); const auth = await this.authService.getAuth(); console.log(chalk_1.default.blue('πŸ”„ Stopping application...')); const response = await axios_1.default.post(`${config.apiUrl}/api/applications/${uuid}/stop`, {}, { headers: { 'Authorization': `Bearer ${auth.token}`, 'Content-Type': 'application/json' }, timeout: 30000 }); console.log(chalk_1.default.green('βœ… Application stopped successfully!')); console.log(chalk_1.default.white(`Application: ${response.data.application.name}`)); } catch (error) { throw new Error(`Failed to stop application: ${error.message}`); } } async startApplication(uuid) { try { const config = await this.configService.getConfig(); const auth = await this.authService.getAuth(); console.log(chalk_1.default.blue('πŸ”„ Starting application...')); const response = await axios_1.default.post(`${config.apiUrl}/api/applications/${uuid}/start`, {}, { headers: { 'Authorization': `Bearer ${auth.token}`, 'Content-Type': 'application/json' }, timeout: 30000 }); console.log(chalk_1.default.green('βœ… Application started successfully!')); console.log(chalk_1.default.white(`Application: ${response.data.application.name}`)); } catch (error) { throw new Error(`Failed to start application: ${error.message}`); } } async monitorDeployment(uuid, deploymentId) { console.log(chalk_1.default.blue('πŸ”„ Monitoring deployment progress...')); // Simulate monitoring (in real implementation, this would poll the deployment status) const spinner = ['β ‹', 'β ™', 'β Ή', 'β Έ', 'β Ό', 'β ΄', 'β ¦', 'β §', 'β ‡', '⠏']; let i = 0; const interval = setInterval(() => { process.stdout.write(`\r${chalk_1.default.blue(spinner[i++ % spinner.length])} Deploying...`); }, 100); setTimeout(() => { clearInterval(interval); process.stdout.write('\r'); console.log(chalk_1.default.green('βœ… Deployment completed successfully!')); }, 5000); } } exports.DeploymentService = DeploymentService; //# sourceMappingURL=deployment.js.map