Skip to content

Commit

Permalink
feat(config): allow setting product name and version on tauri.conf.js…
Browse files Browse the repository at this point in the history
…on (#1358)
  • Loading branch information
lucasfernog authored Mar 23, 2021
1 parent 55c2db4 commit 5b3d9b2
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 153 deletions.
6 changes: 6 additions & 0 deletions .changes/package-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": minor
"tauri-cli": minor
---

Adds `productName` and `version` configs on `tauri.conf.json > package`.
1 change: 1 addition & 0 deletions cli/core/Cargo.lock

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

3 changes: 3 additions & 0 deletions cli/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ serde_with = "1.6"

[target."cfg(target_os = \"windows\")".dependencies]
which = "4.0"

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.3"
15 changes: 13 additions & 2 deletions cli/core/config_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ pub struct OsxConfig {
pub use_bootstrapper: bool,
}

#[skip_serializing_none]
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct PackageConfig {
/// App name. Automatically converted to kebab-case on Linux.
pub product_name: Option<String>,
/// App version.
pub version: Option<String>,
}

#[skip_serializing_none]
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand All @@ -43,12 +53,10 @@ pub struct BundleConfig {
pub active: bool,
/// The bundle targets, currently supports ["deb", "osx", "msi", "appimage", "dmg"] or "all"
pub targets: Option<BundleTarget>,
pub name: Option<String>,
/// The app's identifier
pub identifier: Option<String>,
/// The app's icons
pub icon: Option<Vec<String>>,
pub version: Option<String>,
/// App resources to bundle.
/// Each resource is a path to a file or directory.
/// Glob patterns are supported.
Expand Down Expand Up @@ -540,6 +548,9 @@ type JsonObject = HashMap<String, JsonValue>;
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Config {
/// Package settings.
#[serde(default)]
pub package: PackageConfig,
/// The Tauri configuration.
#[serde(default)]
pub tauri: TauriConfig,
Expand Down
41 changes: 29 additions & 12 deletions cli/core/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
}
]
},
"package": {
"description": "Package settings.",
"default": {},
"allOf": [
{
"$ref": "#/definitions/PackageConfig"
}
]
},
"plugins": {
"description": "The plugins config.",
"default": {},
Expand Down Expand Up @@ -287,12 +296,6 @@
"null"
]
},
"name": {
"type": [
"string",
"null"
]
},
"osx": {
"default": {
"useBootstrapper": false
Expand Down Expand Up @@ -335,12 +338,6 @@
"type": "null"
}
]
},
"version": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -773,6 +770,26 @@
},
"additionalProperties": false
},
"PackageConfig": {
"type": "object",
"properties": {
"productName": {
"description": "App name. Automatically converted to kebab-case on Linux.",
"type": [
"string",
"null"
]
},
"version": {
"description": "App version.",
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
},
"SecurityConfig": {
"type": "object",
"properties": {
Expand Down
39 changes: 28 additions & 11 deletions cli/core/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ use crate::helpers::{
Logger, TauriScript,
};

use std::{env::set_current_dir, fs::File, io::Write, path::PathBuf, process::Command};
use std::{
env::set_current_dir,
fs::{rename, File},
io::Write,
path::PathBuf,
process::Command,
};

mod rust;

Expand Down Expand Up @@ -98,33 +104,44 @@ impl Build {

rust::build_project(self.debug)?;

let app_settings = rust::AppSettings::new(&config_)?;

let out_dir = app_settings.get_out_dir(self.debug)?;
if let Some(product_name) = config_.package.product_name.clone() {
let bin_name = app_settings.cargo_package_settings().name.clone();
#[cfg(windows)]
rename(
out_dir.join(format!("{}.exe", bin_name)),
out_dir.join(format!("{}.exe", product_name)),
)?;
#[cfg(not(windows))]
rename(out_dir.join(bin_name), out_dir.join(product_name))?;
}

if config_.tauri.bundle.active {
let bundler_settings = rust::get_bundler_settings(&config_, self.debug)?;
// move merge modules to the out dir so the bundler can load it
#[cfg(windows)]
{
let (filename, vcruntime_msm) = if cfg!(target_arch = "x86") {
let _ =
std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x64.msm"));
let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x64.msm"));
(
"Microsoft_VC142_CRT_x86.msm",
include_bytes!("./MergeModules/Microsoft_VC142_CRT_x86.msm").to_vec(),
)
} else {
let _ =
std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x86.msm"));
let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x86.msm"));
(
"Microsoft_VC142_CRT_x64.msm",
include_bytes!("./MergeModules/Microsoft_VC142_CRT_x64.msm").to_vec(),
)
};
std::fs::write(bundler_settings.out_dir.join(filename), vcruntime_msm)?;
std::fs::write(out_dir.join(filename), vcruntime_msm)?;
}
let mut settings_builder = SettingsBuilder::new()
.package_settings(bundler_settings.package_settings)
.bundle_settings(bundler_settings.bundle_settings)
.binaries(bundler_settings.binaries)
.project_out_directory(bundler_settings.out_dir);
.package_settings(app_settings.get_package_settings())
.bundle_settings(app_settings.get_bundle_settings(&config_)?)
.binaries(app_settings.get_binaries(&config_)?)
.project_out_directory(out_dir);

if self.verbose {
settings_builder = settings_builder.verbose();
Expand Down
Loading

0 comments on commit 5b3d9b2

Please sign in to comment.