-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
- Loading branch information
1 parent
603cd14
commit f57e119
Showing
8 changed files
with
171 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
**/*.rs.bk | ||
/src/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
extern crate reqwest; | ||
extern crate vergen; | ||
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/vue@3.0.5/dist/vue.global.js", | ||
"https://unpkg.com/highlight.js@10.6.0/styles/github.css", | ||
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.6.0/highlight.min.js", | ||
] { | ||
let mut resp = reqwest::blocking::get(remote_file) | ||
.expect(&format!("Failed to download vue file: {remote_file}")); | ||
|
||
let filename = remote_file.split('/').last().unwrap(); | ||
let vue_file_path = | ||
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(format!("src/html/{filename}")); | ||
let mut output_file = std::fs::File::create(&vue_file_path) | ||
.expect(&format!("Failed to create vue file: {vue_file_path:?}")); | ||
std::io::copy(&mut resp, &mut output_file).expect("Failed to copy content."); | ||
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."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.