node-server-orchestrator
Version:
CLI tool for orchestrating Node.js development servers (backend, frontend, databases, etc.)
134 lines (115 loc) • 3.97 kB
text/typescript
import { Command } from 'commander';
import { ProjectServerManager } from './ProjectServerManager.js';
const program = new Command();
program
.name('project-server-mcp')
.description('CLI for managing project development servers')
.version('1.0.0');
// Start command
program
.command('start <server-id>')
.description('Start a specific server')
.action(async (serverId: string) => {
const manager = new ProjectServerManager();
await manager.loadConfigFromFile('./config.json');
const result = await manager.startServer(serverId);
if (result.success) {
console.log(`✅ ${result.message}`);
console.log(`📊 PID: ${result.pid}`);
console.log(`🌐 Port: ${result.port}`);
} else {
console.error(`❌ ${result.message}`);
process.exit(1);
}
});
// Stop command
program
.command('stop <server-id>')
.description('Stop a specific server')
.action(async (serverId: string) => {
const manager = new ProjectServerManager();
await manager.loadConfigFromFile('./config.json');
const result = await manager.stopServer(serverId);
if (result.success) {
console.log(`✅ ${result.message}`);
} else {
console.error(`❌ ${result.message}`);
process.exit(1);
}
});
// Status command
program
.command('status <server-id>')
.description('Get status of a specific server')
.action(async (serverId: string) => {
const manager = new ProjectServerManager();
await manager.loadConfigFromFile('./config.json');
const status = await manager.getServerStatus(serverId);
const config = manager.getServerConfig(serverId);
if (!config) {
console.error(`❌ Unknown server: ${serverId}`);
process.exit(1);
}
console.log(manager.formatStatusMessage(status, config));
});
// List command
program
.command('list')
.description('List all available servers')
.action(async () => {
const manager = new ProjectServerManager();
await manager.loadConfigFromFile('./config.json');
const servers = manager.listServers();
console.log('📋 Available Servers:');
servers.forEach(id => {
const config = manager.getServerConfig(id);
console.log(` • ${config?.name || id} (${id}) - ${config?.description || 'No description'}`);
});
});
// Start all command
program
.command('start-all')
.description('Start all servers')
.action(async () => {
const manager = new ProjectServerManager();
await manager.loadConfigFromFile('./config.json');
const results = await manager.startAllServers();
console.log('🚀 Starting All Servers:');
Object.entries(results).forEach(([id, result]) => {
const config = manager.getServerConfig(id);
const status = result.success ? '✅' : '❌';
console.log(` ${status} ${config?.name || id}: ${result.message}`);
});
});
// Stop all command
program
.command('stop-all')
.description('Stop all running servers')
.action(async () => {
const manager = new ProjectServerManager();
await manager.loadConfigFromFile('./config.json');
const results = await manager.stopAllServers();
console.log('🛑 Stopping All Servers:');
Object.entries(results).forEach(([id, result]) => {
const config = manager.getServerConfig(id);
const status = result.success ? '✅' : '❌';
console.log(` ${status} ${config?.name || id}: ${result.message}`);
});
});
// MCP server command
program
.command('mcp')
.description('Start as MCP server (for AI agent integration)')
.action(async () => {
const { ProjectServerMCPServer } = await import('./index.js');
const server = new ProjectServerMCPServer();
try {
await server.run();
} catch (error: any) {
console.error('Failed to start MCP server:', error.message);
process.exit(1);
}
});
// Parse command line arguments
program.parse();