From ac8a922d061870782a31c8f4d1ab481d7d6fc30d Mon Sep 17 00:00:00 2001 From: amr-crabnebula Date: Fri, 6 Oct 2023 01:54:59 +0300 Subject: [PATCH] enhance: try to auto-detect the author for the detected identifer --- crates/config/schema.json | 5 +++-- crates/config/src/lib.rs | 6 +++++- crates/packager/schema.json | 5 +++-- crates/packager/src/cli/config.rs | 10 +++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/config/schema.json b/crates/config/schema.json index 8da4f1be..ca081c24 100644 --- a/crates/config/schema.json +++ b/crates/config/schema.json @@ -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.", diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 2a108c01..858e3ec1 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -729,7 +729,11 @@ pub struct Config { /// the package's authors. #[serde(default)] pub authors: Vec, - /// 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, /// The app's publisher. Defaults to the second element in the identifier string. /// Currently maps to the Manufacturer property of the Windows Installer. diff --git a/crates/packager/schema.json b/crates/packager/schema.json index 8da4f1be..ca081c24 100644 --- a/crates/packager/schema.json +++ b/crates/packager/schema.json @@ -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.", diff --git a/crates/packager/src/cli/config.rs b/crates/packager/src/cli/config.rs index 06d7e8bf..f97fe8c9 100644 --- a/crates/packager/src/cli/config.rs +++ b/crates/packager/src/cli/config.rs @@ -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