Skip to content

Commit 4a2f33b

Browse files
authored
feat: add --no-mobile (#628)
1 parent a999e19 commit 4a2f33b

36 files changed

Lines changed: 110 additions & 88 deletions

File tree

.changes/no-mobile.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"create-tauri-app": "patch"
3+
"create-tauri-app-js": "patch"
4+
---
5+
6+
Add `--no-mobile` flag.
7+

src/args.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ pub struct Args {
1515
pub template: Option<Template>,
1616
pub skip: bool,
1717
pub force: bool,
18-
pub alpha: bool,
18+
pub beta: bool,
1919
pub mobile: Option<bool>,
20+
pub no_mobile: Option<bool>,
2021
}
2122

2223
impl Default for Args {
@@ -27,8 +28,9 @@ impl Default for Args {
2728
template: Some(Template::Vanilla),
2829
skip: false,
2930
force: false,
30-
alpha: false,
31-
mobile: Some(false),
31+
beta: false,
32+
mobile: Some(false), // default for this value must be Some(false), as we use it as fallback when -y is used
33+
no_mobile: None,
3234
}
3335
}
3436
}
@@ -54,8 +56,9 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
5456
{GREEN}-t{RESET}, {GREEN}--template <TEMPLATE>{RESET} Specify the UI template to use [{templates}]
5557
{GREEN}-y{RESET}, {GREEN}--yes{RESET} Skip prompts and use defaults where applicable
5658
{GREEN}-f{RESET}, {GREEN}--force{RESET} Force create the directory even if it is not empty.
57-
{GREEN}--beta{RESET} Bootstraps a project using tauri@2.0-alpha
59+
{GREEN}--beta{RESET} Bootstraps a project using tauri@2.0-beta
5860
{GREEN}--mobile{RESET} Bootstraps a mobile project too. Only availabe with `--beta` option.
61+
{GREEN}--no-mobile{RESET} Skip bootstraping a mobile project. Only availabe with `--beta` option.
5962
{GREEN}-h{RESET}, {GREEN}--help{RESET} Prints help information
6063
{GREEN}-v{RESET}, {GREEN}--version{RESET} Prints version information
6164
"#,
@@ -84,7 +87,7 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
8487
}
8588

