Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#*-}" # removes everything up to the first dash
cargo run -- publish --version "$VERSION" --path definitions --out out
cargo run -- publish --version "$VERSION" --path definitions --out out --compact
rm -rf definitions
mv out definitions

Expand Down
27 changes: 25 additions & 2 deletions cli/src/command/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,26 @@ fn write_modules(modules: &[Module], out_dir_path: &str) {
}
}

pub async fn publish(version: String, in_path: Option<String>, out_path: Option<String>) {
fn write_modules_compact(modules: &[Module], out_dir_path: &str) {
let out_dir_path = PathBuf::from(out_dir_path);

if out_dir_path.exists() {
fs::remove_dir_all(&out_dir_path).expect("Error deleting output folder");
}
fs::create_dir_all(&out_dir_path).expect("Error creating output folder");

for module in modules {
let module_path = out_dir_path.join(format!("{}.json", safe_file_name(&module.identifier)));
write_json_file(&module_path, module);
}
}

pub async fn publish(
version: String,
in_path: Option<String>,
out_path: Option<String>,
compact: bool,
) {
let in_dir_path = in_path.unwrap_or_else(|| "./definitions".to_string());
let out_dir_path = out_path.unwrap_or_else(|| "./out".to_string());

Expand All @@ -266,5 +285,9 @@ pub async fn publish(version: String, in_path: Option<String>, out_path: Option<
.map(|x| configure_module(&x, version.clone()))
.collect();

write_modules(&modules, out_dir_path.as_str());
if compact {
write_modules_compact(&modules, out_dir_path.as_str());
} else {
write_modules(&modules, out_dir_path.as_str());
}
}
14 changes: 11 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ enum Commands {
/// Optional path to generated output directory.
#[arg(short, long)]
out: Option<String>,
/// Instead of writing one file per definition, write a single
/// compact `<module>.json` file per module containing the full
/// Module protobuf message.
#[arg(short, long, default_value_t = false)]
compact: bool,
},
Download {
#[arg(short, long)]
Expand Down Expand Up @@ -129,8 +134,11 @@ async fn main() {
version,
path,
} => command::push::push(token, url, version, path).await,
Commands::Publish { version, path, out } => {
command::publish::publish(version, path, out).await
}
Commands::Publish {
version,
path,
out,
compact,
} => command::publish::publish(version, path, out, compact).await,
}
}