Skip to content

Commit d1ce9af

Browse files
authored
feat(cli): add --config arg to the mobile init cmds, closes #13284 (#13660)
1 parent ec6065f commit d1ce9af

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

.changes/mobile-init-config.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": "minor:feat"
3+
"@tauri-apps/cli": "minor:feat"
4+
---
5+
6+
Allow passing `--config` arguments to the `ios init` and `android init` commands to tweak the configuration used to initialize the mobile projects.

crates/tauri-cli/src/mobile/android/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::{
3434
};
3535
use crate::{
3636
helpers::config::{BundleResources, Config as TauriConfig},
37-
Result,
37+
ConfigValue, Result,
3838
};
3939

4040
mod android_studio_script;
@@ -64,6 +64,15 @@ pub struct InitOptions {
6464
/// Skips installing rust toolchains via rustup
6565
#[clap(long)]
6666
skip_targets_install: bool,
67+
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
68+
///
69+
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
70+
///
71+
/// Note that a platform-specific file is looked up and merged with the default file by default
72+
/// (tauri.macos.conf.json, tauri.linux.conf.json, tauri.windows.conf.json, tauri.android.conf.json and tauri.ios.conf.json)
73+
/// but you can use this for more specific use cases such as different build flavors.
74+
#[clap(short, long)]
75+
pub config: Vec<ConfigValue>,
6776
}
6877

6978
#[derive(Subcommand)]
@@ -85,6 +94,7 @@ pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
8594
options.ci,
8695
false,
8796
options.skip_targets_install,
97+
options.config,
8898
)?
8999
}
90100
Commands::Dev(options) => dev::command(options, noise_level)?,

crates/tauri-cli/src/mobile/init.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{get_app, Target};
66
use crate::{
77
helpers::{config::get as get_tauri_config, template::JsonMap},
88
interface::{AppInterface, Interface},
9-
Result,
9+
ConfigValue, Result,
1010
};
1111
use cargo_mobile2::{
1212
android::env::Env as AndroidEnv,
@@ -28,11 +28,19 @@ pub fn command(
2828
ci: bool,
2929
reinstall_deps: bool,
3030
skip_targets_install: bool,
31+
config: Vec<ConfigValue>,
3132
) -> Result<()> {
3233
let wrapper = TextWrapper::default();
3334

34-
exec(target, &wrapper, ci, reinstall_deps, skip_targets_install)
35-
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
35+
exec(
36+
target,
37+
&wrapper,
38+
ci,
39+
reinstall_deps,
40+
skip_targets_install,
41+
config,
42+
)
43+
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
3644
Ok(())
3745
}
3846

@@ -42,8 +50,12 @@ pub fn exec(
4250
#[allow(unused_variables)] non_interactive: bool,
4351
#[allow(unused_variables)] reinstall_deps: bool,
4452
skip_targets_install: bool,
53+
config: Vec<ConfigValue>,
4554
) -> Result<App> {
46-
let tauri_config = get_tauri_config(target.platform_target(), &[])?;
55+
let tauri_config = get_tauri_config(
56+
target.platform_target(),
57+
&config.iter().map(|conf| &conf.0).collect::<Vec<_>>(),
58+
)?;
4759

4860
let tauri_config_guard = tauri_config.lock().unwrap();
4961
let tauri_config_ = tauri_config_guard.as_ref().unwrap();

crates/tauri-cli/src/mobile/ios/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::{
3232
config::{BundleResources, Config as TauriConfig, ConfigHandle},
3333
pbxproj, strip_semver_prerelease_tag,
3434
},
35-
Result,
35+
ConfigValue, Result,
3636
};
3737

3838
use std::{
@@ -77,6 +77,15 @@ pub struct InitOptions {
7777
/// Skips installing rust toolchains via rustup
7878
#[clap(long)]
7979
skip_targets_install: bool,
80+
/// JSON strings or paths to JSON, JSON5 or TOML files to merge with the default configuration file
81+
///
82+
/// Configurations are merged in the order they are provided, which means a particular value overwrites previous values when a config key-value pair conflicts.
83+
///
84+
/// Note that a platform-specific file is looked up and merged with the default file by default
85+
/// (tauri.macos.conf.json, tauri.linux.conf.json, tauri.windows.conf.json, tauri.android.conf.json and tauri.ios.conf.json)
86+
/// but you can use this for more specific use cases such as different build flavors.
87+
#[clap(short, long)]
88+
pub config: Vec<ConfigValue>,
8089
}
8190

8291
#[derive(Subcommand)]
@@ -98,6 +107,7 @@ pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
98107
options.ci,
99108
options.reinstall_deps,
100109
options.skip_targets_install,
110+
options.config,
101111
)?
102112
}
103113
Commands::Dev(options) => dev::command(options, noise_level)?,

0 commit comments

Comments
 (0)