Skip to content

Commit

Permalink
Merge pull request #407 from boozook/fix-init-bundle-id
Browse files Browse the repository at this point in the history
Fix bundle-id in init/new
  • Loading branch information
boozook authored Jul 17, 2024
2 parents d5656ec + 00a88ad commit 7248136
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,26 @@ jobs:

- name: Check
id: check
run: cargo fmt --all -- --check
continue-on-error: true
run: >-
cargo fmt --all -- --check
# (echo "::error::Rust format error." && exit 1)
- name: Format
id: format
if: steps.check.outcome == 'failure'
run: |
cargo fmt --all
cargo fmt --all
# second time is for anti-flickering, because using nightly rustfmt
- name: Suggestions
uses: reviewdog/action-suggester@v1
with:
filter_mode: diff_context
fail_on_error: false
tool_name: Rustfmt
cleanup: false

clippy:
name: Clippy + fmt suggestions
Expand Down Expand Up @@ -539,7 +558,9 @@ jobs:
# needed after clippy fix
- name: fmt
run: cargo fmt --all
run: |
cargo fmt --all
cargo fmt --all
- name: remove config
run: rm -rf .cargo
Expand Down
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 7248136

Please sign in to comment.