Skip to content

Commit

Permalink
update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Dec 28, 2023
1 parent 5e84168 commit 9e7d67b
Show file tree
Hide file tree
Showing 64 changed files with 200 additions and 198 deletions.
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ cargo run -- <cli arguments>
- 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.
- A template also must have a `_cta_manifest_` file which contains info about the template:

```ini
beforeDevCommand = {% pkg_manager_run_command %} dev
beforeBuildCommand = {% pkg_manager_run_command %} build
beforeDevCommand = {{ pkg_manager_run_command }} dev
beforeBuildCommand = {{ pkg_manager_run_command }} build
devPath = http://localhost:1420
distDir = ../dist

Expand All @@ -41,11 +42,12 @@ cargo run -- <cli arguments>
# the second part is the path that the file will be copied to under the final template directory
tauri.svg = public/tauri.svg
```

- In `src/template.rs`, add an entry in the `Template` enum, and modify its methods if needed.
- In `src/package_manager.rs` add your new template to the appropriate package manager in the `templates` method.
- Modify `.scripts/generate-templates-matrix.js` and append the template name inside the template list for the appropriate package manager so the CI would run tests for it.
- Before making a commit, make sure to run `cargo fmt --all` and `pnpm format` in the repo root.

## Financial Contribution

Tauri is an MIT-licensed open source project. Its ongoing development can be supported via [Github Sponsors](https://github.com/sponsors/nothingismagick) or [Open Collective](https://opencollective.com/tauri). We prefer Github Sponsors as donations made are doubled through the matching fund program.
Tauri is an MIT-licensed open source project. Its ongoing development can be supported via [Github Sponsors](https://github.com/sponsors/nothingismagick) or [Open Collective](https://opencollective.com/tauri). We prefer Github Sponsors as donations made are doubled through the matching fund program.
16 changes: 8 additions & 8 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ mod test {
# SPDX-License-Identifier: MIT
beforeDevCommand = npm start -- --port 1420
beforeBuildCommand = {% pkg_manager_run_command %} build # this comment should be stripped
beforeBuildCommand = {{ pkg_manager_run_command }} build # this comment should be stripped
devPath = http://localhost:1420
[mobile]
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
beforeBuildCommand = {{ pkg_manager_run_command }} build mobile
[files]
tauri.svg = src/assets/tauri.svg
Expand All @@ -115,7 +115,7 @@ mod test {

Manifest {
before_dev_command: Some("npm start -- --port 1420"),
before_build_command: Some("{% pkg_manager_run_command %} build"),
before_build_command: Some("{{ pkg_manager_run_command }} build"),
dev_path: Some("http://localhost:1420"),
dist_dir: None,
with_global_tauri: None,
Expand All @@ -130,7 +130,7 @@ mod test {

Manifest {
before_dev_command: Some("npm start -- --port 1420"),
before_build_command: Some("{% pkg_manager_run_command %} build mobile"),
before_build_command: Some("{{ pkg_manager_run_command }} build mobile"),
dev_path: Some("http://localhost:1420"),
dist_dir: None,
with_global_tauri: None,
Expand All @@ -152,7 +152,7 @@ mod test {
devPath = http://localhost:1420
[mobile]
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
beforeBuildCommand = {{ pkg_manager_run_command }} build mobile
[files]
tauri.svg = src/assets/tauri.svg
Expand All @@ -170,9 +170,9 @@ mod test {
# SPDX-License-Identifier: MIT
beforeDevCommand = npm start -- --port 1420
beforeBuildCommand = {% pkg_manager_run_command %} build # this comment should be stripped
beforeBuildCommand = {{ pkg_manager_run_command }} build # this comment should be stripped
devPath = http://localhost:1420
beforeBuildCommand = {% pkg_manager_run_command %} build mobile
beforeBuildCommand = {{ pkg_manager_run_command }} build mobile
[files]
tauri.svg = src/assets/tauri.svg
Expand All @@ -186,7 +186,7 @@ mod test {

Manifest {
before_dev_command: Some("npm start -- --port 1420"),
before_build_command: Some("{% pkg_manager_run_command %} build mobile"),
before_build_command: Some("{{ pkg_manager_run_command }} build mobile"),
dev_path: Some("http://localhost:1420"),
dist_dir: None,
with_global_tauri: None,
Expand Down
12 changes: 6 additions & 6 deletions templates/_base_/src-tauri/Cargo.toml.lts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "{% package_name %}"
name = "{{ package_name }}"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
Expand All @@ -9,21 +9,21 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

{% if mobile %}[lib]
name = "{% lib_name %}"
{{ if mobile }}[lib]
name = "{{ lib_name }}"
crate-type = ["staticlib", "cdylib", "rlib"]

{% endif %}{% if stable %}[build-dependencies]
{{ endif }}{{ if stable }}[build-dependencies]
tauri-build = { version = "1.5", features = [] }

[dependencies]
tauri = { version = "1.5", features = ["shell-open"] }
serde = { version = "1.0", features = ["derive"] }{% else %}[build-dependencies]
serde = { version = "1.0", features = ["derive"] }{{ else }}[build-dependencies]
tauri-build = { version = "2.0.0-alpha", features = [] }

[dependencies]
tauri = { version = "2.0.0-alpha", features = [] }
tauri-plugin-shell = "2.0.0-alpha"{% endif %}
tauri-plugin-shell = "2.0.0-alpha"{{ endif }}
serde_json = "1.0"

[features]
Expand Down
12 changes: 6 additions & 6 deletions templates/_base_/src-tauri/src/main.rs.lts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

{% if mobile %}fn main() {
{% lib_name %}::run()
}{% else %}// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
{{ if mobile }}fn main() {
{{ lib_name }}::run()
}{{ else }}// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}

fn main() {
tauri::Builder::default()
{% if alpha %}.plugin(tauri_plugin_shell::init())
{% endif %}.invoke_handler(tauri::generate_handler![greet])
{{ if alpha }}.plugin(tauri_plugin_shell::init())
{{ endif }}.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}{% endif %}
}{{ endif }}
22 changes: 11 additions & 11 deletions templates/_base_/src-tauri/tauri.conf.json.lts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"build": {
"beforeDevCommand": "{% before_dev_command %}",
"beforeBuildCommand": "{% before_build_command %}",
"devPath": "{% dev_path %}",
"distDir": "{% dist_dir %}"{% if with_global_tauri %},
"withGlobalTauri": true{% endif %}
"beforeDevCommand": "{{ before_dev_command }}",
"beforeBuildCommand": "{{ before_build_command }}",
"devPath": "{{ dev_path }}",
"distDir": "{{ dist_dir }}"{{ if with_global_tauri }},
"withGlobalTauri": true{{ endif }}
},
"package": {
"productName": "{% project_name %}",
"productName": "{{ project_name }}",
"version": "0.0.0"
},
"tauri": {
{% if stable %}"allowlist": {
{{ if stable }}"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
}
},
{% endif %}"bundle": {
{{ endif }}"bundle": {
"active": true,
"targets": "all",
"identifier": "com.tauri.dev",
Expand All @@ -37,15 +37,15 @@
{
"fullscreen": false,
"resizable": true,
"title": "{% package_name %}",
"title": "{{ package_name }}",
"width": 800,
"height": 600
}
]
}{% if alpha %},
}{{ if alpha }},
"plugins": {
"shell": {
"open": true
}
}{% endif %}
}{{ endif }}
}
8 changes: 4 additions & 4 deletions templates/template-angular/_cta_manifest_
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

beforeDevCommand = {% pkg_manager_run_command %} start
beforeBuildCommand = {% pkg_manager_run_command %} build
beforeDevCommand = {{ pkg_manager_run_command }} start
beforeBuildCommand = {{ pkg_manager_run_command }} build
devPath = http://localhost:1420
distDir = ../dist/{% package_name %}/browser
distDir = ../dist/{{ package_name }}/browser

[mobile]
beforeDevCommand = {% pkg_manager_run_command %} start {% double_dash_with_space %}--host $HOST --public-host $HOST
beforeDevCommand = {{ pkg_manager_run_command }} start {{ double_dash_with_space }}--host $HOST --public-host $HOST

[files]
tauri.svg = src/assets/tauri.svg
Expand Down
8 changes: 4 additions & 4 deletions templates/template-angular/angular.json.lts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"analytics": false
},
"projects": {
"{% package_name %}": {
"{{ package_name }}": {
"projectType": "application",
"root": "",
"sourceRoot": "src",
Expand All @@ -15,7 +15,7 @@
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/{% package_name %}",
"outputPath": "dist/{{ package_name }}",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": ["zone.js"],
Expand Down Expand Up @@ -54,10 +54,10 @@
},
"configurations": {
"production": {
"buildTarget": "{% package_name %}:build:production"
"buildTarget": "{{ package_name }}:build:production"
},
"development": {
"buildTarget": "{% package_name %}:build:development"
"buildTarget": "{{ package_name }}:build:development"
}
},
"defaultConfiguration": "development"
Expand Down
10 changes: 5 additions & 5 deletions templates/template-angular/package.json.lts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "{% package_name %}",
"name": "{{ package_name }}",
"version": "0.0.0",
"scripts": {
"ng": "ng",
Expand All @@ -21,8 +21,8 @@
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.2",
"@tauri-apps/api": "^{% if alpha %}2.0.0-alpha.13{% else %}1.5.2{% endif %}"{% if alpha %},
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3"{% endif %}
"@tauri-apps/api": "^{{ if alpha }}2.0.0-alpha.13{{ else }}1.5.2{{ endif }}"{{ if alpha }},
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3"{{ endif }}
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.0.0",
Expand All @@ -36,7 +36,7 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.2.2",
"@tauri-apps/cli": "^{% if alpha %}2.0.0-alpha.20{% else %}1.5.8{% endif %}"{% if mobile %},
"internal-ip": "^7.0.0"{% endif %}
"@tauri-apps/cli": "^{{ if alpha }}2.0.0-alpha.20{{ else }}1.5.8{{ endif }}"{{ if mobile }},
"internal-ip": "^7.0.0"{{ endif }}
}
}
2 changes: 1 addition & 1 deletion templates/template-angular/src/app/app.component.ts.lts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterOutlet } from '@angular/router';
import { invoke } from "@tauri-apps/api/{% if alpha %}core{% else %}tauri{% endif %}";
import { invoke } from "@tauri-apps/api/{{ if alpha }}core{{ else }}tauri{{ endif }}";

@Component({
selector: 'app-root',
Expand Down
2 changes: 1 addition & 1 deletion templates/template-leptos/Cargo.toml.lts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "{% package_name %}-ui"
name = "{{ package_name }}-ui"
version = "0.0.0"
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions templates/template-leptos/Trunk.toml.lts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target = "./index.html"
ignore = ["./src-tauri"]

[serve]
address = "{% if mobile %}0.0.0.0{% else %}127.0.0.1{% endif %}"
address = "{{ if mobile }}0.0.0.0{{ else }}127.0.0.1{{ endif }}"
port = 1420
open = false{% if mobile %}
ws_protocol = "ws"{% endif %}
open = false{{ if mobile }}
ws_protocol = "ws"{{ endif }}
2 changes: 1 addition & 1 deletion templates/template-leptos/src/app.rs.lts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "{% if alpha %}core{% else %}tauri{% endif %}"])]
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "{{ if alpha }}core{{ else }}tauri{{ endif }}"])]
async fn invoke(cmd: &str, args: JsValue) -> JsValue;
}

Expand Down
4 changes: 2 additions & 2 deletions templates/template-preact-ts/_cta_manifest_
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

beforeDevCommand = {% pkg_manager_run_command %} dev
beforeBuildCommand = {% pkg_manager_run_command %} build
beforeDevCommand = {{ pkg_manager_run_command }} dev
beforeBuildCommand = {{ pkg_manager_run_command }} build
devPath = http://localhost:1420
distDir = ../dist

Expand Down
10 changes: 5 additions & 5 deletions templates/template-preact-ts/package.json.lts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "{% package_name %}",
"name": "{{ package_name }}",
"private": true,
"version": "0.0.0",
"type": "module",
Expand All @@ -11,14 +11,14 @@
},
"dependencies": {
"preact": "^10.16.0",
"@tauri-apps/api": "^{% if alpha %}2.0.0-alpha.13{% else %}1.5.2{% endif %}"{% if alpha %},
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3"{% endif %}
"@tauri-apps/api": "^{{ if alpha }}2.0.0-alpha.13{{ else }}1.5.2{{ endif }}"{{ if alpha }},
"@tauri-apps/plugin-shell": "^2.0.0-alpha.3"{{ endif }}
},
"devDependencies": {
"@preact/preset-vite": "^2.5.0",
"typescript": "^5.0.2",
"vite": "^5.0.0",
"@tauri-apps/cli": "^{% if alpha %}2.0.0-alpha.20{% else %}1.5.8{% endif %}"{% if mobile %},
"internal-ip": "^7.0.0"{% endif %}
"@tauri-apps/cli": "^{{ if alpha }}2.0.0-alpha.20{{ else }}1.5.8{{ endif }}"{{ if mobile }},
"internal-ip": "^7.0.0"{{ endif }}
}
}
2 changes: 1 addition & 1 deletion templates/template-preact-ts/src/App.tsx.lts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "preact/hooks";
import preactLogo from "./assets/preact.svg";
import { invoke } from "@tauri-apps/api/{% if alpha %}core{% else %}tauri{% endif %}";
import { invoke } from "@tauri-apps/api/{{ if alpha }}core{{ else }}tauri{{ endif }}";
import "./App.css";

