-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
51 lines (45 loc) · 1.34 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
43
44
45
46
47
48
49
50
51
use std::{
io::Write,
process::{Command, Output},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=./ui/src");
println!("cargo:rerun-if-changed=./ui/public");
println!("cargo:rerun-if-changed=./ui/package.json");
println!("cargo:rerun-if-changed=./ui/tailwind.config.js");
// Don't include sourcemaps
std::env::set_var("GENERATE_SOURCEMAP", "false");
handle_output(
Command::new("npm")
.args(["ci", "--prefix", "ui"])
.output()?,
"npm ci",
)?;
handle_output(
Command::new("npm")
.args(["run", "build", "--prefix", "ui"])
.output()?,
"npm run build",
)?;
Ok(())
}
fn handle_output(
output: Output,
command_description: &str,
) -> Result<(), Box<dyn std::error::Error>> {
if !output.status.success() {
let mut stderr = std::io::stderr();
stderr
.write_all(b"Error when running npm install.\nStdout:\n\n")
.unwrap();
stderr.write_all(&output.stdout).unwrap();
stderr.write_all(b"\n\nStderr:\n\n").unwrap();
stderr.write_all(&output.stderr).unwrap();
return Err(format!(
"Unable to run {}. See stdout and stderr output above",
command_description
)
.into());
}
Ok(())
}