Skip to content

Commit 5b3d9b2

Browse files
authored
feat(config): allow setting product name and version on tauri.conf.json (#1358)
1 parent 55c2db4 commit 5b3d9b2

File tree

17 files changed

+281
-153
lines changed

17 files changed

+281
-153
lines changed

.changes/package-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": minor
3+
"tauri-cli": minor
4+
---
5+
6+
Adds `productName` and `version` configs on `tauri.conf.json > package`.

cli/core/Cargo.lock

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

cli/core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ serde_with = "1.6"
3535

3636
[target."cfg(target_os = \"windows\")".dependencies]
3737
which = "4.0"
38+
39+
[target."cfg(target_os = \"linux\")".dependencies]
40+
heck = "0.3"

cli/core/config_definition.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ pub struct OsxConfig {
3535
pub use_bootstrapper: bool,
3636
}
3737

38+
#[skip_serializing_none]
39+
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
40+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
41+
pub struct PackageConfig {
42+
/// App name. Automatically converted to kebab-case on Linux.
43+
pub product_name: Option<String>,
44+
/// App version.
45+
pub version: Option<String>,
46+
}
47+
3848
#[skip_serializing_none]
3949
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
4050
#[serde(rename_all = "camelCase", deny_unknown_fields)]
@@ -43,12 +53,10 @@ pub struct BundleConfig {
4353
pub active: bool,
4454
/// The bundle targets, currently supports ["deb", "osx", "msi", "appimage", "dmg"] or "all"
4555
pub targets: Option<BundleTarget>,
46-
pub name: Option<String>,
4756
/// The app's identifier
4857
pub identifier: Option<String>,
4958
/// The app's icons
5059
pub icon: Option<Vec<String>>,
51-
pub version: Option<String>,
5260
/// App resources to bundle.
5361
/// Each resource is a path to a file or directory.
5462
/// Glob patterns are supported.
@@ -540,6 +548,9 @@ type JsonObject = HashMap<String, JsonValue>;
540548
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
541549
#[serde(rename_all = "camelCase", deny_unknown_fields)]
542550
pub struct Config {
551+
/// Package settings.
552+
#[serde(default)]
553+
pub package: PackageConfig,
543554
/// The Tauri configuration.
544555
#[serde(default)]
545556
pub tauri: TauriConfig,

cli/core/schema.json

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
}
1818
]
1919
},
20+
"package": {
21+
"description": "Package settings.",
22+
"default": {},
23+
"allOf": [
24+
{
25+
"$ref": "#/definitions/PackageConfig"
26+
}
27+
]
28+
},
2029
"plugins": {
2130
"description": "The plugins config.",
2231
"default": {},
@@ -287,12 +296,6 @@
287296
"null"
288297
]
289298
},
290-
"name": {
291-
"type": [
292-
"string",
293-
"null"
294-
]
295-
},
296299
"osx": {
297300
"default": {
298301
"useBootstrapper": false
@@ -335,12 +338,6 @@
335338
"type": "null"
336339
}
337340
]
338-
},
339-
"version": {
340-
"type": [
341-
"string",
342-
"null"
343-
]
344341
}
345342
},
346343
"additionalProperties": false
@@ -773,6 +770,26 @@
773770
},
774771
"additionalProperties": false
775772
},
773+
"PackageConfig": {
774+
"type": "object",
775+
"properties": {
776+
"productName": {
777+
"description": "App name. Automatically converted to kebab-case on Linux.",
778+
"type": [
779+
"string",
780+
"null"
781+
]
782+
},
783+
"version": {
784+
"description": "App version.",
785+
"type": [
786+
"string",
787+
"null"
788+
]
789+
}
790+
},
791+
"additionalProperties": false
792+
},
776793
"SecurityConfig": {
777794
"type": "object",
778795
"properties": {

cli/core/src/build.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ use crate::helpers::{
88
Logger, TauriScript,
99
};
1010

11-
use std::{env::set_current_dir, fs::File, io::Write, path::PathBuf, process::Command};
11+
use std::{
12+
env::set_current_dir,
13+
fs::{rename, File},
14+
io::Write,
15+
path::PathBuf,
16+
process::Command,
17+
};
1218

1319
mod rust;
1420

@@ -98,33 +104,44 @@ impl Build {
98104

99105
rust::build_project(self.debug)?;
100106

107+
let app_settings = rust::AppSettings::new(&config_)?;
108+
109+
let out_dir = app_settings.get_out_dir(self.debug)?;
110+
if let Some(product_name) = config_.package.product_name.clone() {
111+
let bin_name = app_settings.cargo_package_settings().name.clone();
112+
#[cfg(windows)]
113+
rename(
114+
out_dir.join(format!("{}.exe", bin_name)),
115+
out_dir.join(format!("{}.exe", product_name)),
116+
)?;
117+
#[cfg(not(windows))]
118+
rename(out_dir.join(bin_name), out_dir.join(product_name))?;
119+
}
120+
101121
if config_.tauri.bundle.active {
102-
let bundler_settings = rust::get_bundler_settings(&config_, self.debug)?;
103122
// move merge modules to the out dir so the bundler can load it
104123
#[cfg(windows)]
105124
{
106125
let (filename, vcruntime_msm) = if cfg!(target_arch = "x86") {
107-
let _ =
108-
std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x64.msm"));
126+
let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x64.msm"));
109127
(
110128
"Microsoft_VC142_CRT_x86.msm",
111129
include_bytes!("./MergeModules/Microsoft_VC142_CRT_x86.msm").to_vec(),
112130
)
113131
} else {
114-
let _ =
115-
std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x86.msm"));
132+
let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x86.msm"));
116133
(
117134
"Microsoft_VC142_CRT_x64.msm",
118135
include_bytes!("./MergeModules/Microsoft_VC142_CRT_x64.msm").to_vec(),
119136
)
120137
};
121-
std::fs::write(bundler_settings.out_dir.join(filename), vcruntime_msm)?;
138+
std::fs::write(out_dir.join(filename), vcruntime_msm)?;
122139
}
123140
let mut settings_builder = SettingsBuilder::new()
124-
.package_settings(bundler_settings.package_settings)
125-
.bundle_settings(bundler_settings.bundle_settings)
126-
.binaries(bundler_settings.binaries)
127-
.project_out_directory(bundler_settings.out_dir);
141+
.package_settings(app_settings.get_package_settings())
142+
.bundle_settings(app_settings.get_bundle_settings(&config_)?)
143+
.binaries(app_settings.get_binaries(&config_)?)
144+
.project_out_directory(out_dir);
128145

129146
if self.verbose {
130147
settings_builder = settings_builder.verbose();

0 commit comments

Comments
 (0)