8689
// pargs.contains() consume the flag so we have to bind the bool to a variable.
87-
let alpha = if pargs.contains("--alpha") {
90+
let beta = if pargs.contains("--alpha") {
8891
eprintln!(
8992
"{BOLD}{YELLOW}warning{RESET}: The `{GREEN}--alpha{RESET}` option is now an alias for `{GREEN}--beta{RESET}` and may be removed in the future."
9093
);
@@ -98,12 +101,17 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
98101
template: pargs.opt_value_from_str(["-t", "--template"])?,
99102
skip: pargs.contains(["-y", "--yes"]),
100103
force: pargs.contains(["-f", "--force"]),
101-
alpha,
104+
beta,
102105
mobile: if pargs.contains("--mobile") {
103106
Some(true)
104107
} else {
105108
None
106109
},
110+
no_mobile: if pargs.contains("--no-mobile") {
111+
Some(true)
112+
} else {
113+
None
114+
},
107115
project_name: pargs.opt_free_from_str()?,
108116
};
109117

src/deps.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ fn is_trunk_installed() -> bool {
3737
.unwrap_or(false)
3838
}
3939

40-
fn is_appropriate_tauri_cli_installed(alpha: bool) -> bool {
40+
fn is_appropriate_tauri_cli_installed(beta: bool) -> bool {
4141
let check = |o: Output| match o.status.success() {
4242
true => String::from_utf8_lossy(&o.stdout)
4343
.split_once(' ')
44-
.map(|(_, v)| v.starts_with(if alpha { '2' } else { '1' }))
44+
.map(|(_, v)| v.starts_with(if beta { '2' } else { '1' }))
4545
.unwrap_or(false),
4646
s => s,
4747
};
@@ -111,9 +111,9 @@ fn is_webview2_installed() -> bool {
111111
target_os = "openbsd",
112112
target_os = "netbsd"
113113
))]
114-
fn is_webkit2gtk_installed(alpha: bool) -> bool {
114+
fn is_webkit2gtk_installed(beta: bool) -> bool {
115115
Command::new("pkg-config")
116-
.arg(if alpha {
116+
.arg(if beta {
117117
"webkit2gtk-4.1"
118118
} else {
119119
"webkit2gtk-4.0"
@@ -155,7 +155,7 @@ struct Dep<'a> {
155155
}
156156

157157
/// Print missing deps in a table and returns whether there was any missing deps.
158-
pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha: bool) -> bool {
158+
pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, beta: bool) -> bool {
159159
let rustc_installed = is_rustc_installed();
160160
let cargo_installed = is_cargo_installed();
161161

@@ -167,7 +167,7 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
167167
target_os = "netbsd"
168168
))]
169169
let (webkit2gtk_installed, rsvg2_installed) =
170-
(is_webkit2gtk_installed(alpha), is_rsvg2_installed());
170+
(is_webkit2gtk_installed(beta), is_rsvg2_installed());
171171

172172
let deps: &[Dep<'_>] = &[
173173
Dep {
@@ -190,12 +190,12 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
190190
},
191191
Dep {
192192
name: "Tauri CLI",
193-
instruction: if alpha {
193+
instruction: if beta {
194194
format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0-beta'{RESET}`")
195195
} else {
196196
format!("Run `{BLUE}{BOLD}cargo install tauri-cli{RESET}`")
197197
},
198-
exists: &|| is_appropriate_tauri_cli_installed(alpha),
198+
exists: &|| is_appropriate_tauri_cli_installed(beta),
199199
skip: pkg_manager.is_node() || !template.needs_tauri_cli(),
200200
},
201201
Dep {
@@ -232,8 +232,8 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
232232
))]
233233
Dep {
234234
name: "webkit2gtk & rsvg2",
235-
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if alpha {
236-
"https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux#1-system-dependencies"
235+
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if beta {
236+
"https://beta.tauri.app/guides/prerequisites/#linux"
237237
} else {
238238
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
239239
}),
@@ -249,8 +249,8 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
249249
))]
250250
Dep {
251251
name: "webkit2gtk",
252-
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if alpha {
253-
"https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux#1-system-dependencies"
252+
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if beta {
253+
"https://beta.tauri.app/guides/prerequisites/#linux"
254254
} else {
255255
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
256256
}),
@@ -266,8 +266,8 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
266266
))]
267267
Dep {
268268
name: "rsvg2",
269-
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if alpha {
270-
"https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux#1-system-dependencies"
269+
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if beta {
270+
"https://beta.tauri.app/guides/prerequisites/#linux"
271271
} else {
272272
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
273273
}),

src/lib.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ where
6666
let defaults = args::Args::default();
6767
let args::Args {
6868
skip,
69-
mobile,
70-
alpha,
69+
mut mobile,
70+
no_mobile,
71+
beta,
7172
manager,
7273
project_name,
7374
template,
@@ -77,13 +78,14 @@ where
7778

7879
// Allow `--mobile` to only be used with `--beta` for now
7980
// TODO: remove this limitation once tauri@v2 is stable
80-
if let Some(mobile) = mobile {
81-
if mobile && !alpha {
82-
eprintln!(
83-
"{BOLD}{RED}error{RESET}: `{GREEN}--mobile{RESET}` option is only available if `{GREEN}--beta{RESET}` option is also used"
84-
);
85-
exit(1);
86-
}
81+
if (mobile.is_some() || no_mobile.is_some()) && !beta {
82+
let flag = if mobile.is_some() {
83+
"--mobile"
84+
} else {
85+
"--no-mobile"
86+
};
87+
eprintln!("{BOLD}{RED}error{RESET}: `{GREEN}{}{RESET}` option is only available if `{GREEN}--beta{RESET}` option is also used", flag);
88+
exit(1);
8789
}
8890

8991
// Project name used for the project directory name and productName in tauri.conf.json
@@ -279,13 +281,18 @@ where
279281
}
280282
};
281283

284+
// if --no-mobile is specified, ignore --mobile and force it to fale
285+
if no_mobile.is_some() {
286+
mobile = Some(false);
287+
};
288+
282289
// Prompt for wether to bootstrap a mobile-friendly tauri project
283290
// This should only be prompted if `--beta` is used on the command line and `--mobile` wasn't.
284291
// TODO: remove this limitation once tauri@v2 is stable
285292
let mobile = match mobile {
286293
Some(mobile) => mobile,
287294
None => {
288-
if skip || !alpha {
295+
if skip || !beta {
289296
defaults.mobile.context("default mobile not set")?
290297
} else {
291298
Confirm::with_theme(&ColorfulTheme::default())
@@ -337,14 +344,14 @@ where
337344
pkg_manager,
338345
&project_name,
339346
&package_name,
340-
alpha,
347+
beta,
341348
mobile,
342349
)?;
343350

344351
// Print post-render instructions
345352
println!();
346353
print!("Template created!");
347-
let has_missing = print_missing_deps(pkg_manager, template, alpha);
354+
let has_missing = print_missing_deps(pkg_manager, template, beta);
348355
if has_missing {
349356
println!("Make sure you have installed the prerequisites for your OS: {BLUE}{BOLD}https://tauri.app/v1/guides/getting-started/prerequisites{RESET}, then run:");
350357
} else {

src/template.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a> Template {
244244
pkg_manager: PackageManager,
245245
project_name: &str,
246246
package_name: &str,
247-
alpha: bool,
247+
beta: bool,
248248
mobile: bool,
249249
) -> anyhow::Result<()> {
250250
let manifest_bytes =
@@ -257,9 +257,9 @@ impl<'a> Template {
257257

258258
let lib_name = format!("{}_lib", package_name.replace('-', "_"));
259259

260-
let alpha_str = alpha.to_string();
260+
let beta_str = beta.to_string();
261261
let manifest_template_data: HashMap<&str, &str> = [
262-
("alpha", alpha_str.as_str()),
262+
("beta", beta_str.as_str()),
263263
("pkg_manager_run_command", pkg_manager.run_cmd()),
264264
("lib_name", &lib_name),
265265
("package_name", package_name),
@@ -275,8 +275,8 @@ impl<'a> Template {
275275
.into();
276276

277277
let template_data: HashMap<&str, String> = [
278-
("stable", (!alpha).to_string()),
279-
("alpha", alpha_str.clone()),
278+
("stable", (!beta).to_string()),
279+
("beta", beta_str.clone()),
280280
("mobile", mobile.to_string()),
281281
("project_name", project_name.to_string()),
282282
("package_name", package_name.to_string()),
@@ -335,8 +335,8 @@ impl<'a> Template {
335335
// conditional files:
336336
// are files that start with a special syntax
337337
// "%(<list of flags separated by `-`>%)<file_name>"
338-
// flags are supported package managers, stable, alpha and mobile.
339-
// example: "%(pnpm-npm-yarn-stable-alpha)%package.json"
338+
// flags are supported package managers, stable, beta and mobile.
339+
// example: "%(pnpm-npm-yarn-stable-beta)%package.json"
340340
name if name.starts_with("%(") && name[1..].contains(")%") => {
341341
let mut s = name.strip_prefix("%(").unwrap().split(")%");
342342
let (mut flags, name) = (
@@ -345,16 +345,16 @@ impl<'a> Template {
345345
);
346346

347347
let for_stable = flags.contains(&"stable");
348-
let for_alpha = flags.contains(&"alpha");
348+
let for_beta = flags.contains(&"beta");
349349
let for_mobile = flags.contains(&"mobile");
350350

351351
// remove these flags to only keep package managers flags
352-
flags.retain(|e| !["stable", "alpha", "mobile"].contains(e));
352+
flags.retain(|e| !["stable", "beta", "mobile"].contains(e));
353353

354-
if ((for_stable && !alpha)
355-
|| (for_alpha && alpha && !mobile)
356-
|| (for_mobile && alpha && mobile)
357-
|| (!for_stable && !for_alpha && !for_mobile))
354+
if ((for_stable && !beta)
355+
|| (for_beta && beta && !mobile)
356+
|| (for_mobile && beta && mobile)
357+
|| (!for_stable && !for_beta && !for_mobile))
358358
&& (flags.contains(&pkg_manager.to_string().as_str()) || flags.is_empty())
359359
{
360360
name

templates/_base_/src-tauri/src/main.rs.lte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn greet(name: &str) -> String {
1111

1212
fn main() {
1313
tauri::Builder::default()
14-
{% if alpha %}.plugin(tauri_plugin_shell::init())
14+
{% if beta %}.plugin(tauri_plugin_shell::init())
1515
{% endif %}.invoke_handler(tauri::generate_handler![greet])
1616
.run(tauri::generate_context!())
1717
.expect("error while running tauri application");

templates/template-angular/package.json.lte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"rxjs": "~7.8.0",
2222
"tslib": "^2.3.0",
2323
"zone.js": "~0.14.2",
24-
"@tauri-apps/api": "{% if alpha %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if alpha %},
24+
"@tauri-apps/api": "{% if beta %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if beta %},
2525
"@tauri-apps/plugin-shell": ">=2.0.0-beta.0"{% endif %}
2626
},
2727
"devDependencies": {
@@ -36,7 +36,7 @@
3636
"karma-jasmine": "~5.1.0",
3737
"karma-jasmine-html-reporter": "~2.1.0",
3838
"typescript": "~5.2.2",
39-
"@tauri-apps/cli": "{% if alpha %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if mobile %},
39+
"@tauri-apps/cli": "{% if beta %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if mobile %},
4040
"internal-ip": "^7.0.0"{% endif %}
4141
}
4242
}

templates/template-angular/src/app/app.component.ts.lte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { RouterOutlet } from '@angular/router';
4-
import { invoke } from "@tauri-apps/api/{% if alpha %}core{% else %}tauri{% endif %}";
4+
import { invoke } from "@tauri-apps/api/{% if beta %}core{% else %}tauri{% endif %}";
55

66
@Component({
77
selector: 'app-root',

templates/template-leptos/src/app.rs.lte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use wasm_bindgen::prelude::*;
66

77
#[wasm_bindgen]
88
extern "C" {
9-
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "{% if alpha %}core{% else %}tauri{% endif %}"])]
9+
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "{% if beta %}core{% else %}tauri{% endif %}"])]
1010
async fn invoke(cmd: &str, args: JsValue) -> JsValue;
1111
}
1212

templates/template-preact-ts/package.json.lte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
},
1212
"dependencies": {
1313
"preact": "^10.16.0",
14-
"@tauri-apps/api": "{% if alpha %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if alpha %},
14+
"@tauri-apps/api": "{% if beta %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if beta %},
1515
"@tauri-apps/plugin-shell": ">=2.0.0-beta.0"{% endif %}
1616
},
1717
"devDependencies": {
1818
"@preact/preset-vite": "^2.5.0",
1919
"typescript": "^5.0.2",
2020
"vite": "^5.0.0",
21-
"@tauri-apps/cli": "{% if alpha %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if mobile %},
21+
"@tauri-apps/cli": "{% if beta %}>=2.0.0-beta.0{% else %}^1{% endif %}"{% if mobile %},
2222
"internal-ip": "^7.0.0"{% endif %}
2323
}
2424
}

0 commit comments

Comments
 (0)