import { Command } from "commander"; import chalk from "chalk"; import execa from "execa"; import { logger } from "../utils/logger"; export function devCommand(program: Command): void { program .command("dev") .description("Start the development server") .option("-p, --port ", "Port to run the server on", "3000") .option("-h, --host ", "Host to run the server on", "localhost") .action(async (options) => { logger.info( `Starting development server on ${chalk.bold(`http://${options.host}:${options.port}`)}` ); try { // Run the Next.js development server const subprocess = execa( "npm", [ "run", "dev", "--", "-p", options.port, "-H", options.host, ], { stdio: "inherit", } ); // Handle process termination process.on("SIGINT", () => { subprocess.kill("SIGINT"); process.exit(0); }); // Wait for the subprocess to exit await subprocess; } catch (error) { logger.error( `Failed to start development server: ${(error as Error).message}` ); process.exit(1); } }); }