UNPKG

redirector-cli

Version:

Global CLI tool for managing Redirector backend services with Docker Compose

122 lines 5.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.statusCommand = statusCommand; const logger_1 = require("../utils/logger"); const config_1 = require("../utils/config"); const docker_1 = require("../utils/docker"); async function statusCommand(options) { try { const projectPath = process.cwd(); // Check if project is initialized const isInitialized = await config_1.ConfigManager.isRedirectorProject(projectPath); if (!isInitialized) { logger_1.Logger.error("No Redirector project found in current directory"); logger_1.Logger.info("Run `redirector setup` first to initialize the project"); process.exit(1); } // Load configuration const config = await config_1.ConfigManager.loadConfig(projectPath); const docker = new docker_1.DockerManager(config, projectPath); // Get status const containers = await docker.getStatus(); const health = await docker.checkHealth(); if (options.json) { // JSON output for programmatic use const status = { project: { name: config.projectName, path: projectPath, backendPort: config.backendPort, postgresPort: config.postgresPort, }, services: { backend: health.backend, postgres: health.postgres, }, containers: containers, urls: { backend: `http://localhost:${config.backendPort}`, health: `http://localhost:${config.backendPort}/health`, postgres: `localhost:${config.postgresPort}`, }, }; console.log(JSON.stringify(status, null, 2)); return; } // Human-readable output logger_1.Logger.header("Redirector Service Status"); // Project info logger_1.Logger.subheader("Project Information:"); logger_1.Logger.table({ "Project Name": config.projectName, "Project Path": projectPath, "Backend Port": config.backendPort.toString(), "PostgreSQL Port": config.postgresPort.toString(), Environment: config.environment, }); logger_1.Logger.newLine(); // Service health logger_1.Logger.subheader("Service Health:"); const backendStatus = health.backend ? "✓ Running" : "✗ Not Running"; const postgresStatus = health.postgres ? "✓ Running" : "✗ Not Running"; logger_1.Logger.table({ "Backend API": backendStatus, PostgreSQL: postgresStatus, }); logger_1.Logger.newLine(); // Container details if (containers.length === 0) { logger_1.Logger.warning("No containers found. Run `redirector start` to start services."); } else { logger_1.Logger.subheader("Container Details:"); containers.forEach((container) => { const statusIcon = container.status.includes("running") ? "✓" : "✗"; logger_1.Logger.info(`${statusIcon} ${container.name}`); if (options.verbose) { logger_1.Logger.info(` Status: ${container.status}`); logger_1.Logger.info(` Image: ${container.image}`); if (container.ports) { logger_1.Logger.info(` Ports: ${container.ports}`); } } else { logger_1.Logger.info(` ${container.status}${container.ports ? ` | ${container.ports}` : ""}`); } logger_1.Logger.newLine(); }); } // Access URLs if (health.backend || health.postgres) { logger_1.Logger.subheader("Access URLs:"); const urls = []; if (health.backend) { urls.push(`Backend API: http://localhost:${config.backendPort}`); urls.push(`Health Check: http://localhost:${config.backendPort}/health`); } if (health.postgres) { urls.push(`PostgreSQL: localhost:${config.postgresPort}`); } logger_1.Logger.list(urls); logger_1.Logger.newLine(); } // Helpful commands logger_1.Logger.subheader("Useful Commands:"); const commands = []; if (!health.backend && !health.postgres) { commands.push("`redirector start` - Start all services"); } else { commands.push("`redirector logs` - View service logs"); commands.push("`redirector restart` - Restart services"); commands.push("`redirector stop` - Stop services"); } commands.push("`redirector reset` - Reset all data"); logger_1.Logger.list(commands); } catch (error) { logger_1.Logger.error(`Failed to get status: ${error}`); process.exit(1); } } //# sourceMappingURL=status.js.map