-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbuild.rs
42 lines (39 loc) · 1.22 KB
/
build.rs
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
use anyhow::Result;
use std::env;
use std::process::Command;
fn main() -> Result<()> {
let _ = vergen::EmitBuilder::builder().git_sha(true).emit();
println!("cargo:rerun-if-changed=package.json");
println!("cargo:rerun-if-changed=package-lock.json");
match Command::new("npm").arg("install").spawn() {
Err(_proc) => {
println!("Build requires npm, but it was not found. Please install Node >= 16.16.0.");
std::process::exit(1);
}
Ok(mut child) => {
let status = child.wait()?;
if !status.success() {
println!("Command \"npm install\" failed.");
std::process::exit(1);
}
}
}
let jsdir = format!("{}/js", env::var("OUT_DIR").unwrap());
println!("cargo:rustc-env=JS_DIR={}", jsdir);
println!("cargo:rerun-if-changed=src/html_files/");
let status = Command::new("npm")
.arg("exec")
.arg("--")
.arg("tsc")
.arg("-p")
.arg("src/html_files/")
.arg("--outDir")
.arg(jsdir)
.spawn()?
.wait()?;
if !status.success() {
println!("Failed to compile typescript.");
std::process::exit(1);
}
Ok(())
}