-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathmain.rs
More file actions
49 lines (41 loc) · 1.47 KB
/
main.rs
File metadata and controls
49 lines (41 loc) · 1.47 KB
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
use std::env;
use std::fs::File;
use std::io::Write;
use std::process::Command;
fn main() {
match feather_blocks_generator::generate() {
Ok(code) => {
let base = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/generated");
let _ = std::fs::create_dir_all(base);
let block_fns = format!("{}/block_fns.rs", base);
let props = format!("{}/properties.rs", base);
let table = format!("{}/table.rs", base);
write_to_file(&block_fns, &code.block_fns);
write_to_file(&props, &code.block_properties);
write_to_file(&table, &code.block_table);
[block_fns, props, table].iter().for_each(|path| {
let _ = Command::new("rustfmt").arg(path).output();
});
let data = format!("{}/table.dat", base);
File::create(&data)
.unwrap()
.write_all(&code.block_table_serialized)
.unwrap();
let data = format!("{}/vanilla_ids.dat", base);
File::create(&data)
.unwrap()
.write_all(&code.vanilla_ids_serialized)
.unwrap();
}
Err(e) => {
eprintln!("An error occurred: {}", e);
std::process::exit(1);
}
}
}
fn write_to_file(path: impl AsRef<str>, s: impl AsRef<str>) {
File::create(path.as_ref())
.unwrap()
.write_all(s.as_ref().as_bytes())
.unwrap();
}