-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
127 lines (112 loc) · 3.55 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use std::process::Command;
fn main() {
let build_date = build_data::format_date(build_data::now());
let profile = std::env::var("PROFILE").expect("PROFILE");
let is_debug = profile == "debug";
let npm_cmds = vec![
vec!["install"],
vec!["run", if is_debug { "build-dev" } else { "build" }],
];
for cmd in &npm_cmds {
let status = Command::new("npm").args(cmd).status().unwrap_or_else(|_| {
panic!("Failed to run npm commands: {cmd:?}");
});
if !status.success() {
panic!("Failed to run npm commands: {cmd:?}");
}
}
fn mkdir(dir: &str) {
if std::fs::metadata(dir).is_ok() {
return;
}
if let Err(err) = std::fs::create_dir_all(dir) {
panic!("Failed to create directory {dir}: {err:?}");
}
}
mkdir("static");
mkdir("static/icons");
mkdir("static/scripts");
mkdir("static/scripts/bundles");
mkdir("static/scripts/vendor");
let copies = vec![
(
!is_debug,
"node_modules/htmx.org/dist/htmx.js",
"static/scripts/vendor/htmx.js",
),
(
is_debug,
"node_modules/htmx.org/dist/htmx.min.js",
"static/scripts/vendor/htmx.js",
),
(
true,
"node_modules/htmx-ext-loading-states/loading-states.js",
"static/scripts/vendor/htmx.loading-states.js",
),
(
true,
"node_modules/lucide-static/font/lucide.css",
"static/icons/lucide.css",
),
(
true,
"node_modules/lucide-static/font/lucide.eot",
"static/icons/lucide.eot",
),
(
true,
"node_modules/lucide-static/font/lucide.woff",
"static/icons/lucide.woff",
),
(
true,
"node_modules/lucide-static/font/lucide.woff2",
"static/icons/lucide.woff2",
),
(
true,
"node_modules/lucide-static/font/lucide.ttf",
"static/icons/lucide.ttf",
),
(
true,
"node_modules/lucide-static/font/lucide.svg",
"static/icons/lucide.svg",
),
];
for (go, src, dest) in &copies {
if *go {
if let Ok(dest_meta) = std::fs::metadata(dest) {
let src_meta = std::fs::metadata(src).unwrap_or_else(|_| {
panic!("Failed to get metadata of {src}");
});
if src_meta.modified().unwrap() <= dest_meta.modified().unwrap() {
continue;
}
}
if let Err(err) = std::fs::copy(src, dest) {
panic!("Failed to copy {src} to {dest}: {err:?}");
}
}
}
let status = Command::new("npx")
.arg("tsc")
.arg("-noEmit")
.status()
.unwrap_or_else(|_| {
panic!("Failed to run tsc");
});
if !status.success() {
panic!("Failed to run tsc");
}
println!("cargo:rerun-if-changed=scripts");
println!("cargo:rerun-if-changed=style");
println!("cargo:rerun-if-changed=templates");
println!("cargo:rerun-if-changed=package.json");
println!("cargo:rerun-if-changed=postcss.config.js");
println!("cargo:rerun-if-changed=tailwind.config.js");
println!("cargo:rerun-if-changed=tsconfig.json");
println!("cargo:rustc-env=CARGO_PROFILE={profile}");
println!("cargo:rustc-env=CARGO_BUILD_DATE={build_date}");
}