mirror of https://github.com/tauri-apps/tauri
refactor(bundler): group and organize template file structure (#11046)
This PR groups files in a predictable mannar, so instead of ``` windows/ |_ templates |_ main.wxs |_ installer.nsi |_ nsis.rs |_ msi.rs ``` we group them next to each other ``` windows/ |_ msi |_ main.wxs |_ mod.rs |_ nsis |_ installer.nsi |_ mod.rs ```
This commit is contained in:
parent
4f374a26a3
commit
fbff6388ad
|
@ -86,7 +86,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
|
|||
let mut handlebars = Handlebars::new();
|
||||
handlebars.register_escape_fn(handlebars::no_escape);
|
||||
handlebars
|
||||
.register_template_string("appimage", include_str!("templates/appimage"))
|
||||
.register_template_string("appimage", include_str!("./appimage"))
|
||||
.expect("Failed to register template for handlebars");
|
||||
let temp = handlebars.render("appimage", &sh_map)?;
|
||||
|
|
@ -114,7 +114,7 @@ pub fn generate_desktop_file(
|
|||
.with_context(|| "Failed to setup custom handlebar template")?;
|
||||
} else {
|
||||
handlebars
|
||||
.register_template_string("main.desktop", include_str!("./templates/main.desktop"))
|
||||
.register_template_string("main.desktop", include_str!("./main.desktop"))
|
||||
.with_context(|| "Failed to setup default handlebar template")?;
|
||||
}
|
||||
|
|
@ -72,17 +72,14 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
|
|||
log::info!(action = "Bundling"; "{} ({})", dmg_name, dmg_path.display());
|
||||
|
||||
// write the scripts
|
||||
write(
|
||||
&bundle_script_path,
|
||||
include_str!("templates/dmg/bundle_dmg"),
|
||||
)?;
|
||||
write(&bundle_script_path, include_str!("./bundle_dmg"))?;
|
||||
write(
|
||||
support_directory_path.join("template.applescript"),
|
||||
include_str!("templates/dmg/template.applescript"),
|
||||
include_str!("./template.applescript"),
|
||||
)?;
|
||||
write(
|
||||
support_directory_path.join("eula-resources-template.xml"),
|
||||
include_str!("templates/dmg/eula-resources-template.xml"),
|
||||
include_str!("./eula-resources-template.xml"),
|
||||
)?;
|
||||
|
||||
// chmod script for execution
|
|
@ -185,7 +185,7 @@ pub struct DebianSettings {
|
|||
///
|
||||
/// Default file contents:
|
||||
/// ```text
|
||||
#[doc = include_str!("./linux/templates/main.desktop")]
|
||||
#[doc = include_str!("./linux/freedesktop/main.desktop")]
|
||||
/// ```
|
||||
pub desktop_template: Option<PathBuf>,
|
||||
/// Define the section in Debian Control file. See : <https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections>
|
||||
|
@ -243,7 +243,7 @@ pub struct RpmSettings {
|
|||
///
|
||||
/// Default file contents:
|
||||
/// ```text
|
||||
#[doc = include_str!("./linux/templates/main.desktop")]
|
||||
#[doc = include_str!("./linux/freedesktop/main.desktop")]
|
||||
/// ```
|
||||
pub desktop_template: Option<PathBuf>,
|
||||
/// Path to script that will be executed before the package is unpacked. See
|
||||
|
@ -410,7 +410,7 @@ pub struct NsisSettings {
|
|||
/// An key-value pair where the key is the language and the
|
||||
/// value is the path to a custom `.nsi` file that holds the translated text for tauri's custom messages.
|
||||
///
|
||||
/// See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/templates/nsis-languages/English.nsh> for an example `.nsi` file.
|
||||
/// See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> for an example `.nsi` file.
|
||||
///
|
||||
/// **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`]languages array,
|
||||
pub custom_language_files: Option<HashMap<String, PathBuf>>,
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
// Copyright 2016-2019 Cargo-Bundle developers <https://github.com/burtonageo/cargo-bundle>
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
mod wix;
|
||||
|
||||
use crate::Settings;
|
||||
|
||||
use std::{self, path::PathBuf};
|
||||
|
||||
const WIX_REQUIRED_FILES: &[&str] = &[
|
||||
"candle.exe",
|
||||
"candle.exe.config",
|
||||
"darice.cub",
|
||||
"light.exe",
|
||||
"light.exe.config",
|
||||
"wconsole.dll",
|
||||
"winterop.dll",
|
||||
"wix.dll",
|
||||
"WixUIExtension.dll",
|
||||
"WixUtilExtension.dll",
|
||||
];
|
||||
|
||||
/// Runs all of the commands to build the MSI installer.
|
||||
/// Returns a vector of PathBuf that shows where the MSI was created.
|
||||
pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<PathBuf>> {
|
||||
let tauri_tools_path = settings
|
||||
.local_tools_directory()
|
||||
.map(|d| d.join(".tauri"))
|
||||
.unwrap_or_else(|| dirs::cache_dir().unwrap().join("tauri"));
|
||||
|
||||
let wix_path = tauri_tools_path.join("WixTools314");
|
||||
|
||||
if !wix_path.exists() {
|
||||
wix::get_and_extract_wix(&wix_path)?;
|
||||
} else if WIX_REQUIRED_FILES
|
||||
.iter()
|
||||
.any(|p| !wix_path.join(p).exists())
|
||||
{
|
||||
log::warn!("WixTools directory is missing some files. Recreating it.");
|
||||
std::fs::remove_dir_all(&wix_path)?;
|
||||
wix::get_and_extract_wix(&wix_path)?;
|
||||
}
|
||||
|
||||
wix::build_wix_app_installer(settings, &wix_path, updater)
|
||||
}
|
|
@ -34,6 +34,43 @@ pub const WIX_URL: &str =
|
|||
"https://github.com/wixtoolset/wix3/releases/download/wix3141rtm/wix314-binaries.zip";
|
||||
pub const WIX_SHA256: &str = "6ac824e1642d6f7277d0ed7ea09411a508f6116ba6fae0aa5f2c7daa2ff43d31";
|
||||
|
||||
const WIX_REQUIRED_FILES: &[&str] = &[
|
||||
"candle.exe",
|
||||
"candle.exe.config",
|
||||
"darice.cub",
|
||||
"light.exe",
|
||||
"light.exe.config",
|
||||
"wconsole.dll",
|
||||
"winterop.dll",
|
||||
"wix.dll",
|
||||
"WixUIExtension.dll",
|
||||
"WixUtilExtension.dll",
|
||||
];
|
||||
|
||||
/// Runs all of the commands to build the MSI installer.
|
||||
/// Returns a vector of PathBuf that shows where the MSI was created.
|
||||
pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<PathBuf>> {
|
||||
let tauri_tools_path = settings
|
||||
.local_tools_directory()
|
||||
.map(|d| d.join(".tauri"))
|
||||
.unwrap_or_else(|| dirs::cache_dir().unwrap().join("tauri"));
|
||||
|
||||
let wix_path = tauri_tools_path.join("WixTools314");
|
||||
|
||||
if !wix_path.exists() {
|
||||
get_and_extract_wix(&wix_path)?;
|
||||
} else if WIX_REQUIRED_FILES
|
||||
.iter()
|
||||
.any(|p| !wix_path.join(p).exists())
|
||||
{
|
||||
log::warn!("WixTools directory is missing some files. Recreating it.");
|
||||
std::fs::remove_dir_all(&wix_path)?;
|
||||
get_and_extract_wix(&wix_path)?;
|
||||
}
|
||||
|
||||
build_wix_app_installer(settings, &wix_path, updater)
|
||||
}
|
||||
|
||||
// For Cross Platform Compilation.
|
||||
|
||||
// const VC_REDIST_X86_URL: &str =
|
||||
|
@ -630,7 +667,7 @@ pub fn build_wix_app_installer(
|
|||
.expect("Failed to setup custom handlebar template");
|
||||
} else {
|
||||
handlebars
|
||||
.register_template_string("main.wxs", include_str!("../templates/main.wxs"))
|
||||
.register_template_string("main.wxs", include_str!("./main.wxs"))
|
||||
.map_err(|e| e.to_string())
|
||||
.expect("Failed to setup handlebar template");
|
||||
}
|
||||
|
@ -649,7 +686,7 @@ pub fn build_wix_app_installer(
|
|||
|
||||
// Create the update task XML
|
||||
let mut skip_uac_task = Handlebars::new();
|
||||
let xml = include_str!("../templates/update-task.xml");
|
||||
let xml = include_str!("./update-task.xml");
|
||||
skip_uac_task
|
||||
.register_template_string("update.xml", xml)
|
||||
.map_err(|e| e.to_string())
|
||||
|
@ -661,7 +698,7 @@ pub fn build_wix_app_installer(
|
|||
// 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!("../templates/install-task.ps1");
|
||||
let xml = include_str!("./install-task.ps1");
|
||||
skip_uac_task_installer
|
||||
.register_template_string("install-task.ps1", xml)
|
||||
.map_err(|e| e.to_string())
|
||||
|
@ -673,7 +710,7 @@ pub fn build_wix_app_installer(
|
|||
// 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!("../templates/uninstall-task.ps1");
|
||||
let xml = include_str!("./uninstall-task.ps1");
|
||||
skip_uac_task_uninstaller
|
||||
.register_template_string("uninstall-task.ps1", xml)
|
||||
.map_err(|e| e.to_string())
|
|
@ -480,19 +480,16 @@ fn build_nsis_app_installer(
|
|||
.expect("Failed to setup custom handlebar template");
|
||||
} else {
|
||||
handlebars
|
||||
.register_template_string("installer.nsi", include_str!("./templates/installer.nsi"))
|
||||
.register_template_string("installer.nsi", include_str!("./installer.nsi"))
|
||||
.map_err(|e| e.to_string())
|
||||
.expect("Failed to setup handlebar template");
|
||||
}
|
||||
|
||||
write_utf8_with_bom(
|
||||
output_path.join("FileAssociation.nsh"),
|
||||
include_bytes!("./templates/FileAssociation.nsh"),
|
||||
)?;
|
||||
write_utf8_with_bom(
|
||||
output_path.join("utils.nsh"),
|
||||
include_bytes!("./templates/utils.nsh"),
|
||||
include_bytes!("./FileAssociation.nsh"),
|
||||
)?;
|
||||
write_utf8_with_bom(output_path.join("utils.nsh"), include_bytes!("./utils.nsh"))?;
|
||||
|
||||
let installer_nsi_path = output_path.join("installer.nsi");
|
||||
write_utf8_with_bom(
|
||||
|
@ -681,23 +678,23 @@ fn generate_estimated_size(
|
|||
fn get_lang_data(lang: &str) -> Option<(String, &[u8])> {
|
||||
let path = format!("{lang}.nsh");
|
||||
let content: &[u8] = match lang.to_lowercase().as_str() {
|
||||
"arabic" => include_bytes!("./templates/nsis-languages/Arabic.nsh"),
|
||||
"bulgarian" => include_bytes!("./templates/nsis-languages/Bulgarian.nsh"),
|
||||
"dutch" => include_bytes!("./templates/nsis-languages/Dutch.nsh"),
|
||||
"english" => include_bytes!("./templates/nsis-languages/English.nsh"),
|
||||
"german" => include_bytes!("./templates/nsis-languages/German.nsh"),
|
||||
"japanese" => include_bytes!("./templates/nsis-languages/Japanese.nsh"),
|
||||
"korean" => include_bytes!("./templates/nsis-languages/Korean.nsh"),
|
||||
"portuguesebr" => include_bytes!("./templates/nsis-languages/PortugueseBR.nsh"),
|
||||
"russian" => include_bytes!("./templates/nsis-languages/Russian.nsh"),
|
||||
"tradchinese" => include_bytes!("./templates/nsis-languages/TradChinese.nsh"),
|
||||
"simpchinese" => include_bytes!("./templates/nsis-languages/SimpChinese.nsh"),
|
||||
"french" => include_bytes!("./templates/nsis-languages/French.nsh"),
|
||||
"spanish" => include_bytes!("./templates/nsis-languages/Spanish.nsh"),
|
||||
"spanishinternational" => include_bytes!("./templates/nsis-languages/SpanishInternational.nsh"),
|
||||
"persian" => include_bytes!("./templates/nsis-languages/Persian.nsh"),
|
||||
"turkish" => include_bytes!("./templates/nsis-languages/Turkish.nsh"),
|
||||
"swedish" => include_bytes!("./templates/nsis-languages/Swedish.nsh"),
|
||||
"arabic" => include_bytes!("./languages/Arabic.nsh"),
|
||||
"bulgarian" => include_bytes!("./languages/Bulgarian.nsh"),
|
||||
"dutch" => include_bytes!("./languages/Dutch.nsh"),
|
||||
"english" => include_bytes!("./languages/English.nsh"),
|
||||
"german" => include_bytes!("./languages/German.nsh"),
|
||||
"japanese" => include_bytes!("./languages/Japanese.nsh"),
|
||||
"korean" => include_bytes!("./languages/Korean.nsh"),
|
||||
"portuguesebr" => include_bytes!("./languages/PortugueseBR.nsh"),
|
||||
"russian" => include_bytes!("./languages/Russian.nsh"),
|
||||
"tradchinese" => include_bytes!("./languages/TradChinese.nsh"),
|
||||
"simpchinese" => include_bytes!("./languages/SimpChinese.nsh"),
|
||||
"french" => include_bytes!("./languages/French.nsh"),
|
||||
"spanish" => include_bytes!("./languages/Spanish.nsh"),
|
||||
"spanishinternational" => include_bytes!("./languages/SpanishInternational.nsh"),
|
||||
"persian" => include_bytes!("./languages/Persian.nsh"),
|
||||
"turkish" => include_bytes!("./languages/Turkish.nsh"),
|
||||
"swedish" => include_bytes!("./languages/Swedish.nsh"),
|
||||
_ => return None,
|
||||
};
|
||||
Some((path, content))
|
|
@ -2340,7 +2340,7 @@
|
|||
}
|
||||
},
|
||||
"customLanguageFiles": {
|
||||
"description": "A key-value pair where the key is the language and the\n value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.\n\n See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/templates/nsis-languages/English.nsh> for an example `.nsh` file.\n\n **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`] languages array,",
|
||||
"description": "A key-value pair where the key is the language and the\n value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.\n\n See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> for an example `.nsh` file.\n\n **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`] languages array,",
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
|
|
|
@ -2340,7 +2340,7 @@
|
|||
}
|
||||
},
|
||||
"customLanguageFiles": {
|
||||
"description": "A key-value pair where the key is the language and the\n value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.\n\n See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/templates/nsis-languages/English.nsh> for an example `.nsh` file.\n\n **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`] languages array,",
|
||||
"description": "A key-value pair where the key is the language and the\n value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.\n\n See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> for an example `.nsh` file.\n\n **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`] languages array,",
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
|
|
|
@ -783,7 +783,7 @@ pub struct NsisConfig {
|
|||
/// A key-value pair where the key is the language and the
|
||||
/// value is the path to a custom `.nsh` file that holds the translated text for tauri's custom messages.
|
||||
///
|
||||
/// See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/templates/nsis-languages/English.nsh> for an example `.nsh` file.
|
||||
/// See <https://github.com/tauri-apps/tauri/blob/dev/crates/tauri-bundler/src/bundle/windows/nsis/languages/English.nsh> for an example `.nsh` file.
|
||||
///
|
||||
/// **Note**: the key must be a valid NSIS language and it must be added to [`NsisConfig`] languages array,
|
||||
pub custom_language_files: Option<HashMap<String, PathBuf>>,
|
||||
|
|
Loading…
Reference in New Issue