redirector-cli
Version:
Global CLI tool for managing Redirector backend services with Docker Compose
178 lines • 6.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const logger_1 = require("../utils/logger");
const setup_1 = require("../commands/setup");
const start_1 = require("../commands/start");
const stop_1 = require("../commands/stop");
const restart_1 = require("../commands/restart");
const reset_1 = require("../commands/reset");
const status_1 = require("../commands/status");
const logs_1 = require("../commands/logs");
const program = new commander_1.Command();
// CLI Information
program
.name("redirector")
.description("Global CLI tool for managing Redirector backend services")
.version("1.0.0")
.option("-d, --debug", "Enable debug output")
.hook("preAction", (thisCommand) => {
const options = thisCommand.opts();
if (options.debug) {
process.env.DEBUG = "true";
}
});
// Setup command
program
.command("setup")
.description("Initialize a new Redirector project in the current directory")
.option("-p, --port <number>", "Backend API port", (val) => parseInt(val, 10))
.option("--postgres-port <number>", "PostgreSQL port", (val) => parseInt(val, 10))
.option("-u, --docker-username <username>", "Docker Hub username")
.option("-f, --force", "Overwrite existing configuration")
.option("--no-interactive", "Skip interactive prompts")
.action(async (options) => {
try {
await (0, setup_1.setupCommand)(options);
}
catch (error) {
logger_1.Logger.error(`Setup failed: ${error}`);
process.exit(1);
}
});
// Start command
program
.command("start")
.description("Start all Redirector services")
.option("--no-detach", "Run in foreground (not detached)")
.option("--pull", "Pull latest images before starting")
.option("--build", "Build images before starting")
.action(async (options) => {
try {
await (0, start_1.startCommand)(options);
}
catch (error) {
logger_1.Logger.error(`Start failed: ${error}`);
process.exit(1);
}
});
// Stop command
program
.command("stop")
.description("Stop all Redirector services")
.option("-v, --remove-volumes", "Also remove volumes and data")
.action(async (options) => {
try {
await (0, stop_1.stopCommand)(options);
}
catch (error) {
logger_1.Logger.error(`Stop failed: ${error}`);
process.exit(1);
}
});
// Restart command
program
.command("restart")
.description("Restart all Redirector services")
.option("--pull", "Pull latest images before restarting")
.action(async (options) => {
try {
await (0, restart_1.restartCommand)(options);
}
catch (error) {
logger_1.Logger.error(`Restart failed: ${error}`);
process.exit(1);
}
});
// Reset command
program
.command("reset")
.description("Stop services and remove all data and volumes")
.option("-f, --force", "Skip confirmation prompt")
.option("-y, --confirm", "Automatically confirm reset")
.action(async (options) => {
try {
await (0, reset_1.resetCommand)(options);
}
catch (error) {
logger_1.Logger.error(`Reset failed: ${error}`);
process.exit(1);
}
});
// Status command
program
.command("status")
.description("Show status of all services")
.option("-j, --json", "Output status as JSON")
.option("-v, --verbose", "Show detailed information")
.action(async (options) => {
try {
await (0, status_1.statusCommand)(options);
}
catch (error) {
logger_1.Logger.error(`Status check failed: ${error}`);
process.exit(1);
}
});
// Logs command
program
.command("logs [service]")
.description("Show logs for services (backend, postgres, or all)")
.option("-f, --follow", "Follow log output")
.option("-t, --tail <number>", "Number of lines to show from end of logs", (val) => parseInt(val, 10))
.action(async (service, options) => {
try {
await (0, logs_1.logsCommand)(service, options);
}
catch (error) {
logger_1.Logger.error(`Logs command failed: ${error}`);
process.exit(1);
}
});
// Help command customization
program.on("--help", () => {
console.log("");
console.log("Examples:");
console.log(" $ redirector setup # Initialize project interactively");
console.log(" $ redirector setup --port 8080 # Initialize with custom port");
console.log(" $ redirector start # Start all services");
console.log(" $ redirector start --pull # Pull latest images and start");
console.log(" $ redirector status # Check service status");
console.log(" $ redirector logs backend # Show backend logs");
console.log(" $ redirector logs --follow # Follow all logs");
console.log(" $ redirector stop # Stop services");
console.log(" $ redirector reset --force # Reset without confirmation");
console.log("");
console.log("For more information, visit:");
console.log(" https://github.com/shivarajbakale/redirector-app");
});
// Error handling
process.on("unhandledRejection", (reason, promise) => {
logger_1.Logger.error(`Unhandled Rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});
process.on("uncaughtException", (error) => {
logger_1.Logger.error(`Uncaught Exception: ${error.message}`);
process.exit(1);
});
// Graceful shutdown
process.on("SIGINT", () => {
logger_1.Logger.newLine();
logger_1.Logger.info("Received SIGINT, shutting down gracefully...");
logger_1.Logger.stopSpinner();
process.exit(0);
});
process.on("SIGTERM", () => {
logger_1.Logger.newLine();
logger_1.Logger.info("Received SIGTERM, shutting down gracefully...");
logger_1.Logger.stopSpinner();
process.exit(0);
});
// Parse command line arguments
program.parse();
// Show help if no command provided
if (!process.argv.slice(2).length) {
program.outputHelp();
}
//# sourceMappingURL=redirector.js.map