Skip to content

Commit 1b6b2cf

Browse files
feat(cli): process bundle > windows > wix > fragmentPaths with Handlebars (#11521)
* feat(cli): process `bundle > windows > wix > fragmentPaths` with Handlebars closes #11520 * remove unneeded register_template_string * Update crates/tauri-bundler/src/bundle/windows/msi/mod.rs --------- Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
1 parent 17c6952 commit 1b6b2cf

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": "minor:feat"
3+
"tauri-cli": "minor:feat"
4+
---
5+
6+
Process `bundle > windows > wix > fragmentPaths` with Handlebars to interpolate expressions within it.
7+

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-bundler/src/bundle/linux/appimage/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
106106
// initialize shell script template.
107107
let mut handlebars = Handlebars::new();
108108
handlebars.register_escape_fn(handlebars::no_escape);
109-
handlebars
110-
.register_template_string("appimage", include_str!("./appimage"))
111-
.expect("Failed to register template for handlebars");
112-
let temp = handlebars.render("appimage", &sh_map)?;
109+
let temp = handlebars.render_template(include_str!("./appimage"), &sh_map)?;
113110

114111
// create the shell script file in the target/ folder.
115112
let sh_file = output_path.join("build_appimage.sh");

crates/tauri-bundler/src/bundle/windows/msi/mod.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -726,38 +726,26 @@ pub fn build_wix_app_installer(
726726
);
727727

728728
// Create the update task XML
729-
let mut skip_uac_task = Handlebars::new();
729+
let skip_uac_task = Handlebars::new();
730730
let xml = include_str!("./update-task.xml");
731-
skip_uac_task
732-
.register_template_string("update.xml", xml)
733-
.map_err(|e| e.to_string())
734-
.expect("Failed to setup Update Task handlebars");
731+
let update_content = skip_uac_task.render_template(xml, &data)?;
735732
let temp_xml_path = output_path.join("update.xml");
736-
let update_content = skip_uac_task.render("update.xml", &data)?;
737733
fs::write(temp_xml_path, update_content)?;
738734

739735
// Create the Powershell script to install the task
740736
let mut skip_uac_task_installer = Handlebars::new();
741737
skip_uac_task_installer.register_escape_fn(handlebars::no_escape);
742738
let xml = include_str!("./install-task.ps1");
743-
skip_uac_task_installer
744-
.register_template_string("install-task.ps1", xml)
745-
.map_err(|e| e.to_string())
746-
.expect("Failed to setup Update Task Installer handlebars");
739+
let install_script_content = skip_uac_task_installer.render_template(xml, &data)?;
747740
let temp_ps1_path = output_path.join("install-task.ps1");
748-
let install_script_content = skip_uac_task_installer.render("install-task.ps1", &data)?;
749741
fs::write(temp_ps1_path, install_script_content)?;
750742

751743
// Create the Powershell script to uninstall the task
752744
let mut skip_uac_task_uninstaller = Handlebars::new();
753745
skip_uac_task_uninstaller.register_escape_fn(handlebars::no_escape);
754746
let xml = include_str!("./uninstall-task.ps1");
755-
skip_uac_task_uninstaller
756-
.register_template_string("uninstall-task.ps1", xml)
757-
.map_err(|e| e.to_string())
758-
.expect("Failed to setup Update Task Uninstaller handlebars");
747+
let install_script_content = skip_uac_task_uninstaller.render_template(xml, &data)?;
759748
let temp_ps1_path = output_path.join("uninstall-task.ps1");
760-
let install_script_content = skip_uac_task_uninstaller.render("uninstall-task.ps1", &data)?;
761749
fs::write(temp_ps1_path, install_script_content)?;
762750

763751
data.insert("enable_elevated_update_task", to_json(true));
@@ -772,7 +760,9 @@ pub fn build_wix_app_installer(
772760
let extension_regex = Regex::new("\"http://schemas.microsoft.com/wix/(\\w+)\"")?;
773761
for fragment_path in fragment_paths {
774762
let fragment_path = current_dir.join(fragment_path);
775-
let fragment = fs::read_to_string(&fragment_path)?;
763+
let fragment_content = fs::read_to_string(&fragment_path)?;
764+
let fragment_handlebars = Handlebars::new();
765+
let fragment = fragment_handlebars.render_template(&fragment_content, &data)?;
776766
let mut extensions = Vec::new();
777767
for cap in extension_regex.captures_iter(&fragment) {
778768
extensions.push(wix_toolset_path.join(format!("Wix{}.dll", &cap[1])));

0 commit comments

Comments
 (0)