Skip to content

Commit

Permalink
feat: add beforeEachBundleCommand
Browse files Browse the repository at this point in the history
ref: #7756
  • Loading branch information
amrbashir committed Sep 21, 2023
1 parent a2021c3 commit 5b3f9f3
Show file tree
Hide file tree
Showing 9 changed files with 664 additions and 559 deletions.
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 bundle format.\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
11 changes: 11 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,12 @@ 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 bundle format.
///
/// 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 +1734,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 +1946,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 +2444,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 +2457,7 @@ mod build {
before_dev_command,
before_build_command,
before_bundle_command,
before_each_bundle_command,
features
);
}
Expand Down Expand Up @@ -2736,6 +2746,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

0 comments on commit 5b3f9f3

Please sign in to comment.