-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathbuild.rs
More file actions
52 lines (46 loc) · 1.63 KB
/
build.rs
File metadata and controls
52 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::process::Command;
fn main() {
if std::env::var("SPACEBOT_SKIP_FRONTEND_BUILD").is_ok() {
return;
}
// Re-run if interface source files change
println!("cargo:rerun-if-changed=interface/src/");
println!("cargo:rerun-if-changed=interface/index.html");
println!("cargo:rerun-if-changed=interface/package.json");
println!("cargo:rerun-if-changed=interface/vite.config.ts");
println!("cargo:rerun-if-changed=interface/tailwind.config.ts");
let interface_dir = std::path::Path::new("interface");
// Skip if bun isn't installed or node_modules is missing (CI without frontend deps)
if !interface_dir.join("node_modules").exists() {
eprintln!(
"cargo:warning=interface/node_modules not found, skipping frontend build. Run `bun install` in interface/"
);
ensure_dist_dir();
return;
}
let status = Command::new("bun")
.args(["run", "build"])
.current_dir(interface_dir)
.status();
match status {
Ok(s) if s.success() => {}
Ok(s) => {
eprintln!(
"cargo:warning=frontend build exited with {s}, the binary will serve a stale or empty UI"
);
}
Err(e) => {
eprintln!(
"cargo:warning=failed to run `bun run build`: {e}. Install bun to build the frontend."
);
ensure_dist_dir();
}
}
}
/// rust-embed requires the folder to exist even if empty.
fn ensure_dist_dir() {
let dist = std::path::Path::new("interface/dist");
if !dist.exists() {
std::fs::create_dir_all(dist).ok();
}
}