a reactive (signals based) hypermedia web framework (wip)
stormlightlabs.github.io/volt/
hypermedia
frontend
signals
1import { echo } from "$utils/echo.js";
2import { spawn } from "node:child_process";
3
4/**
5 * Builds the VoltX.js project for production using Vite.
6 */
7export async function buildCommand(options: { outDir?: string } = {}): Promise<void> {
8 const outDir = options.outDir || "dist";
9
10 echo.title("\n⚡ Building VoltX.js project for production...\n");
11
12 try {
13 const { existsSync } = await import("node:fs");
14 if (!existsSync("index.html")) {
15 echo.warn("Warning: No index.html found in current directory");
16 echo.info("Are you in a VoltX.js project?\n");
17 }
18
19 const viteArgs = ["vite", "build", "--outDir", outDir];
20 const viteProcess = spawn("npx", viteArgs, { stdio: "inherit", shell: true });
21
22 viteProcess.on("error", (error) => {
23 echo.err("Failed to build project:", error);
24 process.exit(1);
25 });
26
27 viteProcess.on("exit", (code) => {
28 if (code === 0) {
29 echo.success(`\n✓ Build completed successfully!\n`);
30 echo.info(`Output directory: ${outDir}\n`);
31 } else if (code !== null) {
32 process.exit(code);
33 }
34 });
35 } catch (error) {
36 echo.err("Error building project:", error);
37 process.exit(1);
38 }
39}