Skip to content

Commit

Permalink
feat: add tauri-schema-worker (#10871)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Sep 16, 2024
1 parent ad294d2 commit a1cce04
Show file tree
Hide file tree
Showing 20 changed files with 1,082 additions and 44 deletions.
40 changes: 14 additions & 26 deletions .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"prepublish": [
"cargo install cargo-audit --features=fix",
{
"command": "cargo generate-lockfile",
"command": "echo '<details>\n<summary><em><h4>Cargo Audit</h4></em></summary>\n\n```'",
"dryRunCommand": true,
"runFromRoot": true,
"pipe": true
},
{
"command": "echo '<details>\n<summary><em><h4>Cargo Audit</h4></em></summary>\n\n```'",
"command": "cargo generate-lockfile",
"dryRunCommand": true,
"runFromRoot": true,
"pipe": true
},
{
Expand Down Expand Up @@ -79,15 +79,15 @@
}
},
"prepublish": [
{
"command": "pnpm i --frozen-lockfile",
"dryRunCommand": true
},
{
"command": "echo '<details>\n<summary><em><h4>PNPM Audit</h4></em></summary>\n\n```'",
"dryRunCommand": true,
"pipe": true
},
{
"command": "pnpm i --frozen-lockfile",
"dryRunCommand": true
},
{
"command": "pnpm audit",
"dryRunCommand": true,
Expand Down Expand Up @@ -191,16 +191,7 @@
"path": "./crates/tauri-build",
"manager": "rust",
"dependencies": ["tauri-codegen", "tauri-utils"],
"postversion": [
"node ../../.scripts/ci/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
"cargo build --manifest-path ../tauri-schema-generator/Cargo.toml"
],
"assets": [
{
"path": "./crates/tauri-schema-generator/schemas/config.schema.json",
"name": "config.schema.json"
}
]
"postversion": "node ../../.scripts/ci/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
},
"tauri": {
"path": "./crates/tauri",
Expand All @@ -212,16 +203,16 @@
"tauri-runtime-wry",
"tauri-build"
],
"postversion": "node ../../.scripts/ci/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
"postversion": [
"node ../../.scripts/ci/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
"cargo build --manifest-path ../tauri-schema-generator/Cargo.toml"
]
},
"@tauri-apps/cli": {
"path": "./packages/cli",
"manager": "javascript",
"dependencies": ["tauri-cli"],
"postversion": [
"node ../../.scripts/ci/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
"cargo build --manifest-path ../../crates/tauri-schema-generator/Cargo.toml"
],
"postversion": "node ../../.scripts/ci/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
"prepublish": [],
"publish": [],
"postpublish": []
Expand All @@ -230,10 +221,7 @@
"path": "./crates/tauri-cli",
"manager": "rust",
"dependencies": ["tauri-bundler", "tauri-utils", "tauri-macos-sign"],
"postversion": [
"cargo check",
"cargo build --manifest-path ../tauri-schema-generator/Cargo.toml"
]
"postversion": "cargo check"
},
"tauri-driver": {
"path": "./crates/tauri-driver",
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/deploy-schema-worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2019-2024 Tauri Programme within The Commons Conservancy
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

name: deploy schema worker

on:
push:
branches:
- dev
paths:
- '.github/workflows/deploy-schema-worker.yml'
- 'crates/tauri-schema-worker/**'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cloudflare/wrangler-action@3
with:
command: deploy
workingDirectory: 'crates/tauri-schema-worker'
apiToken: ${{ secrets.SCHEMA_WORKER_CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.SCHEMA_WORKER_CLOUDFLARE_ACCOUNT_ID }}
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/.changes
/audits
/.vscode

# change files are hand-written and shouldn't be formatted
/.changes/*
!/.changes/config.json

# dependcies and artifacts directories
node_modules/
target/
Expand All @@ -25,6 +28,7 @@ crates/tauri-cli/templates
**/autogenerated/**/*.md
packages/cli/index.js
packages/cli/index.d.ts
crates/tauri-schema-worker/.wrangler
CHANGELOG.md
*schema.json

Expand Down
121 changes: 121 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"crates/tauri-codegen",
"crates/tauri-plugin",
"crates/tauri-schema-generator",
"crates/tauri-schema-worker",
"crates/tauri-cli",
"crates/tauri-bundler",
"crates/tauri-macos-sign",
Expand Down Expand Up @@ -50,6 +51,7 @@ codegen-units = 1
lto = true
incremental = false
opt-level = "s"
strip = true

# profiles for tauri-cli
[profile.dev.package.miniz_oxide]
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "tauri-config-2.0.0-rc.14",
"title": "Config",
"description": "The Tauri configuration object.\n It is read from a file where you can define your frontend assets,\n configure the bundler and define a tray icon.\n\n The configuration file is generated by the\n [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in\n your Tauri application source directory (src-tauri).\n\n Once generated, you may modify it at will to customize your Tauri application.\n\n ## File Formats\n\n By default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\n Tauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively.\n The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`.\n The TOML file name is `Tauri.toml`.\n\n ## Platform-Specific Configuration\n\n In addition to the default configuration file, Tauri can\n read a platform-specific configuration from `tauri.linux.conf.json`,\n `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json`\n (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used),\n which gets merged with the main configuration object.\n\n ## Configuration Structure\n\n The configuration is composed of the following objects:\n\n - [`app`](#appconfig): The Tauri configuration\n - [`build`](#buildconfig): The build configuration\n - [`bundle`](#bundleconfig): The bundle configurations\n - [`plugins`](#pluginconfig): The plugins configuration\n\n Example tauri.config.json file:\n\n ```json\n {\n \"productName\": \"tauri-app\",\n \"version\": \"0.1.0\",\n \"build\": {\n \"beforeBuildCommand\": \"\",\n \"beforeDevCommand\": \"\",\n \"devUrl\": \"../dist\",\n \"frontendDist\": \"../dist\"\n },\n \"app\": {\n \"security\": {\n \"csp\": null\n },\n \"windows\": [\n {\n \"fullscreen\": false,\n \"height\": 600,\n \"resizable\": true,\n \"title\": \"Tauri App\",\n \"width\": 800\n }\n ]\n },\n \"bundle\": {},\n \"plugins\": {}\n }\n ```",
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/templates/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://schema.tauri.app/config/2.0.0-rc",
"productName": "{{ app_name }}",
"version": "0.1.0",
"identifier": "com.tauri.dev",
Expand Down
24 changes: 20 additions & 4 deletions crates/tauri-schema-generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use std::{error::Error, path::PathBuf};

use serde::Deserialize;
use tauri_utils::{
acl::{capability::Capability, Permission, Scopes},
config::Config,
Expand All @@ -16,9 +17,13 @@ macro_rules! schema {
};
}

#[derive(Deserialize)]
pub struct VersionMetadata {
tauri: String,
}

pub fn main() -> Result<(), Box<dyn Error>> {
let schemas = [
schema!("config", Config),
schema!("capability", Capability),
schema!("permission", Permission),
schema!("scope", Scopes),
Expand All @@ -32,10 +37,21 @@ pub fn main() -> Result<(), Box<dyn Error>> {
for (filename, schema) in schemas {
let schema = serde_json::to_string_pretty(&schema)?;
write_if_changed(schemas_dir.join(filename), &schema)?;
}

// write config schema file
{
let metadata = include_str!("../tauri-cli/metadata-v2.json");
let tauri_ver = serde_json::from_str::<VersionMetadata>(metadata)?.tauri;

// set id for generated schema
let (filename, mut config_schema) = schema!("config", Config);
let schema_metadata = config_schema.schema.metadata.as_mut().unwrap();
schema_metadata.id = Some(format!("tauri-config-{}", tauri_ver));

if filename.starts_with("config") {
write_if_changed(out.join("../tauri-cli/config.schema.json"), schema)?;
}
let config_schema = serde_json::to_string_pretty(&config_schema)?;
write_if_changed(schemas_dir.join(filename), &config_schema)?;
write_if_changed(out.join("../tauri-cli/config.schema.json"), config_schema)?;
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "tauri-config-2.0.0-rc.14",
"title": "Config",
"description": "The Tauri configuration object.\n It is read from a file where you can define your frontend assets,\n configure the bundler and define a tray icon.\n\n The configuration file is generated by the\n [`tauri init`](https://tauri.app/v1/api/cli#init) command that lives in\n your Tauri application source directory (src-tauri).\n\n Once generated, you may modify it at will to customize your Tauri application.\n\n ## File Formats\n\n By default, the configuration is defined as a JSON file named `tauri.conf.json`.\n\n Tauri also supports JSON5 and TOML files via the `config-json5` and `config-toml` Cargo features, respectively.\n The JSON5 file name must be either `tauri.conf.json` or `tauri.conf.json5`.\n The TOML file name is `Tauri.toml`.\n\n ## Platform-Specific Configuration\n\n In addition to the default configuration file, Tauri can\n read a platform-specific configuration from `tauri.linux.conf.json`,\n `tauri.windows.conf.json`, `tauri.macos.conf.json`, `tauri.android.conf.json` and `tauri.ios.conf.json`\n (or `Tauri.linux.toml`, `Tauri.windows.toml`, `Tauri.macos.toml`, `Tauri.android.toml` and `Tauri.ios.toml` if the `Tauri.toml` format is used),\n which gets merged with the main configuration object.\n\n ## Configuration Structure\n\n The configuration is composed of the following objects:\n\n - [`app`](#appconfig): The Tauri configuration\n - [`build`](#buildconfig): The build configuration\n - [`bundle`](#bundleconfig): The bundle configurations\n - [`plugins`](#pluginconfig): The plugins configuration\n\n Example tauri.config.json file:\n\n ```json\n {\n \"productName\": \"tauri-app\",\n \"version\": \"0.1.0\",\n \"build\": {\n \"beforeBuildCommand\": \"\",\n \"beforeDevCommand\": \"\",\n \"devUrl\": \"../dist\",\n \"frontendDist\": \"../dist\"\n },\n \"app\": {\n \"security\": {\n \"csp\": null\n },\n \"windows\": [\n {\n \"fullscreen\": false,\n \"height\": 600,\n \"resizable\": true,\n \"title\": \"Tauri App\",\n \"width\": 800\n }\n ]\n },\n \"bundle\": {},\n \"plugins\": {}\n }\n ```",
"type": "object",
Expand Down
4 changes: 4 additions & 0 deletions crates/tauri-schema-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
/node_modules
/.wrangler
/build
18 changes: 18 additions & 0 deletions crates/tauri-schema-worker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "tauri-schema-worker"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]

[dependencies]
worker = { version = "0.3", features = ['http', 'axum'] }
worker-macros = { version = "0.3", features = ['http'] }
console_error_panic_hook = { version = "0.1" }
axum = { version = "0.7", default-features = false }
tower-service = "0.3"
semver = { version = "1.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
anyhow = "1.0"
3 changes: 3 additions & 0 deletions crates/tauri-schema-worker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# schema.tauri.app worker

Source code for `https://schema.tauri.app` cloudflare worker.
Loading

0 comments on commit a1cce04

Please sign in to comment.