Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/mobile-init-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": "minor:feat"
"@tauri-apps/cli": "minor:feat"
---

Allow passing `--config` arguments to the `ios init` and `android init` commands to tweak the configuration used to initialize the mobile projects.
12 changes: 11 additions & 1 deletion crates/tauri-cli/src/mobile/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use super::{
};
use crate::{
helpers::config::{BundleResources, Config as TauriConfig},
Result,
ConfigValue, Result,
};

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

#[derive(Subcommand)]
Expand All @@ -85,6 +94,7 @@ pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
options.ci,
false,
options.skip_targets_install,
options.config,
)?
}
Commands::Dev(options) => dev::command(options, noise_level)?,
Expand Down
20 changes: 16 additions & 4 deletions crates/tauri-cli/src/mobile/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{get_app, Target};
use crate::{
helpers::{config::get as get_tauri_config, template::JsonMap},
interface::{AppInterface, Interface},
Result,
ConfigValue, Result,
};
use cargo_mobile2::{
android::env::Env as AndroidEnv,
Expand All @@ -28,11 +28,19 @@ pub fn command(
ci: bool,
reinstall_deps: bool,
skip_targets_install: bool,
config: Vec<ConfigValue>,
) -> Result<()> {
let wrapper = TextWrapper::default();

exec(target, &wrapper, ci, reinstall_deps, skip_targets_install)
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
exec(
target,
&wrapper,
ci,
reinstall_deps,
skip_targets_install,
config,
)
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
Ok(())
}

Expand All @@ -42,8 +50,12 @@ pub fn exec(
#[allow(unused_variables)] non_interactive: bool,
#[allow(unused_variables)] reinstall_deps: bool,
skip_targets_install: bool,
config: Vec<ConfigValue>,
) -> Result<App> {
let tauri_config = get_tauri_config(target.platform_target(), &[])?;
let tauri_config = get_tauri_config(
target.platform_target(),
&config.iter().map(|conf| &conf.0).collect::<Vec<_>>(),
)?;

let tauri_config_guard = tauri_config.lock().unwrap();
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
Expand Down
12 changes: 11 additions & 1 deletion crates/tauri-cli/src/mobile/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
config::{BundleResources, Config as TauriConfig, ConfigHandle},
pbxproj, strip_semver_prerelease_tag,
},
Result,
ConfigValue, Result,
};

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

#[derive(Subcommand)]
Expand All @@ -98,6 +107,7 @@ pub fn command(cli: Cli, verbosity: u8) -> Result<()> {
options.ci,
options.reinstall_deps,
options.skip_targets_install,
options.config,
)?
}
Commands::Dev(options) => dev::command(options, noise_level)?,
Expand Down