mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-29 13:03:09 +03:00
feature(bundle) merge BundleSettings with config from tauri.conf… (#471)
* feat(bundler) read tauri config WIP * feat(bundler) merge BundleSettings with tauri.conf.json" * chore(lint) strings must use single quotes * chore(bundler) platform-specific config on separated object on tauri cfg * fix(eslint) unexpected trailing comma
This commit is contained in:
parent
2a6e5b50ce
commit
21e710e1b0
@ -23,6 +23,7 @@ libflate = "0.1"
|
||||
md5 = "0.7.0"
|
||||
msi = "0.2"
|
||||
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
strsim = "0.10.0"
|
||||
tar = "0.4"
|
||||
|
@ -14,6 +14,7 @@ mod path_utils;
|
||||
mod platform;
|
||||
mod rpm_bundle;
|
||||
mod settings;
|
||||
mod tauri_config;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod wix;
|
||||
|
||||
|
@ -235,6 +235,12 @@ impl Settings {
|
||||
|
||||
let bundle_settings = add_external_bin(bundle_settings)?;
|
||||
|
||||
let tauri_config = super::tauri_config::get();
|
||||
let merged_bundle_settings = match tauri_config {
|
||||
Ok(config) => merge_settings(bundle_settings, config.tauri.bundle),
|
||||
Err(_) => bundle_settings
|
||||
};
|
||||
|
||||
Ok(Settings {
|
||||
package,
|
||||
package_type,
|
||||
@ -245,7 +251,7 @@ impl Settings {
|
||||
project_out_directory: target_dir,
|
||||
binary_path,
|
||||
binary_name,
|
||||
bundle_settings,
|
||||
bundle_settings: merged_bundle_settings,
|
||||
})
|
||||
}
|
||||
|
||||
@ -584,6 +590,39 @@ fn add_external_bin(bundle_settings: BundleSettings) -> crate::Result<BundleSett
|
||||
})
|
||||
}
|
||||
|
||||
fn options_value<T>(first: Option<T>, second: Option<T>) -> Option<T> {
|
||||
if first.is_some() {
|
||||
first
|
||||
}
|
||||
else {
|
||||
second
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_settings(
|
||||
bundle_settings: BundleSettings,
|
||||
config: crate::bundle::tauri_config::BundleConfig
|
||||
) -> BundleSettings {
|
||||
BundleSettings {
|
||||
name: options_value(config.name, bundle_settings.name),
|
||||
identifier: options_value(config.identifier, bundle_settings.identifier),
|
||||
icon: options_value(config.icon, bundle_settings.icon),
|
||||
version: options_value(config.version, bundle_settings.version),
|
||||
resources: options_value(config.resources, bundle_settings.resources),
|
||||
copyright: options_value(config.copyright, bundle_settings.copyright),
|
||||
category: options_value(config.category, bundle_settings.category),
|
||||
short_description: options_value(config.short_description, bundle_settings.short_description),
|
||||
long_description: options_value(config.long_description, bundle_settings.long_description),
|
||||
script: options_value(config.script, bundle_settings.script),
|
||||
deb_depends: options_value(config.deb.depends, bundle_settings.deb_depends),
|
||||
osx_frameworks: options_value(config.osx.frameworks, bundle_settings.osx_frameworks),
|
||||
osx_minimum_system_version: options_value(config.osx.minimum_system_version, bundle_settings.osx_minimum_system_version),
|
||||
external_bin: options_value(config.external_bin, bundle_settings.external_bin),
|
||||
exception_domain: options_value(config.osx.exception_domain, bundle_settings.exception_domain),
|
||||
..bundle_settings
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ResourcePaths<'a> {
|
||||
pattern_iter: std::slice::Iter<'a, String>,
|
||||
glob_iter: Option<glob::Paths>,
|
||||
|
70
cli/tauri-bundler/src/bundle/tauri_config.rs
Normal file
70
cli/tauri-bundler/src/bundle/tauri_config.rs
Normal file
@ -0,0 +1,70 @@
|
||||
use serde::Deserialize;
|
||||
use super::category::AppCategory;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use std::fs;
|
||||
|
||||
#[derive(PartialEq, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(tag = "deb", rename_all = "camelCase")]
|
||||
pub struct DebConfig {
|
||||
pub depends: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(tag = "deb", rename_all = "camelCase")]
|
||||
pub struct OsxConfig {
|
||||
pub frameworks: Option<Vec<String>>,
|
||||
pub minimum_system_version: Option<String>,
|
||||
pub exception_domain: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(tag = "bundle", rename_all = "camelCase")]
|
||||
pub struct BundleConfig {
|
||||
pub name: Option<String>,
|
||||
pub identifier: Option<String>,
|
||||
pub icon: Option<Vec<String>>,
|
||||
pub version: Option<String>,
|
||||
pub resources: Option<Vec<String>>,
|
||||
pub copyright: Option<String>,
|
||||
pub category: Option<AppCategory>,
|
||||
pub short_description: Option<String>,
|
||||
pub long_description: Option<String>,
|
||||
pub script: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub deb: DebConfig,
|
||||
#[serde(default)]
|
||||
pub osx: OsxConfig,
|
||||
pub external_bin: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Deserialize, Clone, Debug, Default)]
|
||||
#[serde(tag = "tauri", rename_all = "camelCase")]
|
||||
pub struct TauriConfig {
|
||||
#[serde(default)]
|
||||
pub bundle: BundleConfig,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Deserialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub tauri: TauriConfig,
|
||||
}
|
||||
|
||||
pub fn get() -> crate::Result<Config> {
|
||||
match std::env::var_os("TAURI_CONFIG") {
|
||||
Some(config) => {
|
||||
let json = &config.into_string().expect("failed to read TAURI_CONFIG");
|
||||
Ok(serde_json::from_str(json)?)
|
||||
},
|
||||
None => match std::env::var_os("TAURI_DIR") {
|
||||
Some(tauri_dir) => {
|
||||
let tauri_dir_str = tauri_dir.into_string().expect("failed to read TAURI_DIR");
|
||||
let json = &fs::read_to_string(format!("{}{}", tauri_dir_str, "/tauri.conf.json"))?;
|
||||
Ok(serde_json::from_str(json)?)
|
||||
},
|
||||
None => Err(crate::Error::from("Couldn't get tauri config; please specify the TAURI_CONFIG or TAURI_DIR environment variables"))
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ error_chain! {
|
||||
ConvertError(std::num::TryFromIntError);
|
||||
RegexError(::regex::Error) #[cfg(windows)];
|
||||
HttpError(::attohttpc::Error) #[cfg(windows)];
|
||||
Json(::serde_json::error::Error);
|
||||
}
|
||||
errors {}
|
||||
}
|
||||
|
@ -9,7 +9,23 @@ export default {
|
||||
active: true
|
||||
},
|
||||
bundle: {
|
||||
active: true
|
||||
active: true,
|
||||
identifier: 'com.tauri.dev',
|
||||
icon: ['icons/32x32.png', 'icons/128x128.png', 'icons/128x128@2x.png', 'icons/icon.icns', 'icons/icon.ico'],
|
||||
resources: [],
|
||||
externalBin: [],
|
||||
copyright: '',
|
||||
category: '',
|
||||
shortDescription: '',
|
||||
longDescription: '',
|
||||
deb: {
|
||||
depends: []
|
||||
},
|
||||
osx: {
|
||||
frameworks: [],
|
||||
minimumSystemVersion: ''
|
||||
},
|
||||
exceptionDomain: ''
|
||||
},
|
||||
whitelist: {
|
||||
all: true
|
||||
|
@ -24,10 +24,6 @@ dev-server = [ "tauri/dev-server" ]
|
||||
embedded-server = [ "tauri/embedded-server" ]
|
||||
no-server = [ "tauri/no-server" ]
|
||||
|
||||
[package.metadata.bundle]
|
||||
identifier = "com.tauri.dev"
|
||||
icon = ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"]
|
||||
|
||||
[[bin]]
|
||||
name = "app"
|
||||
path = "src/main.rs"
|
||||
|
Loading…
Reference in New Issue
Block a user