mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-24 19:25:12 +03:00
feat(cli): check if project identifier or lib name changed (#10479)
* feat(cli): check if project identifier changed * implement ios check * also check lib name * clippy * ensure_init from xcode-script * fill change file [skip ci]
This commit is contained in:
parent
7e810cb2a3
commit
ca68689564
6
.changes/cli-mobile-checks.md
Normal file
6
.changes/cli-mobile-checks.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-cli": patch:enhance
|
||||
"@tauri-apps/cli": patch:enhance
|
||||
---
|
||||
|
||||
Check if identifier or lib name changed when running mobile commands.
|
@ -54,7 +54,12 @@ pub fn command(options: Options) -> Result<()> {
|
||||
);
|
||||
(config, metadata, cli_options)
|
||||
};
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Android,
|
||||
)?;
|
||||
|
||||
let env = env()?;
|
||||
|
||||
|
@ -131,7 +131,12 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
|
||||
let tauri_path = tauri_dir();
|
||||
set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?;
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Android,
|
||||
)?;
|
||||
|
||||
let mut env = env()?;
|
||||
configure_cargo(&app, Some((&mut env, &config)))?;
|
||||
|
@ -145,7 +145,12 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
|
||||
let tauri_path = tauri_dir();
|
||||
set_current_dir(tauri_path).with_context(|| "failed to change current working directory")?;
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Android,
|
||||
)?;
|
||||
run_dev(
|
||||
interface,
|
||||
options,
|
||||
|
@ -24,7 +24,12 @@ pub fn command() -> Result<()> {
|
||||
&Default::default(),
|
||||
)
|
||||
};
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Android,
|
||||
)?;
|
||||
inject_assets(&config, tauri_config.lock().unwrap().as_ref().unwrap())?;
|
||||
let env = env()?;
|
||||
os::open_file_with("Android Studio", config.project_dir(), &env.base).map_err(Into::into)
|
||||
|
@ -156,7 +156,12 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
|
||||
let tauri_path = tauri_dir();
|
||||
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Ios,
|
||||
)?;
|
||||
inject_assets(&config)?;
|
||||
|
||||
let info_plist_path = config
|
||||
|
@ -168,7 +168,12 @@ fn run_command(options: Options, noise_level: NoiseLevel) -> Result<()> {
|
||||
let tauri_path = tauri_dir();
|
||||
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Ios,
|
||||
)?;
|
||||
inject_assets(&config)?;
|
||||
|
||||
let info_plist_path = config
|
||||
|
@ -25,7 +25,12 @@ pub fn command() -> Result<()> {
|
||||
)
|
||||
};
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)?;
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Ios,
|
||||
)?;
|
||||
inject_assets(&config)?;
|
||||
let env = env()?;
|
||||
os::open_file_with("Xcode", config.project_dir(), &env).map_err(Into::into)
|
||||
|
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use super::{env, get_app, get_config, read_options};
|
||||
use super::{ensure_init, env, get_app, get_config, read_options, MobileTarget};
|
||||
use crate::{
|
||||
helpers::config::get as get_tauri_config,
|
||||
interface::{AppInterface, AppSettings, Interface, Options as InterfaceOptions},
|
||||
@ -82,6 +82,12 @@ pub fn command(options: Options) -> Result<()> {
|
||||
);
|
||||
(config, metadata, cli_options)
|
||||
};
|
||||
ensure_init(
|
||||
&tauri_config,
|
||||
config.app(),
|
||||
config.project_dir(),
|
||||
MobileTarget::Ios,
|
||||
)?;
|
||||
|
||||
let env = env()?.explicit_env_vars(cli_options.vars);
|
||||
|
||||
|
@ -3,9 +3,14 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use crate::{
|
||||
helpers::{app_paths::tauri_dir, config::Config as TauriConfig},
|
||||
helpers::{
|
||||
app_paths::tauri_dir,
|
||||
config::{Config as TauriConfig, ConfigHandle},
|
||||
},
|
||||
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
use anyhow::Context;
|
||||
use anyhow::{bail, Result};
|
||||
use heck::ToSnekCase;
|
||||
use jsonrpsee::core::client::{Client, ClientBuilder, ClientT};
|
||||
@ -277,7 +282,13 @@ pub fn get_app(config: &TauriConfig, interface: &AppInterface) -> App {
|
||||
})
|
||||
}
|
||||
|
||||
fn ensure_init(project_dir: PathBuf, target: Target) -> Result<()> {
|
||||
#[allow(unused_variables)]
|
||||
fn ensure_init(
|
||||
tauri_config: &ConfigHandle,
|
||||
app: &App,
|
||||
project_dir: PathBuf,
|
||||
target: Target,
|
||||
) -> Result<()> {
|
||||
if !project_dir.exists() {
|
||||
bail!(
|
||||
"{} project directory {} doesn't exist. Please run `tauri {} init` and try again.",
|
||||
@ -286,6 +297,51 @@ fn ensure_init(project_dir: PathBuf, target: Target) -> Result<()> {
|
||||
target.command_name(),
|
||||
)
|
||||
}
|
||||
|
||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
||||
|
||||
let mut project_outdated_reasons = Vec::new();
|
||||
|
||||
match target {
|
||||
Target::Android => {
|
||||
let java_folder = project_dir
|
||||
.join("app/src/main/java")
|
||||
.join(tauri_config_.identifier.replace('.', "/"));
|
||||
if !java_folder.exists() {
|
||||
project_outdated_reasons
|
||||
.push("you have modified your \"identifier\" in the Tauri configuration");
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
Target::Ios => {
|
||||
let project_yml = read_to_string(project_dir.join("project.yml"))
|
||||
.context("missing project.yml file in the Xcode project directory")?;
|
||||
if !project_yml.contains(&format!(
|
||||
"PRODUCT_BUNDLE_IDENTIFIER: {}",
|
||||
tauri_config_.identifier
|
||||
)) {
|
||||
project_outdated_reasons
|
||||
.push("you have modified your \"identifier\" in the Tauri configuration");
|
||||
}
|
||||
|
||||
println!("{}", app.lib_name());
|
||||
if !project_yml.contains(&format!("framework: lib{}.a", app.lib_name())) {
|
||||
project_outdated_reasons
|
||||
.push("you have modified your [lib.name] or [package.name] in the Cargo.toml file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !project_outdated_reasons.is_empty() {
|
||||
let reason = project_outdated_reasons.join(" and ");
|
||||
bail!(
|
||||
"{} project directory is outdated because {reason}. Please run `tauri {} init` and try again.",
|
||||
target.ide_name(),
|
||||
target.command_name(),
|
||||
)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user