-
Notifications
You must be signed in to change notification settings - Fork 28
/
build.rs
31 lines (24 loc) · 1.13 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
use std::{fs::File, io, path::Path};
use vergen::{vergen, Config};
fn main() {
// Generate the 'cargo:' key output
vergen(Config::default()).expect("Something is wrong!");
let artifacts_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/html/");
std::fs::create_dir_all(&artifacts_dir).expect("failed to create a dir");
for remote_file in [
"https://unpkg.com/[email protected]/dist/vue.global.js",
"https://unpkg.com/[email protected]/styles/github.css",
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.6.0/highlight.min.js",
] {
download_file(remote_file, &artifacts_dir);
}
}
fn download_file(remote_file: &str, dir: &Path) {
let mut resp = reqwest::blocking::get(remote_file)
.unwrap_or_else(|_| panic!("Failed to download vue file: {}", remote_file));
let filename = remote_file.split('/').last().unwrap();
let file_path = dir.join(filename);
let mut output_file = File::create(&file_path)
.unwrap_or_else(|_| panic!("Failed to create artifact file: {:?}", file_path));
io::copy(&mut resp, &mut output_file).expect("Failed to copy content.");
}