feat(cli): add --reinstall-deps option to ios init

This commit is contained in:
Lucas Nogueira 2022-09-01 12:07:06 -03:00
parent 8f3a9c5cf6
commit 5d82357166
No known key found for this signature in database
GPG Key ID: C54D79C4018F1D19
4 changed files with 32 additions and 30 deletions

View File

@ -26,7 +26,7 @@ use sublime_fuzzy::best_match;
use super::{ use super::{
ensure_init, get_app, ensure_init, get_app,
init::{command as init_command, init_dot_cargo, Options as InitOptions}, init::{command as init_command, init_dot_cargo},
log_finished, read_options, CliOptions, Target as MobileTarget, MIN_DEVICE_MATCH_SCORE, log_finished, read_options, CliOptions, Target as MobileTarget, MIN_DEVICE_MATCH_SCORE,
}; };
use crate::{ use crate::{
@ -53,6 +53,14 @@ pub struct Cli {
command: Commands, command: Commands,
} }
#[derive(Debug, Parser)]
#[clap(about = "Initializes a Tauri Android project")]
pub struct InitOptions {
/// Skip prompting for values
#[clap(long)]
ci: bool,
}
#[derive(Subcommand)] #[derive(Subcommand)]
enum Commands { enum Commands {
Init(InitOptions), Init(InitOptions),
@ -67,7 +75,7 @@ enum Commands {
pub fn command(cli: Cli, verbosity: usize) -> Result<()> { pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
let noise_level = NoiseLevel::from_occurrences(verbosity as u64); let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
match cli.command { match cli.command {
Commands::Init(options) => init_command(options, MobileTarget::Android)?, Commands::Init(options) => init_command(MobileTarget::Android, options.ci, false)?,
Commands::Open => open::command()?, Commands::Open => open::command()?,
Commands::Dev(options) => dev::command(options, noise_level)?, Commands::Dev(options) => dev::command(options, noise_level)?,
Commands::Build(options) => build::command(options, noise_level)?, Commands::Build(options) => build::command(options, noise_level)?,

View File

@ -11,31 +11,25 @@ use cargo_mobile::{
}, },
config::app::App, config::app::App,
dot_cargo, dot_cargo,
os::code_command,
target::TargetTrait as _, target::TargetTrait as _,
util::{ util::{
self, self,
cli::{Report, TextWrapper}, cli::{Report, TextWrapper},
}, },
}; };
use clap::Parser;
use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError}; use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError};
use std::{env::current_dir, fs, path::PathBuf}; use std::{env::current_dir, fs, path::PathBuf};
#[derive(Debug, Parser)] pub fn command(target: Target, ci: bool, reinstall_deps: bool) -> Result<()> {
#[clap(about = "Initializes a Tauri Android project")]
pub struct Options {
/// Skip prompting for values
#[clap(long)]
ci: bool,
}
pub fn command(mut options: Options, target: Target) -> Result<()> {
options.ci = options.ci || std::env::var("CI").is_ok();
let wrapper = TextWrapper::with_splitter(textwrap::termwidth(), textwrap::NoHyphenation); let wrapper = TextWrapper::with_splitter(textwrap::termwidth(), textwrap::NoHyphenation);
exec(target, &wrapper, options.ci, true, true).map_err(|e| anyhow::anyhow!("{:#}", e))?; exec(
target,
&wrapper,
ci || std::env::var("CI").is_ok(),
reinstall_deps,
)
.map_err(|e| anyhow::anyhow!("{:#}", e))?;
Ok(()) Ok(())
} }
@ -69,7 +63,6 @@ pub fn exec(
target: Target, target: Target,
wrapper: &TextWrapper, wrapper: &TextWrapper,
non_interactive: bool, non_interactive: bool,
skip_dev_tools: bool,
#[allow(unused_variables)] reinstall_deps: bool, #[allow(unused_variables)] reinstall_deps: bool,
) -> Result<App> { ) -> Result<App> {
let tauri_config = get_tauri_config(None)?; let tauri_config = get_tauri_config(None)?;
@ -87,14 +80,6 @@ pub fn exec(
) )
})?; })?;
} }
if !skip_dev_tools && util::command_present("code").unwrap_or_default() {
let mut command = code_command();
command.add_args(&["--install-extension", "vadimcn.vscode-lldb"]);
if non_interactive {
command.add_arg("--force");
}
command.run_and_wait()?;
}
let (handlebars, mut map) = handlebars(&app); let (handlebars, mut map) = handlebars(&app);
@ -169,7 +154,6 @@ pub fn exec(
(handlebars, map), (handlebars, map),
wrapper, wrapper,
non_interactive, non_interactive,
skip_dev_tools,
reinstall_deps, reinstall_deps,
)?; )?;
init_dot_cargo(&app, None)?; init_dot_cargo(&app, None)?;

View File

@ -23,7 +23,7 @@ use sublime_fuzzy::best_match;
use super::{ use super::{
ensure_init, env, get_app, ensure_init, env, get_app,
init::{command as init_command, init_dot_cargo, Options as InitOptions}, init::{command as init_command, init_dot_cargo},
log_finished, read_options, CliOptions, Target as MobileTarget, MIN_DEVICE_MATCH_SCORE, log_finished, read_options, CliOptions, Target as MobileTarget, MIN_DEVICE_MATCH_SCORE,
}; };
use crate::{ use crate::{
@ -55,6 +55,17 @@ pub struct Cli {
command: Commands, command: Commands,
} }
#[derive(Debug, Parser)]
#[clap(about = "Initializes a Tauri iOS project")]
pub struct InitOptions {
/// Skip prompting for values
#[clap(long)]
ci: bool,
/// Reinstall dependencies
#[clap(short, long)]
reinstall_deps: bool,
}
#[derive(Subcommand)] #[derive(Subcommand)]
enum Commands { enum Commands {
Init(InitOptions), Init(InitOptions),
@ -68,7 +79,7 @@ enum Commands {
pub fn command(cli: Cli, verbosity: usize) -> Result<()> { pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
let noise_level = NoiseLevel::from_occurrences(verbosity as u64); let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
match cli.command { match cli.command {
Commands::Init(options) => init_command(options, MobileTarget::Ios)?, Commands::Init(options) => init_command(MobileTarget::Ios, options.ci, options.reinstall_deps)?,
Commands::Open => open::command()?, Commands::Open => open::command()?,
Commands::Dev(options) => dev::command(options, noise_level)?, Commands::Dev(options) => dev::command(options, noise_level)?,
Commands::Build(options) => build::command(options, noise_level)?, Commands::Build(options) => build::command(options, noise_level)?,

View File

@ -32,14 +32,13 @@ pub fn gen(
(handlebars, mut map): (Handlebars, template::JsonMap), (handlebars, mut map): (Handlebars, template::JsonMap),
wrapper: &TextWrapper, wrapper: &TextWrapper,
non_interactive: bool, non_interactive: bool,
skip_dev_tools: bool,
reinstall_deps: bool, reinstall_deps: bool,
) -> Result<()> { ) -> Result<()> {
println!("Installing iOS toolchains..."); println!("Installing iOS toolchains...");
Target::install_all()?; Target::install_all()?;
rust_version_check(wrapper)?; rust_version_check(wrapper)?;
deps::install_all(wrapper, non_interactive, skip_dev_tools, reinstall_deps) deps::install_all(wrapper, non_interactive, true, reinstall_deps)
.with_context(|| "failed to install Apple dependencies")?; .with_context(|| "failed to install Apple dependencies")?;
let dest = config.project_dir(); let dest = config.project_dir();