Skip to content

Commit 8ba553c

Browse files
authored
feat: only prompt for pkg managers supported by template, closes #208 (#209)
* feat: only prompt for pkg managers supported by template, closes #208 * clippy
1 parent 04fb4e6 commit 8ba553c

5 files changed

Lines changed: 43 additions & 23 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-tauri-app": "patch"
3+
"create-tauri-app-js": "patch"
4+
---
5+
6+
Only prompt for supported package managers when using `--template` cli option.

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ pnpm create tauri-app
5454

5555
<br>
5656

57-
You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Vite + Vue project, run:
57+
You can also directly specify the project name, package manager and the template you want to use via additional command line options. For example, to scaffold a Vue project in a `my-tauri-app` directory, using `pnpm`, run:
5858

5959
```bash
6060
# curl
61-
sh <(curl https://create.tauri.app/sh) --template svelte
61+
sh <(curl https://create.tauri.app/sh) my-tauri-app --template svelte --manager pnpm
6262
# wget
63-
sh <(wget https://create.tauri.app/sh) --template svelte
63+
sh <(wget https://create.tauri.app/sh) my-tauri-app --template svelte --manager pnpm
6464
# cargo
65-
cargo create-tauri-app --template svelte
65+
cargo create-tauri-app my-tauri-app --template svelte --manager pnpm
6666
# npm 6.x
67-
npm create tauri-app@latest my-tauri-app --template svelte
67+
npm create tauri-app@latest my-tauri-app --template svelte --manager pnpm
6868
# npm 7+, extra double-dash is needed:
69-
npm create tauri-app@latest my-tauri-app -- --template svelte
69+
npm create tauri-app@latest my-tauri-app -- --template svelte --manager pnpm
7070
# yarn
71-
yarn create tauri-app my-tauri-app --template svelte
71+
yarn create tauri-app my-tauri-app --template svelte --manager pnpm
7272
# pnpm
73-
pnpm create tauri-app my-tauri-app --template svelte
73+
pnpm create tauri-app my-tauri-app --template svelte --manager pnpm
7474
```
7575

7676
Currently supported template presets include:

packages/cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ cargo create-tauri-app
2020

2121
<br>
2222

23-
You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Vite + Vue project, run:
23+
You can also directly specify the project name, package manager and the template you want to use via additional command line options. For example, to scaffold a Yew project in a `my-tauri-app` directory, using `cargo`, run:
2424

2525
```bash
26-
cargo create-tauri-app --template svelte
26+
cargo create-tauri-app my-tauri-app --template yew --manager cargo
2727
```
2828

2929
Currently supported template presets include:

packages/cli/node/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ pnpm create tauri-app
3131

3232
<br>
3333

34-
You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Vite + Vue project, run:
34+
You can also directly specify the project name, package manager and the template you want to use via additional command line options. For example, to scaffold a Vue project in a `my-tauri-app` directory, using `pnpm`, run:
3535

3636

3737
```bash
3838
# npm 6.x
39-
npm create tauri-app@latest my-tauri-app --template svelte
39+
npm create tauri-app@latest my-tauri-app --template svelte --manager pnpm
4040
# npm 7+, extra double-dash is needed:
41-
npm create tauri-app@latest my-tauri-app -- --template svelte
41+
npm create tauri-app@latest my-tauri-app -- --template svelte --manager pnpm
4242
# yarn
43-
yarn create tauri-app my-tauri-app --template svelte
43+
yarn create tauri-app my-tauri-app --template svelte --manager pnpm
4444
# pnpm
45-
pnpm create tauri-app my-tauri-app --template svelte
45+
pnpm create tauri-app my-tauri-app --template svelte --manager pnpm
4646
```
4747

4848
Currently supported template presets include:

packages/cli/src/lib.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,28 @@ where
131131
if skip {
132132
defaults.manager.unwrap()
133133
} else {
134-
let managers = PackageManager::ALL;
135-
let index = Select::with_theme(&ColorfulTheme::default())
136-
.with_prompt("Choose your package manager")
137-
.items(managers)
138-
.default(0)
139-
.interact()
140-
.unwrap();
141-
managers[index]
134+
let managers = PackageManager::ALL.to_vec();
135+
let managers = args
136+
.template
137+
.map(|t| {
138+
managers
139+
.iter()
140+
.copied()
141+
.filter(|p| p.templates().contains(&t))
142+
.collect::<Vec<_>>()
143+
})
144+
.unwrap_or(managers);
145+
if managers.len() == 1 {
146+
managers[0]
147+
} else {
148+
let index = Select::with_theme(&ColorfulTheme::default())
149+
.with_prompt("Choose your package manager")
150+
.items(&managers)
151+
.default(0)
152+
.interact()
153+
.unwrap();
154+
managers[index]
155+
}
142156
}
143157
});
144158

0 commit comments

Comments
 (0)