UNPKG

forge-deploy-cli

Version:

Professional CLI for local deployments with automatic subdomain routing, SSL certificates, and infrastructure management

171 lines 8.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.statusCommand = statusCommand; const chalk_1 = __importDefault(require("chalk")); const config_1 = require("../services/config"); const api_1 = require("../services/api"); const localDeployment_1 = require("../services/localDeployment"); async function statusCommand(options) { console.log(chalk_1.default.blue.bold('Checking deployment status...')); const configService = new config_1.ConfigService(); const config = await configService.getConfig(); if (!config.apiKey) { console.error(chalk_1.default.red('Not logged in. Please run: forge login')); process.exit(1); } const apiService = new api_1.ForgeApiService(config.apiUrl); apiService.setApiKey(config.apiKey); try { let deployments; if (options.deploymentId) { // Get specific deployment const response = await apiService.getDeployments({ id: options.deploymentId }); if (response.success) { deployments = response.data?.deployments || []; } else { throw new Error(response.error?.message || 'Failed to fetch deployment'); } } else if (options.all) { // Get all deployments const response = await apiService.getDeployments(); if (response.success) { deployments = response.data?.deployments || []; } else { throw new Error(response.error?.message || 'Failed to fetch deployments'); } } else { // Get current project deployment if (!config.deploymentId) { console.error(chalk_1.default.red('No deployment found for current project. Use --all to see all deployments.')); process.exit(1); } const response = await apiService.getDeployments({ id: config.deploymentId }); if (response.success) { deployments = response.data?.deployments || []; } else { throw new Error(response.error?.message || 'Failed to fetch deployment'); } } if (deployments.length === 0) { console.log(chalk_1.default.yellow('No deployments found')); return; } console.log(); deployments.forEach((deployment) => { const statusColor = getStatusColor(deployment.status); const healthColor = getHealthColor(deployment.healthStatus); console.log(chalk_1.default.white.bold(`${deployment.projectName} (${deployment.id})`)); console.log(chalk_1.default.gray(` URL: ${deployment.url}`)); console.log(chalk_1.default.gray(` Framework: ${deployment.framework}`)); console.log(` Status: ${statusColor(deployment.status)}`); console.log(` Health: ${healthColor(deployment.healthStatus)}`); console.log(chalk_1.default.gray(` Created: ${new Date(deployment.createdAt).toLocaleString()}`)); if (deployment.deployedAt) { console.log(chalk_1.default.gray(` Deployed: ${new Date(deployment.deployedAt).toLocaleString()}`)); } console.log(); }); // Also show local deployment status console.log(chalk_1.default.blue.bold('Local Deployments:')); const localDeployments = await localDeployment_1.LocalDeploymentManager.listDeployments(); if (localDeployments.length === 0) { console.log(chalk_1.default.gray(' No local deployments found')); } else { // Update resource usage for all local deployments for (const localDep of localDeployments) { await localDeployment_1.LocalDeploymentManager.updateDeploymentResources(localDep.id); } // Get updated deployments with fresh resource data const updatedLocalDeployments = await localDeployment_1.LocalDeploymentManager.listDeployments(); updatedLocalDeployments.forEach(localDep => { const localStatusColor = getLocalStatusColor(localDep.status); console.log(chalk_1.default.white.bold(` ${localDep.projectName} (${localDep.id})`)); console.log(chalk_1.default.gray(` Project Path: ${localDep.projectPath}`)); console.log(chalk_1.default.gray(` Local URL: http://localhost:${localDep.port}`)); console.log(chalk_1.default.gray(` Public URL: ${localDep.url}`)); console.log(` Status: ${localStatusColor(localDep.status)}`); console.log(chalk_1.default.gray(` Framework: ${localDep.framework}`)); if (localDep.startedAt) { console.log(chalk_1.default.gray(` Started: ${new Date(localDep.startedAt).toLocaleString()}`)); } if (localDep.pid) { console.log(chalk_1.default.gray(` Process ID: ${localDep.pid}`)); } // Show resource usage if available if (localDep.resources) { const { cpu, memory, diskUsed, diskUsagePercent } = localDep.resources; console.log(chalk_1.default.gray(` CPU: ${cpu.toFixed(1)}% | Memory: ${memory.toFixed(1)}%`)); console.log(chalk_1.default.gray(` Disk: ${(diskUsed / (1024 * 1024 * 1024)).toFixed(2)}GB (${diskUsagePercent.toFixed(1)}% of 15GB limit)`)); } // Show available actions based on status if (localDep.status === 'running') { console.log(chalk_1.default.blue(` Actions: forge pause ${localDep.id} | forge stop ${localDep.id}`)); } else if (localDep.status === 'paused') { console.log(chalk_1.default.blue(` Actions: forge resume ${localDep.id} | forge stop ${localDep.id}`)); } else if (localDep.status === 'stopped') { console.log(chalk_1.default.blue(` Actions: forge deploy (to restart)`)); } console.log(); }); } console.log(chalk_1.default.blue('Web Interface:')); console.log(chalk_1.default.gray(' For detailed deployment information with web interface:')); console.log(chalk_1.default.cyan(' Visit: https://forgecli.tech/deployments')); console.log(chalk_1.default.gray(' Or use: forge info --id <deployment-id>')); console.log(); } catch (error) { console.error(chalk_1.default.red('Failed to fetch status:'), error instanceof Error ? error.message : error); process.exit(1); } } function getStatusColor(status) { switch (status.toLowerCase()) { case 'deployed': return chalk_1.default.green; case 'building': case 'deploying': return chalk_1.default.yellow; case 'failed': case 'cancelled': return chalk_1.default.red; default: return chalk_1.default.gray; } } function getHealthColor(health) { switch (health.toLowerCase()) { case 'healthy': return chalk_1.default.green; case 'unhealthy': return chalk_1.default.red; default: return chalk_1.default.gray; } } function getLocalStatusColor(status) { switch (status.toLowerCase()) { case 'running': return chalk_1.default.green; case 'paused': return chalk_1.default.yellow; case 'stopped': return chalk_1.default.gray; case 'failed': return chalk_1.default.red; default: return chalk_1.default.gray; } } //# sourceMappingURL=status.js.map