Skip to content

Commit

Permalink
feat(cli): process bundle > windows > wix > fragmentPaths with Hand…
Browse files Browse the repository at this point in the history
…lebars (#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 <[email protected]>
  • Loading branch information
amrbashir and lucasfernog authored Nov 5, 2024
1 parent 17c6952 commit 1b6b2cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .changes/bundler-fragment-handlebars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-bundler": "minor:feat"
"tauri-cli": "minor:feat"
---

Process `bundle > windows > wix > fragmentPaths` with Handlebars to interpolate expressions within it.

4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions crates/tauri-bundler/src/bundle/linux/appimage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
// initialize shell script template.
let mut handlebars = Handlebars::new();
handlebars.register_escape_fn(handlebars::no_escape);
handlebars
.register_template_string("appimage", include_str!("./appimage"))
.expect("Failed to register template for handlebars");
let temp = handlebars.render("appimage", &sh_map)?;
let temp = handlebars.render_template(include_str!("./appimage"), &sh_map)?;

// create the shell script file in the target/ folder.
let sh_file = output_path.join("build_appimage.sh");
Expand Down
24 changes: 7 additions & 17 deletions crates/tauri-bundler/src/bundle/windows/msi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,38 +726,26 @@ pub fn build_wix_app_installer(
);

// Create the update task XML
let mut skip_uac_task = Handlebars::new();
let skip_uac_task = Handlebars::new();
let xml = include_str!("./update-task.xml");
skip_uac_task
.register_template_string("update.xml", xml)
.map_err(|e| e.to_string())
.expect("Failed to setup Update Task handlebars");
let update_content = skip_uac_task.render_template(xml, &data)?;
let temp_xml_path = output_path.join("update.xml");
let update_content = skip_uac_task.render("update.xml", &data)?;
fs::write(temp_xml_path, update_content)?;

// Create the Powershell script to install the task
let mut skip_uac_task_installer = Handlebars::new();
skip_uac_task_installer.register_escape_fn(handlebars::no_escape);
let xml = include_str!("./install-task.ps1");
skip_uac_task_installer
.register_template_string("install-task.ps1", xml)
.map_err(|e| e.to_string())
.expect("Failed to setup Update Task Installer handlebars");
let install_script_content = skip_uac_task_installer.render_template(xml, &data)?;
let temp_ps1_path = output_path.join("install-task.ps1");
let install_script_content = skip_uac_task_installer.render("install-task.ps1", &data)?;
fs::write(temp_ps1_path, install_script_content)?;

// Create the Powershell script to uninstall the task
let mut skip_uac_task_uninstaller = Handlebars::new();
skip_uac_task_uninstaller.register_escape_fn(handlebars::no_escape);
let xml = include_str!("./uninstall-task.ps1");
skip_uac_task_uninstaller
.register_template_string("uninstall-task.ps1", xml)
.map_err(|e| e.to_string())
.expect("Failed to setup Update Task Uninstaller handlebars");
let install_script_content = skip_uac_task_uninstaller.render_template(xml, &data)?;
let temp_ps1_path = output_path.join("uninstall-task.ps1");
let install_script_content = skip_uac_task_uninstaller.render("uninstall-task.ps1", &data)?;
fs::write(temp_ps1_path, install_script_content)?;

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

0 comments on commit 1b6b2cf

Please sign in to comment.