-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.rs
More file actions
75 lines (70 loc) · 2.32 KB
/
bundle.rs
File metadata and controls
75 lines (70 loc) · 2.32 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::parser::Parser;
use prost::Message;
use std::fs;
use std::io::Write;
pub fn bundle(path: Option<String>, out: Option<String>) {
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
let out_path = out.unwrap_or_else(|| "./bundles".to_string());
match fs::create_dir_all(&out_path) {
Ok(_) => {}
Err(err) => {
panic!("Error creating output directory: {:?}", err);
}
}
let parser = match Parser::from_path(dir_path.as_str()) {
Some(reader) => reader,
None => {
panic!("Error reading definitions");
}
};
for feature in parser.features {
feature.data_types.iter().for_each(|data_type| {
let mut buf = Vec::new();
if data_type.encode(&mut buf).is_ok() {
let path = format!(
"{}/{}_{}_{}.pb",
&out_path,
feature.name,
"data_type",
data_type.identifier.to_lowercase()
);
fs::File::create(&path)
.expect("abc")
.write_all(&buf)
.expect("a");
}
});
feature.flow_types.iter().for_each(|flow_type| {
let mut buf = Vec::new();
if flow_type.encode(&mut buf).is_ok() {
let path = format!(
"{}/{}_{}_{}.pb",
&out_path,
feature.name,
"flow_type",
flow_type.identifier.to_lowercase()
);
fs::File::create(&path)
.expect("abc")
.write_all(&buf)
.expect("a");
}
});
feature.runtime_functions.iter().for_each(|function| {
let mut buf = Vec::new();
if function.encode(&mut buf).is_ok() {
let path = format!(
"{}/{}_{}_{}.pb",
&out_path,
feature.name,
"function",
function.runtime_name.to_lowercase()
);
fs::File::create(&path)
.expect("abc")
.write_all(&buf)
.expect("a");
}
});
}
}