-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
46 lines (40 loc) · 1.44 KB
/
build.rs
File metadata and controls
46 lines (40 loc) · 1.44 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
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=ui/src");
println!("cargo:rerun-if-changed=ui/static");
println!("cargo:rerun-if-changed=ui/svelte.config.js");
println!("cargo:rerun-if-changed=ui/package.json");
if std::env::var("SKIP_UI_BUILD").is_ok() {
let build_dir = std::path::Path::new("ui/build");
if !build_dir.exists() {
std::fs::create_dir_all(build_dir).unwrap();
std::fs::write(
build_dir.join("index.html"),
"<h1>Binary was compiled with SKIP_UI_BUILD</h1>",
)
.unwrap();
}
return;
}
let ui_dir = std::path::Path::new("ui");
let build_dir = ui_dir.join("build");
// Clean previous build (removes stub from SKIP_UI_BUILD if present)
if build_dir.exists() {
std::fs::remove_dir_all(&build_dir).unwrap();
}
// Install dependencies if node_modules is missing
if !ui_dir.join("node_modules").exists() {
let status = Command::new("npm")
.arg("install")
.current_dir(ui_dir)
.status()
.expect("failed to run npm install");
assert!(status.success(), "npm install failed");
}
let status = Command::new("npm")
.args(["run", "build"])
.current_dir(ui_dir)
.status()
.expect("failed to run npm build");
assert!(status.success(), "SvelteKit build failed");
}