Skip to content

Commit f91ce78

Browse files
authored
feat(lte): skip rendering falsy values (#598)
* feat(lte): skip rendering falsy values * clippy * remove trailing comma * fix vanilla templates
1 parent 26e9a60 commit f91ce78

22 files changed

Lines changed: 141 additions & 107 deletions

File tree

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 `vanilla` template generating an invalid `tauri.conf.json` file.
7+

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cargo run -- <cli arguments>
2424
> You should open a new issue first to discuss the addition of a certain template.
2525
2626
- Add a directory in `templates` and name it `template-<template-name>` where `<template-name>` is the name of the template and add all the files you need there.
27-
- A template also must have a `_cta_manifest_` file which contains info about the template:
27+
- A template also must have a `.manifest` file which contains info about the template:
2828

2929
```ini
3030
beforeDevCommand = {% pkg_manager_run_command %} dev

src/template.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::{
1313
utils::{colors::*, lte},
1414
};
1515

16+
const CTA_MANIFEST_FILENAME: &str = ".manifest";
17+
1618
#[derive(RustEmbed)]
1719
#[folder = "templates"]
1820
#[allow(clippy::upper_case_acronyms, non_camel_case_types)]
@@ -245,15 +247,19 @@ impl<'a> Template {
245247
alpha: bool,
246248
mobile: bool,
247249
) -> anyhow::Result<()> {
248-
let manifest_bytes = EMBEDDED_TEMPLATES::get(&format!("template-{self}/_cta_manifest_"))
249-
.with_context(|| "Failed to get manifest bytes")?
250-
.data;
251-
let manifest_str = String::from_utf8(manifest_bytes.to_vec())?;
250+
let manifest_bytes =
251+
EMBEDDED_TEMPLATES::get(&format!("template-{self}/{CTA_MANIFEST_FILENAME}"))
252+
.with_context(|| "Failed to get manifest bytes")?
253+
.data
254+
.to_vec();
255+
let manifest_str = String::from_utf8(manifest_bytes)?;
252256
let manifest = Manifest::parse(&manifest_str, mobile)?;
253257

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

260+
let stable_str = (!alpha).to_string();
256261
let manifest_template_data: HashMap<&str, &str> = [
262+
("stable", stable_str.as_str()),
257263
("pkg_manager_run_command", pkg_manager.run_cmd()),
258264
("lib_name", &lib_name),
259265
("project_name", project_name),
@@ -270,7 +276,7 @@ impl<'a> Template {
270276
.into();
271277

272278
let template_data: HashMap<&str, String> = [
273-
("stable", (!alpha).to_string()),
279+
("stable", stable_str.clone()),
274280
("alpha", alpha.to_string()),
275281
("mobile", mobile.to_string()),
276282
("project_name", project_name.to_string()),
@@ -326,7 +332,7 @@ impl<'a> Template {
326332
let file_name = match &*file_name {
327333
"_gitignore" => ".gitignore",
328334
// skip manifest
329-
"_cta_manifest_" => return Ok(()),
335+
CTA_MANIFEST_FILENAME => return Ok(()),
330336
// conditional files:
331337
// are files that start with a special syntax
332338
// "%(<list of flags separated by `-`>%)<file_name>"
@@ -362,18 +368,13 @@ impl<'a> Template {
362368
};
363369

364370
// Only modify files that need to use the template engine
365-
let (file_data, file_name) = if let Some(file_name) = file_name.strip_suffix(".lte") {
366-
let file_data = EMBEDDED_TEMPLATES::get(file).unwrap().data.to_vec();
367-
let file_data_as_str = std::str::from_utf8(&file_data)?;
368-
(
369-
lte::render(file_data_as_str, template_data)?.into_bytes(),
370-
file_name,
371-
)
371+
let (file_data, file_name) = if let Some(new_name) = file_name.strip_suffix(".lte") {
372+
let data = EMBEDDED_TEMPLATES::get(file).unwrap().data.to_vec();
373+
let data = lte::render(data, template_data)?.into_bytes();
374+
(data, new_name)
372375
} else {
373-
(
374-
EMBEDDED_TEMPLATES::get(file).unwrap().data.to_vec(),
375-
file_name,
376-
)
376+
let data = EMBEDDED_TEMPLATES::get(file).unwrap().data.to_vec();
377+
(data, file_name)
377378
};
378379

379380
let parent = p.parent().unwrap();

0 commit comments

Comments
 (0)