Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bundle-id in init/new #407

Merged
merged 3 commits into from
Jul 17, 2024
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
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
Loading