diff options
Diffstat (limited to 'website/website-gen/src')
-rw-r--r-- | website/website-gen/src/main.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/website/website-gen/src/main.rs b/website/website-gen/src/main.rs deleted file mode 100644 index 7d35a37cf..000000000 --- a/website/website-gen/src/main.rs +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | use std::{fs, path::Path, process::Command}; | ||
2 | |||
3 | type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
4 | |||
5 | /// This tool builds the github-pages website to the `./target/website` folder | ||
6 | fn main() { | ||
7 | if let Err(err) = try_main() { | ||
8 | eprintln!("{}", err); | ||
9 | std::process::exit(-1); | ||
10 | } | ||
11 | } | ||
12 | |||
13 | fn try_main() -> Result<()> { | ||
14 | check_cwd()?; | ||
15 | build_scaffold()?; | ||
16 | build_docs()?; | ||
17 | println!("Finished\n./target/website/index.html"); | ||
18 | Ok(()) | ||
19 | } | ||
20 | |||
21 | fn cargo() -> Command { | ||
22 | Command::new("cargo") | ||
23 | } | ||
24 | |||
25 | fn check_cwd() -> Result<()> { | ||
26 | let toml = std::fs::read_to_string("./Cargo.toml")?; | ||
27 | if !toml.contains("[workspace]") { | ||
28 | Err("website-gen should be run from the root of workspace")?; | ||
29 | } | ||
30 | Ok(()) | ||
31 | } | ||
32 | |||
33 | fn build_docs() -> Result<()> { | ||
34 | let status = cargo().args(&["doc", "--all", "--no-deps"]).status()?; | ||
35 | if !status.success() { | ||
36 | Err("cargo doc failed")?; | ||
37 | } | ||
38 | sync_dir("./target/doc", "./target/website/api-docs")?; | ||
39 | Ok(()) | ||
40 | } | ||
41 | |||
42 | fn build_scaffold() -> Result<()> { | ||
43 | sync_dir("./website/src", "./target/website") | ||
44 | } | ||
45 | |||
46 | fn sync_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> { | ||
47 | return sync_dir(src.as_ref(), dst.as_ref()); | ||
48 | |||
49 | fn sync_dir(src: &Path, dst: &Path) -> Result<()> { | ||
50 | let _ = fs::remove_dir_all(dst); | ||
51 | fs::create_dir_all(dst)?; | ||
52 | for entry in walkdir::WalkDir::new(src) { | ||
53 | let entry = entry?; | ||
54 | let src_path = entry.path(); | ||
55 | let dst_path = dst.join(src_path.strip_prefix(src)?); | ||
56 | if src_path.is_dir() { | ||
57 | fs::create_dir_all(dst_path)?; | ||
58 | } else { | ||
59 | fs::copy(src_path, dst_path)?; | ||
60 | } | ||
61 | } | ||
62 | Ok(()) | ||
63 | } | ||
64 | } | ||