a reactive (signals based) hypermedia web framework (wip) stormlightlabs.github.io/volt/
hypermedia frontend signals
at main 1.3 kB view raw
1import { echo } from "$utils/echo.js"; 2import { spawn } from "node:child_process"; 3 4/** 5 * Starts a Vite development server for the current project. 6 */ 7export async function devCommand(options: { port?: number; open?: boolean } = {}): Promise<void> { 8 const port = options.port || 3000; 9 const shouldOpen = options.open || false; 10 11 echo.title("\n⚡ Starting VoltX.js development server...\n"); 12 13 try { 14 const { existsSync } = await import("node:fs"); 15 if (!existsSync("index.html")) { 16 echo.warn("Warning: No index.html found in current directory"); 17 echo.info("Are you in a VoltX.js project?\n"); 18 } 19 20 const viteArgs = ["vite", "--port", port.toString(), "--host"]; 21 22 if (shouldOpen) { 23 viteArgs.push("--open"); 24 } 25 26 const viteProcess = spawn("npx", viteArgs, { stdio: "inherit", shell: true }); 27 28 viteProcess.on("error", (error) => { 29 echo.err("Failed to start dev server:", error); 30 process.exit(1); 31 }); 32 33 viteProcess.on("exit", (code) => { 34 if (code !== 0 && code !== null) { 35 process.exit(code); 36 } 37 }); 38 39 process.on("SIGINT", () => { 40 viteProcess.kill("SIGINT"); 41 process.exit(0); 42 }); 43 } catch (error) { 44 echo.err("Error starting dev server:", error); 45 process.exit(1); 46 } 47}