feat(cli/init): allow empty responses non-crucial questions (#9183)

closes #9181
This commit is contained in:
Amr Bashir 2024-03-19 15:41:41 +02:00 committed by GitHub
parent 81b853bc87
commit ac76a22f38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 34 deletions

View File

@ -0,0 +1,6 @@
---
'tauri-cli': 'patch:enhance'
'@tauri-apps/cli': 'patch:enhance'
---
Allow empty responses for `devUrl`, `beforeDevCommand` and `beforeBuildCommands` questions in `tauri init`.

View File

@ -15,6 +15,7 @@ pub fn input<T>(
where
T: Clone + FromStr + Display + ToString,
T::Err: Display + std::fmt::Debug,
T: PartialEq<str>,
{
if skip {
Ok(initial)
@ -28,7 +29,10 @@ where
builder = builder.with_initial_text(v.to_string());
}
builder.interact_text().map(Some).map_err(Into::into)
builder
.interact_text()
.map(|t: T| if t.ne("") { Some(t) } else { None })
.map_err(Into::into)
}
}

View File

@ -89,18 +89,28 @@ impl Options {
self.app_name = self.app_name.map(|s| Ok(Some(s))).unwrap_or_else(|| {
prompts::input(
"What is your app name?",
init_defaults.app_name.clone(),
Some(
init_defaults
.app_name
.clone()
.unwrap_or_else(|| "Tauri App".to_string()),
),
self.ci,
false,
true,
)
})?;
self.window_title = self.window_title.map(|s| Ok(Some(s))).unwrap_or_else(|| {
prompts::input(
"What should the window title be?",
init_defaults.app_name.clone(),
Some(
init_defaults
.app_name
.clone()
.unwrap_or_else(|| "Tauri".to_string()),
),
self.ci,
false,
true,
)
})?;
@ -116,7 +126,7 @@ impl Options {
"What is the url of your dev server?",
init_defaults.framework.map(|f| f.dev_url()),
self.ci,
false,
true,
)
})?;
@ -131,6 +141,7 @@ impl Options {
true,
)
})?;
self.before_build_command = self
.before_build_command
.map(|s| Ok(Some(s)))
@ -186,35 +197,21 @@ pub fn command(mut options: Options) -> Result<()> {
data.insert("tauri_build_dep", to_json(tauri_build_dep));
data.insert(
"frontend_dist",
to_json(
options
.frontend_dist
.unwrap_or_else(|| "../dist".to_string()),
),
);
data.insert(
"dev_url",
to_json(
options
.dev_url
.unwrap_or_else(|| "http://localhost:4000".to_string()),
),
to_json(options.frontend_dist.as_deref().unwrap_or("../dist")),
);
data.insert("dev_url", to_json(options.dev_url));
data.insert(
"app_name",
to_json(options.app_name.unwrap_or_else(|| "Tauri App".to_string())),
to_json(options.app_name.as_deref().unwrap_or("Tauri App")),
);
data.insert(
"window_title",
to_json(options.window_title.unwrap_or_else(|| "Tauri".to_string())),
);
data.insert(
"before_dev_command",
to_json(options.before_dev_command.unwrap_or_default()),
to_json(options.window_title.as_deref().unwrap_or("Tauri")),
);
data.insert("before_dev_command", to_json(options.before_dev_command));
data.insert(
"before_build_command",
to_json(options.before_build_command.unwrap_or_default()),
to_json(options.before_build_command),
);
let mut config = serde_json::from_str(

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
use crate::{
helpers::{prompts::input, template},
helpers::{prompts, template},
Result,
};
use clap::{Parser, Subcommand};
@ -59,7 +59,7 @@ pub fn command(cli: Cli) -> Result<()> {
return Err(anyhow::anyhow!("android folder already exists"));
}
let plugin_id = input(
let plugin_id = prompts::input(
"What should be the Android Package ID for your plugin?",
Some(format!("com.plugin.{}", plugin_name)),
false,

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use crate::helpers::prompts::input;
use crate::helpers::prompts;
use crate::Result;
use crate::{
helpers::{resolve_tauri_path, template},
@ -141,7 +141,7 @@ pub fn command(mut options: Options) -> Result<()> {
}
let plugin_id = if options.android || options.mobile {
let plugin_id = input(
let plugin_id = prompts::input(
"What should be the Android Package ID for your plugin?",
Some(format!("com.plugin.{}", plugin_name)),
false,

View File

@ -3,10 +3,10 @@
"version": "0.1.0",
"identifier": "com.tauri.dev",
"build": {
"frontendDist": "{{ frontend_dist }}",
"devUrl": "{{ dev_url }}",
"beforeDevCommand": "{{ before_dev_command }}",
"beforeBuildCommand": "{{ before_build_command }}"
"frontendDist": "{{ frontend_dist }}"{{#if dev_url}},
"devUrl": "{{ dev_url }}"{{/if}}{{#if before_dev_command}},
"beforeDevCommand": "{{ before_dev_command }}"{{/if}}{{#if before_build_command}},
"beforeBuildCommand": "{{ before_build_command }}"{{/if}}
},
"app": {
"windows": [