Skip to content

Commit 27524c3

Browse files
authored
feat: add dioxus template (#784)
1 parent 58fd975 commit 27524c3

File tree

20 files changed

+200
-15
lines changed

20 files changed

+200
-15
lines changed

.changes/dioxus.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 `dioxus` template
7+

.github/workflows/templates-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ jobs:
106106
rustup target add wasm32-unknown-unknown
107107
cargo install --locked trunk
108108
if: matrix.settings.install_trunk
109+
- run: |
110+
rustup target add wasm32-unknown-unknown
111+
cargo install --locked dioxus-cli
112+
if: matrix.settings.install_dioxus_cli
109113
110114
- name: install system dependencies
111115
if: matrix.settings.rc != true

.scripts/generate-templates-matrix.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const matrixConfig = [
2424
manager: "cargo",
2525
install_cmd: "",
2626
run_cmd: "cargo",
27-
templates: ["vanilla", "yew", "sycamore", "leptos"],
27+
templates: ["vanilla", "yew", "sycamore", "leptos", "dioxus"],
2828
},
2929
{
3030
manager: "pnpm",
@@ -78,6 +78,7 @@ matrixConfig
7878
const jobInfo = {
7979
template: t,
8080
install_trunk: ["yew", "sycamore", "leptos"].includes(t),
81+
install_dioxus_cli: t === "dioxus",
8182
rc: false,
8283
no_bundle_flag: "-b none",
8384
...managerInfo,

src/deps.rs

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

40+
fn is_dioxus_cli_installed() -> bool {
41+
Command::new("dx")
42+
.arg("-V")
43+
.output()
44+
.map(|o| o.status.success())
45+
.unwrap_or(false)
46+
}
47+
4048
fn is_appropriate_tauri_cli_installed(rc: bool) -> bool {
4149
let check = |o: Output| match o.status.success() {
4250
true => String::from_utf8_lossy(&o.stdout)
@@ -212,6 +220,12 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
212220
exists: &is_trunk_installed,
213221
skip: pkg_manager.is_node() || !template.needs_trunk(),
214222
},
223+
Dep {
224+
name: "Dioxus CLI",
225+
instruction: format!("Run `{BLUE}{BOLD}cargo install dioxus-cli{RESET}`"),
226+
exists: &is_dioxus_cli_installed,
227+
skip: pkg_manager.is_node() || !template.needs_dioxus_cli(),
228+
},
215229
Dep {
216230
name: "wasm32 target",
217231
instruction: format!("Run `{BLUE}{BOLD}rustup target add wasm32-unknown-unknown{RESET}`"),

src/package_manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl PackageManager {
8181
Template::Yew,
8282
Template::Leptos,
8383
Template::Sycamore,
84+
Template::Dioxus,
8485
],
8586
PackageManager::Pnpm
8687
| PackageManager::Yarn
@@ -105,6 +106,7 @@ impl PackageManager {
105106
Template::Yew,
106107
Template::Leptos,
107108
Template::Sycamore,
109+
Template::Dioxus,
108110
],
109111
PackageManager::Pnpm
110112
| PackageManager::Yarn

src/template.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub enum Template {
5858
Preact,
5959
PreactTs,
6060
Blazor,
61+
Dioxus,
6162
}
6263

6364
impl Display for Template {
@@ -80,6 +81,7 @@ impl Display for Template {
8081
Template::Preact => write!(f, "preact"),
8182
Template::PreactTs => write!(f, "preact-ts"),
8283
Template::Blazor => write!(f, "blazor"),
84+
Template::Dioxus => write!(f, "dioxus"),
8385
}
8486
}
8587
}
@@ -105,6 +107,7 @@ impl FromStr for Template {
105107
"preact" => Ok(Template::Preact),
106108
"preact-ts" => Ok(Template::PreactTs),
107109
"blazor" => Ok(Template::Blazor),
110+
"dioxus" => Ok(Template::Dioxus),
108111
_ => Err(format!(
109112
"{YELLOW}{s}{RESET} is not a valid template. Valid templates are [{}]",
110113
Template::ALL
@@ -133,6 +136,7 @@ impl Template {
133136
Template::Blazor => {
134137
"Blazor - (https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor/)"
135138
}
139+
Template::Dioxus => "Dioxus - (https://dioxuslabs.com/)",
136140
_ => unreachable!(),
137141
}
138142
}
@@ -157,6 +161,7 @@ impl<'a> Template {
157161
Template::Preact,
158162
Template::PreactTs,
159163
Template::Blazor,
164+
Template::Dioxus,
160165
];
161166

162167
pub fn flavors<'b>(&self, pkg_manager: PackageManager) -> Option<&'b [Flavor]> {
@@ -222,7 +227,9 @@ impl<'a> Template {
222227
| Template::Angular
223228
| Template::Preact
224229
| Template::PreactTs => PackageManager::NODE,
225-
Template::Yew | Template::Leptos | Template::Sycamore => &[PackageManager::Cargo],
230+
Template::Yew | Template::Leptos | Template::Sycamore | Template::Dioxus => {
231+
&[PackageManager::Cargo]
232+
}
226233
Template::Blazor => &[PackageManager::Dotnet],
227234
}
228235
}
@@ -242,6 +249,10 @@ impl<'a> Template {
242249
matches!(self, Template::Blazor)
243250
}
244251

252+
pub const fn needs_dioxus_cli(&self) -> bool {
253+
matches!(self, Template::Dioxus)
254+
}
255+
245256
pub const fn needs_wasm32_target(&self) -> bool {
246257
matches!(self, Template::Sycamore | Template::Yew | Template::Leptos)
247258
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2019-2022 Tauri Programme within The Commons Conservancy
2+
# SPDX-License-Identifier: Apache-2.0
3+
# SPDX-License-Identifier: MIT
4+
5+
beforeDevCommand = dx serve --port 1420
6+
beforeBuildCommand = dx build
7+
devPath = http://localhost:1420
8+
distDir = ../dist
9+
withGlobalTauri = true
10+
11+
[files]
12+
tauri.svg = assets/tauri.svg
13+
styles.css = assets/styles.css
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/src
2+
/assets
3+
/Cargo.toml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"tauri-apps.tauri-vscode",
4+
"rust-lang.rust-analyzer",
5+
"DioxusLabs.dioxus"
6+
]
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "{% package_name %}-ui"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[dependencies]
8+
dioxus = { version = "0.5", features = ["web"] }
9+
dioxus-logger = "0.5"
10+
wasm-bindgen = "0.2"
11+
wasm-bindgen-futures = "0.4"
12+
web-sys = "0.3"
13+
js-sys = "0.3"
14+
serde = { version = "1", features = ["derive"] }
15+
serde-wasm-bindgen = "0.6"
16+
17+
[workspace]
18+
members = ["src-tauri"]

0 commit comments

Comments
 (0)