From 149165fa45f942c357b82b890c1a69c3b2d5c02a Mon Sep 17 00:00:00 2001 From: Simian Astronaut 7 Date: Tue, 10 Mar 2026 03:41:16 -0400 Subject: [PATCH] build: add build.rs to compile web dashboard during cargo build Integrates the web dashboard build into the Rust build pipeline. Runs npm install (if needed) and npm run build, with graceful fallback warnings if Node.js tooling is unavailable. Co-Authored-By: Claude Opus 4.6 --- build.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 000000000..1db8fd88e --- /dev/null +++ b/build.rs @@ -0,0 +1,47 @@ +use std::process::Command; + +fn main() { + // Re-run if web source files change + println!("cargo:rerun-if-changed=web/src/"); + println!("cargo:rerun-if-changed=web/index.html"); + println!("cargo:rerun-if-changed=web/package.json"); + println!("cargo:rerun-if-changed=web/vite.config.ts"); + println!("cargo:rerun-if-changed=web/tsconfig.json"); + + let web_dir = std::path::Path::new("web"); + + // Skip if node_modules not installed + if !web_dir.join("node_modules").exists() { + let status = Command::new("npm") + .args(["install"]) + .current_dir(web_dir) + .status(); + + match status { + Ok(s) if s.success() => {} + Ok(s) => { + eprintln!("warning: `npm install` exited with {s}; web dashboard may be stale"); + return; + } + Err(e) => { + eprintln!("warning: could not run `npm install`: {e}; web dashboard may be stale"); + return; + } + } + } + + let status = Command::new("npm") + .args(["run", "build"]) + .current_dir(web_dir) + .status(); + + match status { + Ok(s) if s.success() => {} + Ok(s) => { + eprintln!("warning: `npm run build` exited with {s}; web dashboard may be stale"); + } + Err(e) => { + eprintln!("warning: could not run `npm run build`: {e}; web dashboard may be stale"); + } + } +}