-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
48 lines (43 loc) · 1.14 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
use std::path::PathBuf;
use std::process::{exit, Command};
use std::{env, fs};
fn is_program_in_path(program: &str) -> bool {
if let Ok(path) = env::var("PATH") {
for p in path.split(':') {
let p_str = format!("{}/{}", p, program);
if fs::metadata(p_str).is_ok() {
return true;
}
}
}
false
}
fn main() {
println!("cargo:rerun-if-changed=static_src/tailwind.config.ts");
println!("cargo:rerun-if-changed=static_src/src");
let path = PathBuf::from("static/css/bundle.css");
if !path.exists() {
println!("cargo:rerun-if-changed=static/css/bundle.css");
}
if !is_program_in_path("yarn") {
eprintln!("yarn is missing");
exit(1);
}
env::set_current_dir("static_src").unwrap();
//in development mode we compile without minification
#[cfg(debug_assertions)]
match Command::new("yarn").args(["compile"]).spawn() {
Ok(_) => (),
Err(e) => {
eprintln!("{e}");
}
}
//in release mode this compiles tailwind minified and then uses teser and post css to minify everything else
#[cfg(not(debug_assertions))]
match Command::new("yarn").args(["compile:prod"]).spawn() {
Ok(_) => (),
Err(e) => {
eprintln!("{e}");
}
}
}