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

feat: add beforeEachBundleCommand #7880

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changes/tauri-bundle-with-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-bundler': 'minor:feat'
---

Add `bundle::bundle_project_with_hook`.
5 changes: 5 additions & 0 deletions .changes/tauri-cli-before-each-bundle-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-cli': 'minor:feat'
---

Execute the newly added `beforeEachBundleCommand` when bundling each target.
5 changes: 5 additions & 0 deletions .changes/tauri-utils-before-each-bundle-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': 'minor:feat'
---

Add `before_each_bundle_command` to the config.
11 changes: 11 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,17 @@
}
]
},
"beforeEachBundleCommand": {
"description": "Similar to `before_bundle_command`, a shell command to run before the bundling phase of each package type. Check `TAURI_BUNDLER_PACKAGE_TYPE` env var to know which package type is being bundled.\n\nThe TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.",
"anyOf": [
{
"$ref": "#/definitions/HookCommand"
},
{
"type": "null"
}
]
},
"features": {
"description": "Features passed to `cargo` commands.",
"type": [
Expand Down
12 changes: 12 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,13 @@ pub struct BuildConfig {
/// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
#[serde(alias = "before-bundle-command")]
pub before_bundle_command: Option<HookCommand>,
/// Similar to `before_bundle_command`, a shell command to run before the bundling phase
/// of each package type. Check `TAURI_BUNDLER_PACKAGE_TYPE` env var to know
/// which package type is being bundled.
///
/// The TAURI_PLATFORM, TAURI_ARCH, TAURI_FAMILY, TAURI_PLATFORM_VERSION, TAURI_PLATFORM_TYPE and TAURI_DEBUG environment variables are set if you perform conditional compilation.
#[serde(alias = "before-bundle-command")]
pub before_each_bundle_command: Option<HookCommand>,
/// Features passed to `cargo` commands.
pub features: Option<Vec<String>>,
/// Whether we should inject the Tauri API on `window.__TAURI__` or not.
Expand All @@ -1728,6 +1735,7 @@ impl Default for BuildConfig {
before_dev_command: None,
before_build_command: None,
before_bundle_command: None,
before_each_bundle_command: None,
features: None,
with_global_tauri: false,
}
Expand Down Expand Up @@ -1939,6 +1947,7 @@ fn default_build() -> BuildConfig {
before_dev_command: None,
before_build_command: None,
before_bundle_command: None,
before_each_bundle_command: None,
features: None,
with_global_tauri: false,
}
Expand Down Expand Up @@ -2436,6 +2445,7 @@ mod build {
let before_dev_command = quote!(None);
let before_build_command = quote!(None);
let before_bundle_command = quote!(None);
let before_each_bundle_command = quote!(None);
let features = quote!(None);

literal_struct!(
Expand All @@ -2448,6 +2458,7 @@ mod build {
before_dev_command,
before_build_command,
before_bundle_command,
before_each_bundle_command,
features
);
}
Expand Down Expand Up @@ -2736,6 +2747,7 @@ mod test {
before_dev_command: None,
before_build_command: None,
before_bundle_command: None,
before_each_bundle_command: None,
features: None,
with_global_tauri: false,
};
Expand Down
11 changes: 11 additions & 0 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub struct Bundle {
/// Bundles the project.
/// Returns the list of paths where the bundles can be found.
pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
bundle_project_with_hook(settings, |_| Ok(()))
}

/// Bundles the project and runs the hook before bundling each target.
/// Returns the list of paths where the bundles can be found.
pub fn bundle_project_with_hook<F: Fn(&PackageType) -> crate::Result<()>>(
settings: Settings,
before_each_package_hook: F,
) -> crate::Result<Vec<Bundle>> {
let package_types = settings.package_types()?;
if package_types.is_empty() {
return Ok(Vec::new());
Expand All @@ -67,6 +76,8 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<Bundle>> {
continue;
}

before_each_package_hook(package_type)?;

let bundle_paths = match package_type {
#[cfg(target_os = "macos")]
PackageType::MacOsBundle => macos::app::bundle_project(&settings)?,
Expand Down
Loading
Loading