-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(images): add metadata fields for image cli flags (#250)
- Loading branch information
Showing
1 changed file
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,7 +394,7 @@ impl Execution { | |
.insert_str("manufacturer", self.manufacturer(&package)?) | ||
.insert_str("upgrade-code-guid", self.upgrade_guid(&package)?) | ||
.insert_str("path-component-guid", self.path_guid(&package)?); | ||
if let Some(ref banner) = self.banner { | ||
if let Some(banner) = self.banner_image(&package) { | ||
map = map.insert_str("banner", banner); | ||
} | ||
if let Some(description) = description(self.description.clone(), &package) { | ||
|
@@ -406,7 +406,7 @@ impl Execution { | |
Source (wxs) file using a text editor." | ||
); | ||
} | ||
if let Some(ref dialog) = self.dialog { | ||
if let Some(dialog) = self.dialog_image(&package) { | ||
map = map.insert_str("dialog", dialog); | ||
} | ||
match self.eula(&package)? { | ||
|
@@ -444,7 +444,7 @@ impl Execution { | |
(wxs) file using a text editor." | ||
); | ||
} | ||
if let Some(icon) = self.product_icon { | ||
if let Some(icon) = self.product_icon(&package) { | ||
map = map.insert_str("product-icon", icon); | ||
} | ||
|
||
|
@@ -613,6 +613,51 @@ impl Execution { | |
Ok(Uuid::new_v4().as_hyphenated().to_string().to_uppercase()) | ||
} | ||
} | ||
|
||
fn banner_image(&self, manifest: &Package) -> Option<StoredPathBuf> { | ||
if let Some(path) = &self.banner { | ||
trace!("A banner image has been explicitly specified"); | ||
Some(path.clone()) | ||
} else { | ||
manifest | ||
.metadata | ||
.get("wix") | ||
.and_then(|w| w.as_object()) | ||
.and_then(|t| t.get("banner")) | ||
.and_then(|p| p.as_str()) | ||
.map(|p| StoredPathBuf::new(p.to_owned())) | ||
} | ||
} | ||
|
||
fn dialog_image(&self, manifest: &Package) -> Option<StoredPathBuf> { | ||
if let Some(path) = &self.dialog { | ||
trace!("A dialog image has been explicitly specified"); | ||
Some(path.clone()) | ||
} else { | ||
manifest | ||
.metadata | ||
.get("wix") | ||
.and_then(|w| w.as_object()) | ||
.and_then(|t| t.get("dialog")) | ||
.and_then(|p| p.as_str()) | ||
.map(|p| StoredPathBuf::new(p.to_owned())) | ||
} | ||
} | ||
|
||
fn product_icon(&self, manifest: &Package) -> Option<StoredPathBuf> { | ||
if let Some(path) = &self.product_icon { | ||
trace!("A product icon has been explicitly specified"); | ||
Some(path.clone()) | ||
} else { | ||
manifest | ||
.metadata | ||
.get("wix") | ||
.and_then(|w| w.as_object()) | ||
.and_then(|t| t.get("product-icon")) | ||
.and_then(|p| p.as_str()) | ||
.map(|p| StoredPathBuf::new(p.to_owned())) | ||
} | ||
} | ||
} | ||
|
||
impl Default for Execution { | ||
|
@@ -872,6 +917,17 @@ mod tests { | |
upgrade-guid = "71C1A58D-3FD2-493D-BB62-4B27C66FCCF9" | ||
"#; | ||
|
||
const IMAGES_MANIFEST: &str = r#"[package] | ||
name = "Example" | ||
version = "0.1.0" | ||
authors = ["First Last <[email protected]>"] | ||
[package.metadata.wix] | ||
product-icon = "wix/product.ico" | ||
dialog = "wix/dialog.png" | ||
banner = "wix/banner.png" | ||
"#; | ||
|
||
#[test] | ||
fn license_name_with_mit_license_field_works() { | ||
let project = setup_project(MIT_MANIFEST); | ||
|
@@ -1314,5 +1370,26 @@ mod tests { | |
.unwrap(); | ||
assert_eq!(actual, expected); | ||
} | ||
|
||
#[test] | ||
fn image_metadata_works() { | ||
let project = setup_project(IMAGES_MANIFEST); | ||
let manifest = crate::manifest(Some(&project.path().join("Cargo.toml"))).unwrap(); | ||
let package = crate::package(&manifest, None).unwrap(); | ||
|
||
let actual = Builder::default().build(); | ||
assert_eq!( | ||
actual.product_icon(&package).unwrap().as_str(), | ||
"wix/product.ico" | ||
); | ||
assert_eq!( | ||
actual.dialog_image(&package).unwrap().as_str(), | ||
"wix/dialog.png" | ||
); | ||
assert_eq!( | ||
actual.banner_image(&package).unwrap().as_str(), | ||
"wix/banner.png" | ||
); | ||
} | ||
} | ||
} |