Skip to content

Commit a0b9042

Browse files
committed
feat: add pkg to frontend init
1 parent 09df520 commit a0b9042

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

cargo-dist/src/init.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ fn get_new_dist_metadata(
733733
InstallerStyle::Npm,
734734
InstallerStyle::Homebrew,
735735
InstallerStyle::Msi,
736+
InstallerStyle::Pkg,
736737
]
737738
} else {
738739
eprintln!("{notice} no CI backends enabled, most installers have been hidden");
@@ -849,6 +850,72 @@ fn get_new_dist_metadata(
849850
}
850851
}
851852

853+
// Special handling of the pkg installer
854+
if meta
855+
.installers
856+
.as_deref()
857+
.unwrap_or_default()
858+
.contains(&InstallerStyle::Pkg)
859+
{
860+
let pkg_is_new = !orig_meta
861+
.installers
862+
.as_deref()
863+
.unwrap_or_default()
864+
.contains(&InstallerStyle::Pkg);
865+
866+
if pkg_is_new && orig_meta.mac_pkg_config.is_none() {
867+
let prompt = r#"you've enabled a Mac .pkg installer. This requires a unique bundle ID;
868+
please enter one now. This is in reverse-domain name format.
869+
For more information, consult the Apple documentation:
870+
https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1"#;
871+
let default = "".to_string();
872+
873+
let identifier: String = if args.yes {
874+
default
875+
} else {
876+
let res = Input::with_theme(&theme)
877+
.with_prompt(prompt)
878+
.allow_empty(true)
879+
.interact_text()?;
880+
eprintln!();
881+
res
882+
};
883+
let identifier = identifier.trim();
884+
if identifier.is_empty() {
885+
return Err(DistError::MacPkgBundleIdentifierMissing {});
886+
}
887+
888+
let prompt = r#"Please enter the installation prefix this .pkg should use."#;
889+
let prefix = if args.yes {
890+
None
891+
} else {
892+
let res: String = Input::with_theme(&theme)
893+
.with_prompt(prompt)
894+
.allow_empty(true)
895+
.interact_text()?;
896+
eprintln!();
897+
898+
let trimmed = res.trim();
899+
if trimmed.is_empty() {
900+
None
901+
} else {
902+
Some(trimmed.to_owned())
903+
}
904+
};
905+
906+
meta.mac_pkg_config = Some(config::MacPkgConfig {
907+
identifier: Some(identifier.to_owned()),
908+
install_location: prefix,
909+
})
910+
}
911+
}
912+
913+
meta.publish_jobs = if publish_jobs.is_empty() {
914+
None
915+
} else {
916+
Some(publish_jobs.to_owned())
917+
};
918+
852919
// Special handling of the npm installer
853920
if meta
854921
.installers

0 commit comments

Comments
 (0)