Skip to content

Commit caf8a6e

Browse files
committed
chore: cleanup after #806
1 parent 9e7a039 commit caf8a6e

29 files changed

Lines changed: 123 additions & 139 deletions

File tree

.changes/tauriver.md

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+
Fix incorrect version printed for installing `tauri-cli` command

.github/workflows/templates-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ jobs:
111111
cargo install dioxus-cli --locked
112112
if: matrix.settings.install_dioxus_cli
113113
114-
- name: install system dependencies
114+
- name: install system dependencies (v1)
115115
if: matrix.settings.tauriVersion == 1
116116
run: |
117117
sudo apt-get update
118118
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libayatana-appindicator3-dev librsvg2-dev patchelf
119119
120-
- name: install system dependencies (rc)
120+
- name: install system dependencies
121121
if: matrix.settings.tauriVersion == 'latest'
122122
run: |
123123
sudo apt-get update

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ cargo run -- <cli arguments>
2929
```ini
3030
beforeDevCommand = {% pkg_manager_run_command %} dev
3131
beforeBuildCommand = {% pkg_manager_run_command %} build
32-
devPath = http://localhost:1420
33-
distDir = ../dist
32+
devUrl = http://localhost:1420
33+
frontendDist = ../dist
3434

3535
# the next sction is used to determine what files to copy from `templates/_assets_`
3636
# if you introduce a new file like an icon that is shared between multiple templates,

src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub enum TauriVersion {
1616
}
1717

1818
impl TauriVersion {
19-
pub fn all() -> &'static [TauriVersion] {
20-
&[TauriVersion::V1, TauriVersion::V2]
19+
pub fn all() -> [TauriVersion; 2] {
20+
[TauriVersion::V1, TauriVersion::V2]
2121
}
2222
}
2323

src/deps.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ pub fn print_missing_deps(
210210
Dep {
211211
name: "Tauri CLI",
212212
instruction: match tauri_version {
213-
TauriVersion::V1 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0' --locked{RESET}`"),
214-
TauriVersion::V2 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^1.0.0' --locked{RESET}`"),
213+
TauriVersion::V1 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^1.0.0' --locked{RESET}`"),
214+
TauriVersion::V2 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0' --locked{RESET}`"),
215215
},
216216
exists: &|| is_appropriate_tauri_cli_installed(tauri_version),
217217
skip: pkg_manager.is_node() || !template.needs_tauri_cli(),

