diff --git a/.gitignore b/.gitignore index 4c382ebf..fab6eb73 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ dist/ uploads.txt dist-manifest.json .intentionally-empty-file.o +.DS_Store diff --git a/Cargo.lock b/Cargo.lock index 353d1406..1382e300 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "typeshare-cli" -version = "1.12.0" +version = "1.12.1" dependencies = [ "anyhow", "clap", @@ -714,7 +714,7 @@ dependencies = [ [[package]] name = "typeshare-core" -version = "1.12.0" +version = "1.12.1" dependencies = [ "anyhow", "cool_asserts", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 44c9c9ed..882a1e53 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "typeshare-cli" -version = "1.12.0" +version = "1.12.1" edition = "2021" description = "Command Line Tool for generating language files with typeshare" license = "MIT OR Apache-2.0" @@ -26,7 +26,7 @@ once_cell = "1" rayon = "1.10" serde = { version = "1", features = ["derive"] } toml = "0.8" -typeshare-core = { path = "../core", version = "=1.12.0" } +typeshare-core = { path = "../core", version = "=1.12.1" } log.workspace = true flexi_logger.workspace = true anyhow = "1" diff --git a/core/Cargo.toml b/core/Cargo.toml index aaa38900..987164d7 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "typeshare-core" -version = "1.12.0" +version = "1.12.1" license = "MIT OR Apache-2.0" edition = "2021" description = "The code generator used by Typeshare's command line tool" diff --git a/core/src/language/typescript.rs b/core/src/language/typescript.rs index eecce3b2..770357a5 100644 --- a/core/src/language/typescript.rs +++ b/core/src/language/typescript.rs @@ -216,32 +216,63 @@ impl TypeScript { writeln!(w)?; self.write_comments(w, 1, &v.shared().comments)?; match v { - RustEnumVariant::Unit(shared) => write!( - w, - "\t| {{ {}: {:?}, {}?: undefined }}", - tag_key, shared.id.renamed, content_key - ), + RustEnumVariant::Unit(shared) => { + if !tag_key.is_empty() { + if !content_key.is_empty() { + write!( + w, + "\t| {{ {}: {:?}, {}?: undefined }}", + tag_key, shared.id.renamed, content_key + ) + } else { + write!(w, "\t| {{ {}: {:?} }}", tag_key, shared.id.renamed) + } + } else { + write!(w, "\t| {:?}", shared.id.renamed) + } + } RustEnumVariant::Tuple { ty, shared } => { let r#type = self .format_type(ty, e.shared().generic_types.as_slice()) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; - write!( - w, - "\t| {{ {}: {:?}, {}{}: {} }}", - tag_key, - shared.id.renamed, - content_key, - ty.is_optional().then_some("?").unwrap_or_default(), - r#type - ) + if !tag_key.is_empty() { + if !content_key.is_empty() { + write!( + w, + "\t| {{ {}: {:?}, {}{}: {} }}", + tag_key, + shared.id.renamed, + content_key, + ty.is_optional().then_some("?").unwrap_or_default(), + r#type + ) + } else { + panic!("Tuple variants must have a content key if they have a tag key: {:?}", shared.id.original) + } + } else { + write!( + w, + "\t| {{ {:?}{}: {} }}", + shared.id.renamed, + ty.is_optional().then_some("?").unwrap_or_default(), + r#type + ) + } } RustEnumVariant::AnonymousStruct { fields, shared } => { - writeln!( - w, - "\t| {{ {}: {:?}, {}: {{", - tag_key, shared.id.renamed, content_key - )?; - + if !tag_key.is_empty() { + if !content_key.is_empty() { + writeln!( + w, + "\t| {{ {}: {:?}, {}: {{", + tag_key, shared.id.renamed, content_key + )?; + } else { + panic!("Struct variants must have a content key if they have a tag key: {:?}", shared.id.original) + } + } else { + writeln!(w, "\t| {{ {:?}: {{", shared.id.renamed)?; + } fields.iter().try_for_each(|f| { self.write_field(w, f, e.shared().generic_types.as_slice()) })?; diff --git a/core/src/parser.rs b/core/src/parser.rs index 3cc86c49..ba797a17 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -391,12 +391,8 @@ pub(crate) fn parse_enum(e: &ItemEnum, target_os: &[String]) -> Result VERSION="" +# --dry-run +DRY_RUN=false # Parse command line arguments while [[ $# -gt 0 ]]; do @@ -41,6 +44,10 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --dry-run) + DRY_RUN=true + shift + ;; -h|--help) help ;; @@ -52,12 +59,12 @@ while [[ $# -gt 0 ]]; do done # Check if required arguments are provided -if [ -z "${TARGET}" ]; then +if [[ -z "${TARGET}" ]]; then echo "Missing required argument: --target" exit 1 fi -if [ -z "$VERSION" ]; then +if [[ -z "$VERSION" ]]; then echo "Missing required argument: --version" exit 1 fi @@ -87,9 +94,13 @@ echo "{\"artifacts\": [{\"path\": \"dist/${ZIP_NAME}\"}]}" > dist-manifest.json echo "Build complete, contents of dist-manifest.json:" cat dist-manifest.json -# Upload to release -cat dist-manifest.json | jq --raw-output ".artifacts[]?.path | select( . != null )" > uploads.txt -echo "uploading..." -cat uploads.txt -gh release upload ${VERSION} $(cat uploads.txt) -echo "uploaded!" +if [[ "$DRY_RUN" == true ]]; then + echo "ℹ️ Dry run, skipping release upload" +else + # Upload to release + cat dist-manifest.json | jq --raw-output ".artifacts[]?.path | select( . != null )" > uploads.txt + echo "uploading..." + cat uploads.txt + gh release upload ${VERSION} $(cat uploads.txt) + echo "uploaded!" +fi