-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
55 lines (45 loc) · 1.39 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
52
53
54
55
use std::{
env, fs,
path::{Path, PathBuf},
process::Command,
};
use anyhow::Context;
pub fn main() {
let out_dir = env::var("OUT_DIR").expect("could not find 'out_dir'");
let cargo_target_dir =
get_cargo_target_dir(Path::new(&out_dir)).expect("could not find 'target_dir'");
let root_dir = cargo_target_dir
.parent()
.expect("could not find 'root_dir'");
let root_style_path = root_dir.join("style").join("lumx");
let root_style_ui_path = root_style_path.join("lumx-ui.scss");
fs::create_dir_all(&root_style_path).unwrap();
Command::new("npx")
.args([
"tailwindcss",
"-i",
"./tailwind-entry.css",
"-o",
&root_style_ui_path.to_str().unwrap(),
])
.status()
.expect("unable to build lumx styles");
}
fn get_cargo_target_dir(out_dir: impl AsRef<Path>) -> anyhow::Result<PathBuf> {
let mut target_dir = None;
let mut sub_path = out_dir.as_ref();
while let Some(parent) = sub_path.parent() {
if parent.ends_with("target") {
target_dir = Some(parent);
break;
}
sub_path = parent;
}
let target_dir = target_dir.with_context(|| {
format!(
"Could not find `target` dir in parents of {}",
out_dir.as_ref().display()
)
})?;
Ok(target_dir.to_path_buf())
}