-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
69 lines (62 loc) · 2.06 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
use std::fs::{read_dir, read_to_string, File};
use std::path::Path;
use std::io::{Error, Write};
// use std::env;
fn main() -> Result<(), Error> {
let paths = read_dir("src/views").unwrap();
let mut contents = "".to_string();
for path in paths {
let path_name = &path.as_ref().unwrap().path().display().to_string();
if path_name.starts_with('_') {
continue;
}
let content = read_to_string(path_name).expect(path_name);
contents.push_str(&format!(
"#[allow(dead_code)]pub static {}: &str = r#\"{}\"#;",
path.unwrap()
.file_name()
.to_str()
.unwrap()
.replace(".html", "")
.to_ascii_uppercase(),
content
.lines()
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.collect::<Vec<&str>>()
.join("")
));
}
if Path::new("src/html.rs").exists() {
if contents != read_to_string("src/html.rs")? {
let mut output = File::create("src/html.rs")?;
write!(output, "{}", contents)?;
}
} else {
let mut output = File::create("src/html.rs")?;
write!(output, "{}", contents)?;
}
let paths = read_dir("./").unwrap();
for path in paths {
println!("File name: {}", path.unwrap().path().display())
}
// export .env
// if Path::new(".env").exists() {
// let env_contents = read_to_string(".env")?;
// for line in env_contents.split("\n") {
// if line.starts_with("#") {
// continue;
// };
// let mut kv: Vec<&str> = line.splitn(2, "=").collect();
// if let Some(sp) = kv[1].strip_prefix("'") {
// kv[1] = sp;
// }
// if let Some(ss) = kv[1].strip_suffix("'") {
// kv[1] = ss;
// }
// println!("{} = {}", kv[0], kv[1]);
// env::set_var(kv[0], kv[1]);
// }
// }
Ok(())
}