UNPKG

forge-deploy-cli

Version:

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

110 lines 4.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.serviceCommand = void 0; const chalk_1 = __importDefault(require("chalk")); const commander_1 = require("commander"); const autoRestart_1 = require("../services/autoRestart"); const system_1 = require("../utils/system"); exports.serviceCommand = new commander_1.Command('service') .description('Manage Forge CLI service') .option('--start', 'Start the auto-restart service') .option('--stop', 'Stop the auto-restart service') .option('--restart', 'Restart the auto-restart service') .option('--status', 'Show service status') .option('--daemon', 'Run as service daemon (internal use)') .action(async (options) => { try { if (options.daemon) { // This is used internally by the service await autoRestart_1.AutoRestartService.startServiceDaemon(); return; } if (options.start) { await startService(); return; } if (options.stop) { await stopService(); return; } if (options.restart) { await restartService(); return; } if (options.status) { await showServiceStatus(); return; } // Default: show service status await showServiceStatus(); } catch (error) { console.log(chalk_1.default.red(`Service operation failed: ${error}`)); process.exit(1); } }); async function startService() { console.log(chalk_1.default.cyan('Starting Forge CLI service...')); try { await autoRestart_1.AutoRestartService.startAutoRestart(); console.log(chalk_1.default.green('Service started successfully')); } catch (error) { console.log(chalk_1.default.red(`Failed to start service: ${error}`)); process.exit(1); } } async function stopService() { console.log(chalk_1.default.cyan('Stopping Forge CLI service...')); try { await autoRestart_1.AutoRestartService.stopAutoRestart(); console.log(chalk_1.default.green('Service stopped successfully')); } catch (error) { console.log(chalk_1.default.red(`Failed to stop service: ${error}`)); process.exit(1); } } async function restartService() { console.log(chalk_1.default.cyan('Restarting Forge CLI service...')); try { await autoRestart_1.AutoRestartService.stopAutoRestart(); console.log(chalk_1.default.gray('Service stopped')); // Wait a moment before restarting await new Promise(resolve => setTimeout(resolve, 2000)); await autoRestart_1.AutoRestartService.startAutoRestart(); console.log(chalk_1.default.green('Service restarted successfully')); } catch (error) { console.log(chalk_1.default.red(`Failed to restart service: ${error}`)); process.exit(1); } } async function showServiceStatus() { console.log(chalk_1.default.blue('Forge CLI Service Status')); console.log(); const systemInfo = (0, system_1.getSystemInfo)(); const autoRestartEnabled = await autoRestart_1.AutoRestartService.isAutoRestartEnabled(); console.log(chalk_1.default.blue('Service Information:')); console.log(` ${chalk_1.default.cyan('Auto-restart:')} ${autoRestartEnabled ? chalk_1.default.green('Configured') : chalk_1.default.red('Not configured')}`); console.log(` ${chalk_1.default.cyan('Platform:')} ${systemInfo.platform}`); console.log(` ${chalk_1.default.cyan('System uptime:')} ${Math.floor(systemInfo.uptime / 3600)} hours`); console.log(); if (autoRestartEnabled) { console.log(chalk_1.default.green('✓ Auto-restart service is configured')); console.log(chalk_1.default.gray(' The CLI will automatically restart after system reboots')); console.log(); console.log(chalk_1.default.blue('Available commands:')); console.log(chalk_1.default.gray(' forge service --start Start the service')); console.log(chalk_1.default.gray(' forge service --stop Stop the service')); console.log(chalk_1.default.gray(' forge service --restart Restart the service')); } else { console.log(chalk_1.default.yellow('⚠ Auto-restart service is not configured')); console.log(chalk_1.default.gray(' Run "forge setup --auto-restart" to enable auto-restart')); } } //# sourceMappingURL=service.js.map