-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
55 lines (47 loc) · 1.63 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
const NM_FILES_TO_COPY: [&str; 6] = [
"jquery/dist/jquery.slim.js",
"bootstrap/dist/css/bootstrap.css",
"bootstrap/dist/js/bootstrap.bundle.js",
"bootstrap-icons/bootstrap-icons.svg",
"video.js/dist/video.js",
"video.js/dist/video-js.css",
];
const NM_TARGET_DIR: &str = "static/assets/";
const CLIENT_SRC_DIR: &str = "client-src/";
use std::fs::copy;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let mut package_json = PathBuf::from(&CLIENT_SRC_DIR);
package_json.push("package.json");
println!("cargo:rerun-if-changed={}", &package_json.to_string_lossy());
/*
let output = Command::new("npm")
.args(&["install"])
.current_dir(Path::new(&CLIENT_SRC_DIR))
.output()
.expect("Failed to execute npm install");
if !output.status.success() {
panic!("Error during npm install");
}
*/
let nm_dir = format!("{}node_modules/", CLIENT_SRC_DIR);
for file in &NM_FILES_TO_COPY {
let mut source = PathBuf::from(&nm_dir);
source.push(file);
println!("cargo:rerun-if-changed={}", &source.to_string_lossy());
let file_name = source.file_name().expect(&format!(
"Failed to get filename from source file {}",
&file
));
let mut target = PathBuf::from(NM_TARGET_DIR);
target.push(file_name);
copy(&source, &target).expect(&format!(
"Failed to copy file from {} to {}",
&source.to_string_lossy(),
&target.to_string_lossy()
));
println!("cargo:rerun-if-changed={}", &target.to_string_lossy());
}
}