function App() {
Expand Down
8 changes: 4 additions & 4 deletions templates/template-preact-ts/vite.config.ts.lts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineConfig } from "vite";
import preact from "@preact/preset-vite";{% if mobile %}
import preact from "@preact/preset-vite";{{ if mobile }}
import { internalIpV4 } from "internal-ip";

// @ts-expect-error process is a nodejs global
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);{% endif %}
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);{{ endif }}

// https://vitejs.dev/config/
export default defineConfig(async () => ({
Expand All @@ -16,15 +16,15 @@ export default defineConfig(async () => ({
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,{% if mobile %}
strictPort: true,{{ if mobile }}
host: mobile ? "0.0.0.0" : false,
hmr: mobile
? {
protocol: "ws",
host: await internalIpV4(),
port: 1421,
}
: undefined,{% endif %}
: undefined,{{ endif }}
watch: {
// 3. tell vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
Expand Down
4 changes: 2 additions & 2 deletions templates/template-preact/_cta_manifest_
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

beforeDevCommand = {% pkg_manager_run_command %} dev
beforeBuildCommand = {% pkg_manager_run_command %} build
beforeDevCommand = {{ pkg_manager_run_command }} dev
beforeBuildCommand = {{ pkg_manager_run_command }} build
devPath = http://localhost:1420
distDir = ../dist

Expand Down
Loading

0 comments on commit 9e7d67b

Please sign in to comment.