Skip to content

Commit 8512da7

Browse files
committed
feat: implemented binary bundling
1 parent ede55e4 commit 8512da7

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

cli/src/command/bundle.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

cli/src/command/definition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::formatter::{info, success};
22
use code0_definition_reader::parser::Parser;
33
use colored::Colorize;
4+
use prost::Message;
5+
use tucana::shared::DefinitionDataType;
46

57
pub fn search_definition(name: String, path: Option<String>) {
68
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());

cli/src/command/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pub mod download;
33
pub mod feature;
44
pub mod report;
55
pub mod watch;
6+
pub mod bundle;

cli/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ enum Commands {
5353
#[clap(short, long, value_parser, num_args = 1.., value_delimiter = ' ')]
5454
features: Option<Vec<String>>,
5555
},
56+
Bundle {
57+
#[arg(short, long)]
58+
path: Option<String>,
59+
#[arg(short, long)]
60+
out: Option<String>,
61+
}
5662
}
5763

5864
#[tokio::main]
5965
async fn main() {
6066
let cli = Cli::parse();
6167

6268
match cli.command {
69+
Commands::Bundle {path, out} => command::bundle::bundle(path, out),
6370
Commands::Report { path } => command::report::report_errors(path),
6471
Commands::Feature { name, path } => command::feature::search_feature(name, path),
6572
Commands::Definition { name, path } => command::definition::search_definition(name, path),

0 commit comments

Comments
 (0)