Skip to content

Commit ae9e141

Browse files
authored
fix: check for template without flavor before, closes #441 (#444)
1 parent fe97c77 commit ae9e141

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

.changes/template-flag-flavor.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+
Fix crash when passing a flavored template like `vue-ts` to the CLI.
7+

packages/cli/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ where
151151
managers
152152
.iter()
153153
.copied()
154-
.filter(|p| p.templates().contains(&t))
154+
.filter(|p| p.templates_no_flavors().contains(&t.without_flavor()))
155155
.collect::<Vec<_>>()
156156
})
157157
.unwrap_or(managers);
@@ -203,7 +203,7 @@ where
203203
}
204204
});
205205

206-
let templates = pkg_manager.templates();
206+
let templates_no_flavors = pkg_manager.templates_no_flavors();
207207

208208
// Template to render
209209
let template = args.template.unwrap_or_else(|| {
@@ -213,15 +213,15 @@ where
213213
let index = Select::with_theme(&ColorfulTheme::default())
214214
.with_prompt("Choose your UI template")
215215
.items(
216-
&templates
216+
&templates_no_flavors
217217
.iter()
218218
.map(|t| t.select_text())
219219
.collect::<Vec<_>>(),
220220
)
221221
.default(0)
222222
.interact()
223223
.unwrap();
224-
let template = templates[index];
224+
let template = templates_no_flavors[index];
225225

226226
// Prompt for flavors if the template has more than one flavor
227227
let flavors = template.flavors(pkg_manager);
@@ -257,11 +257,11 @@ where
257257
// If the package manager and the template are specified on the command line
258258
// then almost all prompts are skipped so we need to make sure that the combination
259259
// is valid, otherwise, we error and exit
260-
if !pkg_manager.templates_all().contains(&template) {
260+
if !pkg_manager.templates().contains(&template) {
261261
eprintln!(
262262
"{BOLD}{RED}error{RESET}: the {GREEN}{}{RESET} template is not suppported for the {GREEN}{pkg_manager}{RESET} package manager\n possible templates for {GREEN}{pkg_manager}{RESET} are: [{}]",
263263
template,
264-
templates.iter().map(|e|format!("{GREEN}{e}{RESET}")).collect::<Vec<_>>().join(", ")
264+
templates_no_flavors.iter().map(|e|format!("{GREEN}{e}{RESET}")).collect::<Vec<_>>().join(", ")
265265
);
266266
exit(1);
267267
}

packages/cli/src/package_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a> PackageManager {
3131
}
3232
impl PackageManager {
3333
/// Returns templates without flavors
34-
pub const fn templates(&self) -> &[Template] {
34+
pub const fn templates_no_flavors(&self) -> &[Template] {
3535
match self {
3636
PackageManager::Cargo => &[
3737
Template::Vanilla,
@@ -50,7 +50,7 @@ impl PackageManager {
5050
}
5151
}
5252

53-
pub const fn templates_all(&self) -> &[Template] {
53+
pub const fn templates(&self) -> &[Template] {
5454
match self {
5555
PackageManager::Cargo => &[
5656
Template::Vanilla,

packages/cli/src/template.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ impl<'a> Template {
146146
}
147147
}
148148

149+
pub fn without_flavor(&self) -> Self {
150+
match self {
151+
Template::VanillaTs => Template::Vanilla,
152+
Template::VueTs => Template::Vue,
153+
Template::SvelteTs => Template::Svelte,
154+
Template::ReactTs => Template::React,
155+
Template::SolidTs => Template::Solid,
156+
_ => *self,
157+
}
158+
}
159+
149160
pub const fn needs_trunk(&self) -> bool {
150161
matches!(self, Template::Sycamore | Template::Yew | Template::Leptos)
151162
}

0 commit comments

Comments
 (0)