1+ use std:: fs;
2+ use std:: io:: Write ;
3+ use prost:: Message ;
4+ use code0_definition_reader:: parser:: Parser ;
5+
6+ pub fn bundle ( path : Option < String > , out : Option < String > ) {
7+ let dir_path = path. unwrap_or_else ( || "./definitions" . to_string ( ) ) ;
8+ let out_path = out. unwrap_or_else ( || "./bundles" . to_string ( ) ) ;
9+ match fs:: create_dir_all ( & out_path) {
10+ Ok ( _) => { }
11+ Err ( err) => {
12+ panic ! ( "Error creating output directory: {:?}" , err) ;
13+ }
14+ }
15+
16+ let parser = match Parser :: from_path ( dir_path. as_str ( ) ) {
17+ Some ( reader) => reader,
18+ None => {
19+ panic ! ( "Error reading definitions" ) ;
20+ }
21+ } ;
22+
23+ for feature in parser. features {
24+ feature. data_types . iter ( ) . for_each ( |data_type| {
25+ let mut buf = Vec :: new ( ) ;
26+ if let Ok ( _) = data_type. encode ( & mut buf) {
27+ let path = format ! ( "{}/{}_{}_{}.pb" , & out_path, feature. name, "data_type" , data_type. identifier. to_lowercase( ) ) ;
28+ fs:: File :: create ( & path) . expect ( "abc" ) . write_all ( & buf) . expect ( "a" ) ;
29+ }
30+ } ) ;
31+
32+ feature. flow_types . iter ( ) . for_each ( |flow_type| {
33+ let mut buf = Vec :: new ( ) ;
34+ if let Ok ( _) = flow_type. encode ( & mut buf) {
35+ let path = format ! ( "{}/{}_{}_{}.pb" , & out_path, feature. name, "flow_type" , flow_type. identifier. to_lowercase( ) ) ;
36+ fs:: File :: create ( & path) . expect ( "abc" ) . write_all ( & buf) . expect ( "a" ) ;
37+ }
38+ } ) ;
39+
40+ feature. runtime_functions . iter ( ) . for_each ( |function| {
41+ let mut buf = Vec :: new ( ) ;
42+ if let Ok ( _) = function. encode ( & mut buf) {
43+ let path = format ! ( "{}/{}_{}_{}.pb" , & out_path, feature. name, "function" , function. runtime_name. to_lowercase( ) ) ;
44+ fs:: File :: create ( & path) . expect ( "abc" ) . write_all ( & buf) . expect ( "a" ) ;
45+ }
46+ } ) ;
47+ }
48+ }
0 commit comments