src/manifest.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use anyhow::{bail, Context};
66
pub struct Manifest<'a> {
77
pub before_dev_command: Option<&'a str>,
88
pub before_build_command: Option<&'a str>,
9-
pub dev_path: Option<&'a str>,
10-
pub dist_dir: Option<&'a str>,
9+
pub dev_url: Option<&'a str>,
10+
pub frontend_dist: Option<&'a str>,
1111
pub with_global_tauri: Option<bool>,
1212
pub files: HashMap<&'a str, &'a str>,
1313
}
@@ -59,8 +59,8 @@ impl<'a> Manifest<'a> {
5959
match k {
6060
"beforeDevCommand" => manifest.before_dev_command = Some(v),
6161
"beforeBuildCommand" => manifest.before_build_command = Some(v),
62-
"devPath" => manifest.dev_path = Some(v),
63-
"distDir" => manifest.dist_dir = Some(v),
62+
"devUrl" => manifest.dev_url = Some(v),
63+
"frontendDist" => manifest.frontend_dist = Some(v),
6464
"withGlobalTauri" => manifest.with_global_tauri = Some(v.parse()?),
6565
_ if in_files_section => {
6666
manifest.files.insert(k, v);
@@ -86,7 +86,7 @@ mod test {
8686
8787
beforeDevCommand = npm start -- --port 1420
8888
beforeBuildCommand = {% pkg_manager_run_command %} build # this comment should be stripped
89-
devPath = http://localhost:1420
89+
devUrl = http://localhost:1420
9090
9191
[files]
9292
tauri.svg = src/assets/tauri.svg
@@ -101,8 +101,8 @@ mod test {
101101
Manifest {
102102
before_dev_command: Some("npm start -- --port 1420"),
103103
before_build_command: Some("{% pkg_manager_run_command %} build"),
104-
dev_path: Some("http://localhost:1420"),
105-
dist_dir: None,
104+
dev_url: Some("http://localhost:1420"),
105+
frontend_dist: None,
106106
with_global_tauri: None,
107107
files,
108108
}
@@ -119,7 +119,7 @@ mod test {
119119
120120
beforeDevCommand = npm start -- --port 1420
121121
beforeBuildCommand =
122-
devPath = http://localhost:1420
122+
devUrl = http://localhost:1420
123123
124124
[files]
125125
tauri.svg = src/assets/tauri.svg
@@ -138,7 +138,7 @@ mod test {
138138
139139
beforeDevCommand = npm start -- --port 1420
140140
beforeBuildCommand = {% pkg_manager_run_command %} build # this comment should be stripped
141-
devPath = http://localhost:1420
141+
devUrl = http://localhost:1420
142142
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
143143
144144
[files]
@@ -154,8 +154,8 @@ mod test {
154154
Manifest {
155155
before_dev_command: Some("npm start -- --port 1420"),
156156
before_build_command: Some("{% pkg_manager_run_command %} build mobile"),
157-
dev_path: Some("http://localhost:1420"),
158-
dist_dir: None,
157+
dev_url: Some("http://localhost:1420"),
158+
frontend_dist: None,
159159
with_global_tauri: None,
160160
files,
161161
}

src/template.rs

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -278,40 +278,39 @@ impl<'a> Template {
278278
let lib_name = format!("{}_lib", package_name.replace('-', "_"));
279279
let project_name_pascal_case = utils::to_pascal_case(project_name);
280280

281+
let versions = TauriVersion::all()
282+
.iter()
283+
.map(|&v| {
284+
(
285+
format!("v{v}",),
286+
match v == tauri_version {
287+
true => "true",
288+
false => "false",
289+
},
290+
)
291+
})
292+
.collect::<Vec<_>>();
293+
294+
let styles = String::from_utf8(
295+
EMBEDDED_TEMPLATES::get("_assets_/styles.css")
296+
.unwrap()
297+
.data
298+
.to_vec(),
299+
)?;
300+
281301
let mut manifest_template_data: HashMap<&str, &str> = [
282302
("pkg_manager_run_command", pkg_manager.run_cmd()),
283303
("lib_name", &lib_name),
284304
("package_name", package_name),
285305
("project_name", project_name),
286306
("identifier", identifier),
287307
("project_name_pascal_case", &project_name_pascal_case),
288-
(
289-
"double_dash_with_space",
290-
if pkg_manager == PackageManager::Npm {
291-
"-- "
292-
} else {
293-
""
294-
},
295-
),
296308
]
297309
.into();
298310

299-
let versions = TauriVersion::all()
300-
.iter()
301-
.map(|v| format!("v{v}"))
302-
.collect::<Vec<_>>();
303-
for version in &versions {
304-
manifest_template_data.insert(version.as_str(), "false");
311+
for (version, enabled) in &versions {
312+
manifest_template_data.insert(version, enabled);
305313
}
306-
let tauri_version_key = format!("v{tauri_version}");
307-
manifest_template_data.insert(tauri_version_key.as_str(), "true");
308-
309-
let styles = String::from_utf8(
310-
EMBEDDED_TEMPLATES::get("_assets_/styles.css")
311-
.unwrap()
312-
.data
313-
.to_vec(),
314-
)?;
315314

316315
let mut template_data: HashMap<&str, String> = [
317316
("project_name", project_name.to_string()),
@@ -336,16 +335,16 @@ impl<'a> Template {
336335
)?,
337336
),
338337
(
339-
"dev_path",
338+
"dev_url",
340339
lte::render(
341-
manifest.dev_path.unwrap_or_default(),
340+
manifest.dev_url.unwrap_or_default(),
342341
&manifest_template_data,
343342
)?,
344343
),
345344
(
346-
"dist_dir",
345+
"frontend_dist",
347346
lte::render(
348-
manifest.dist_dir.unwrap_or_default(),
347+
manifest.frontend_dist.unwrap_or_default(),
349348
&manifest_template_data,
350349
)?,
351350
),
@@ -354,33 +353,18 @@ impl<'a> Template {
354353
manifest.with_global_tauri.unwrap_or_default().to_string(),
355354
),
356355
("lib_name", lib_name),
357-
(
358-
"styles_padded",
359-
styles
360-
.lines()
361-
.map(|l| {
362-
if l.is_empty() {
363-
l.to_string()
364-
} else {
365-
format!(" {l}")
366-
}
367-
})
368-
.collect::<Vec<_>>()
369-
.join("\n"),
370-
),
371356
("styles", styles),
372357
]
373358
.into();
374359

375-
let versions = TauriVersion::all()
360+
for (version, enabled) in &versions {
361+
template_data.insert(version.as_str(), enabled.to_string());
362+
}
363+
364+
let version_flags = TauriVersion::all()
376365
.iter()
377-
.map(|v| format!("v{v}"))
366+
.map(|&v| (v, format!("v{v}")))
378367
.collect::<Vec<_>>();
379-
for version in &versions {
380-
template_data.insert(version.as_str(), "false".to_string());
381-
}
382-
let tauri_version_key = format!("v{tauri_version}");
383-
template_data.insert(tauri_version_key.as_str(), "true".to_string());
384368

385369
let write_file = |file: &str, template_data| -> anyhow::Result<()> {
386370
// remove the first component, which is certainly the template directory they were in before getting embeded into the binary
@@ -394,11 +378,6 @@ impl<'a> Template {
394378
let p = target_dir.join(p);
395379
let file_name = p.file_name().unwrap().to_string_lossy();
396380

397-
let version_flags = TauriVersion::all()
398-
.iter()
399-
.map(|version| (format!("v{version}"), *version))
400-
.collect::<Vec<_>>();
401-
402381
let file_name = match &*file_name {
403382
"_gitignore" => ".gitignore",
404383
// skip manifest
@@ -417,19 +396,18 @@ impl<'a> Template {
417396

418397
let for_version = version_flags
419398
.iter()
420-
.find(|(flag, _version)| flags.contains(&flag.as_str()))
421-
.map(|(_flag, version)| *version);
422-
423-
// remove these flags to only keep package managers flags
424-
flags.retain(|e| !["stable", "rc"].contains(e));
425-
426-
if let Some(for_version) = for_version {
427-
if for_version == tauri_version {
428-
name
429-
} else {
430-
return Ok(());
431-
}
432-
} else if flags.contains(&pkg_manager.to_string().as_str()) || flags.is_empty()
399+
.find(|(_, flag)| flags.contains(&flag.as_str()))
400+
.map(|(v, _)| *v);
401+
402+
// remove version flags to only keep package managers flags
403+
flags.retain(|e| !version_flags.iter().any(|(_, flag)| e == flag));
404+
405+
// this file has a version flag and matches active version.
406+
// if doesn't have any version flag, it should be rendered
407+
if for_version.map(|v| v == tauri_version).unwrap_or(true)
408+
// this file has a package manager flag and matches active package manager.
409+
// if doesn't have any package manager flag, it should be rendered
410+
&& (flags.contains(&pkg_manager.to_string().as_str()) || flags.is_empty())
433411
{
434412
name
435413
} else {

templates/_base_/src-tauri/%(v1)%tauri.conf.json.lte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"build": {
44
{% if before_dev_command %}"beforeDevCommand": "{% before_dev_command %}",
55
{% endif %}{% if before_build_command %}"beforeBuildCommand": "{% before_build_command %}",
6-
{% endif %}{% if dev_path %}"devPath": "{% dev_path %}",
7-
{% endif %}"distDir": "{% dist_dir %}"{% if with_global_tauri %},
6+
{% endif %}{% if dev_url %}"devPath": "{% dev_url %}",
7+
{% endif %}"distDir": "{% frontend_dist %}"{% if with_global_tauri %},
88
"withGlobalTauri": true{% endif %}
99
},
1010
"package": {

templates/_base_/src-tauri/%(v2)%tauri.conf.json.lte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"identifier": "{% identifier %}",
66
"build": {
77
{% if before_dev_command %}"beforeDevCommand": "{% before_dev_command %}",
8-
{% endif %}{% if dev_path %}"devUrl": "{% dev_path %}",
8+
{% endif %}{% if dev_url %}"devUrl": "{% dev_url %}",
99
{% endif %}{% if before_build_command %}"beforeBuildCommand": "{% before_build_command %}",
10-
{% endif %}"frontendDist": "{% dist_dir %}"
10+
{% endif %}"frontendDist": "{% frontend_dist %}"
1111
},
1212
"app": {
1313
{% if with_global_tauri %}"withGlobalTauri": true,

templates/template-angular/.manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
beforeDevCommand = {% pkg_manager_run_command %} start
66
beforeBuildCommand = {% pkg_manager_run_command %} build
7-
devPath = http://localhost:1420
8-
distDir = ../dist/{% package_name %}/browser
7+
devUrl = http://localhost:1420
8+
frontendDist = ../dist/{% package_name %}/browser
99

1010
[files]
1111
tauri.svg = src/assets/tauri.svg

0 commit comments

Comments
 (0)