Skip to content

Commit

Permalink
fix bundle-id for init/new, closes #396
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Jul 17, 2024
1 parent d5656ec commit 21331c7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-playdate"
version = "0.5.1"
version = "0.5.2"
readme = "README.md"
description = "Build tool for neat yellow console."
keywords = ["playdate", "build", "cargo", "plugin", "cargo-subcommand"]
Expand Down
2 changes: 1 addition & 1 deletion cargo/src/init/full-metadata.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name = "{name}"
author = "{author}"
version = "{version}"
bundle-id = "com.yourcompany.{bundle_id}"
bundle-id = "{bundle_id}"
description = "{description}"

content-warning = "This game contains mild realistic, violence and bloodshed."
Expand Down
20 changes: 15 additions & 5 deletions cargo/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,14 @@ fn add_min_metadata(_config: &Config<'_>, manifest: &mut toml_edit::DocumentMut)
let name = manifest["package"]["name"].as_str()
.unwrap_or("hello-world")
.to_owned();
let bundle_id = name.replace(['_', '-'], ".")
.replace("..", ".")
.replace("..", ".");
let bundle_id = bundle_id_from_crate_name(&name);
let has_description = manifest["package"].as_table()
.map(|t| t.contains_key("description"))
.unwrap_or(false);

let meta = &mut manifest["package"]["metadata"][METADATA_FIELD];

meta["bundle-id"] = value(format!("com.{}", bundle_id.strip_prefix('.').unwrap_or(&bundle_id)));
meta["bundle-id"] = value(bundle_id);
if !has_description {
meta["description"] = value(format!("Description of {name} program."));
}
Expand All @@ -186,7 +184,7 @@ fn add_full_metadata(_config: &Config<'_>, manifest: &mut toml_edit::DocumentMut
let name = manifest["package"]["name"].as_str()
.unwrap_or("hello-world")
.to_owned();
let bundle_id = name.replace(['_', '-'], ".");
let bundle_id = bundle_id_from_crate_name(&name);
let version = manifest["package"]["version"].as_str().unwrap_or("0.0");

let author_default = "You, Inc";
Expand Down Expand Up @@ -234,6 +232,18 @@ fn add_full_metadata(_config: &Config<'_>, manifest: &mut toml_edit::DocumentMut
}


fn bundle_id_from_crate_name(name: &str) -> String {
let bundle_id = name.replace(['_', '-'], ".")
.replace("..", ".")
.replace("..", ".");

format!(
"com.yourcompany.{}",
bundle_id.strip_prefix('.').unwrap_or(&bundle_id)
)
}


fn cargo_add<'s>(config: &Config<'_>,
pwd: &Path,
manifest: &Path,
Expand Down

0 comments on commit 21331c7

Please sign in to comment.