Skip to content

Commit

Permalink
enhance: try to auto-detect the author for the detected identifer
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Oct 5, 2023
1 parent 1549cae commit ac8a922
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions crates/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@
}
},
"identifier": {
"description": "the app's identifier.",
"description": "the application identifier in reverse domain name notation (e.g. `com.packager.example`). This string must be unique across applications since it is used in some system configurations. This string must contain only alphanumeric characters (A–Z, a–z, and 0–9), hyphens (-), and periods (.).",
"type": [
"string",
"null"
]
],
"pattern": "^[a-zA-Z0-9-\\.]*$"
},
"publisher": {
"description": "The app's publisher. Defaults to the second element in the identifier string. Currently maps to the Manufacturer property of the Windows Installer.",
Expand Down
6 changes: 5 additions & 1 deletion crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,11 @@ pub struct Config {
/// the package's authors.
#[serde(default)]
pub authors: Vec<String>,
/// the app's identifier.
/// the application identifier in reverse domain name notation (e.g. `com.packager.example`).
/// This string must be unique across applications since it is used in some system configurations.
/// This string must contain only alphanumeric characters (A–Z, a–z, and 0–9), hyphens (-),
/// and periods (.).
#[schemars(regex(pattern = r"^[a-zA-Z0-9-\.]*$"))]
pub identifier: Option<String>,
/// The app's publisher. Defaults to the second element in the identifier string.
/// Currently maps to the Manufacturer property of the Windows Installer.
Expand Down
5 changes: 3 additions & 2 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@
}
},
"identifier": {
"description": "the app's identifier.",
"description": "the application identifier in reverse domain name notation (e.g. `com.packager.example`). This string must be unique across applications since it is used in some system configurations. This string must contain only alphanumeric characters (A–Z, a–z, and 0–9), hyphens (-), and periods (.).",
"type": [
"string",
"null"
]
],
"pattern": "^[a-zA-Z0-9-\\.]*$"
},
"publisher": {
"description": "The app's publisher. Defaults to the second element in the identifier string. Currently maps to the Manufacturer property of the Windows Installer.",
Expand Down
10 changes: 9 additions & 1 deletion crates/packager/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@ pub fn load_configs_from_cargo_workspace(
config.version = package.version.to_string();
}
if config.identifier.is_none() {
let author = package
.authors
.first()
.map(|a| {
let a = a.replace(['_', ' ', '.'], "-").to_lowercase();
a.strip_suffix("_").map(ToString::to_string).unwrap_or(a)
})
.unwrap_or_else(|| format!("{}-author", package.name));
config
.identifier
.replace(format!("com.{}.app", package.name));
.replace(format!("com.{}.{}", author, package.name));
}
if config.out_dir.as_os_str().is_empty() {
config.out_dir = metadata
Expand Down

0 comments on commit ac8a922

Please sign in to comment.