diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6955b9..edc08ff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/cli/src/command/publish.rs b/cli/src/command/publish.rs index dbcedc3..6b3e7ea 100644 --- a/cli/src/command/publish.rs +++ b/cli/src/command/publish.rs @@ -245,7 +245,26 @@ fn write_modules(modules: &[Module], out_dir_path: &str) { } } -pub async fn publish(version: String, in_path: Option, out_path: Option) { +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, + out_path: Option, + 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()); @@ -266,5 +285,9 @@ pub async fn publish(version: String, in_path: Option, 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()); + } } diff --git a/cli/src/main.rs b/cli/src/main.rs index 5c16e0b..615f323 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -93,6 +93,11 @@ enum Commands { /// Optional path to generated output directory. #[arg(short, long)] out: Option, + /// Instead of writing one file per definition, write a single + /// compact `.json` file per module containing the full + /// Module protobuf message. + #[arg(short, long, default_value_t = false)] + compact: bool, }, Download { #[arg(short, long)] @@ -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, } }