From 70a84efe1cc013842f26599f89a7491d6a6ba18d Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Thu, 1 Aug 2024 21:30:17 +0800 Subject: [PATCH] :tada: Release 2.0.0-rc.12 --- Cargo.lock | 24 +++++++++++++++++------- Cargo.toml | 23 +++++++++-------------- macros/Cargo.toml | 2 +- macros/src/lib.rs | 6 ++++++ src/lang/js.rs | 1 + src/lang/js_ts.rs | 32 +++++++++++++++----------------- src/lang/ts.rs | 1 + src/lib.rs | 6 +++--- 8 files changed, 53 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71f2ff6..66be955 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2842,7 +2842,9 @@ dependencies = [ [[package]] name = "specta" -version = "2.0.0-rc.16" +version = "2.0.0-rc.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfd9c8f5ec3e3727784396e946bfa91a973853e70e3b1d637c36e5f99c1daf0e" dependencies = [ "paste", "specta-macros", @@ -2851,7 +2853,9 @@ dependencies = [ [[package]] name = "specta-jsdoc" -version = "0.0.3" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a084c2caf239158e761dd22034b240297fa79bdebc284ecb3e6a59db6c8eca76" dependencies = [ "specta", "specta-serde", @@ -2860,7 +2864,9 @@ dependencies = [ [[package]] name = "specta-macros" -version = "2.0.0-rc.16" +version = "2.0.0-rc.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68999d29816965eb9e5201f60aec02a76512139811661a7e8e653abc810b8f72" dependencies = [ "Inflector", "proc-macro2", @@ -2870,7 +2876,9 @@ dependencies = [ [[package]] name = "specta-serde" -version = "0.0.3" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1751ce21ddc96210530fc7dfb90c43f2ff680daf4e1030f2414126b316564b5e" dependencies = [ "specta", "thiserror", @@ -2878,7 +2886,9 @@ dependencies = [ [[package]] name = "specta-typescript" -version = "0.0.3" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3637aaf3b9b11e4bafec4fc2c6eaf1d252690f19dee2209fdcea8f16210fd1d8" dependencies = [ "specta", "specta-serde", @@ -3255,7 +3265,7 @@ dependencies = [ [[package]] name = "tauri-specta" -version = "2.0.0-rc.11" +version = "2.0.0-rc.12" dependencies = [ "heck 0.5.0", "serde", @@ -3297,7 +3307,7 @@ dependencies = [ [[package]] name = "tauri-specta-macros" -version = "2.0.0-rc.5" +version = "2.0.0-rc.6" dependencies = [ "heck 0.5.0", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index d73ba18..bfd7ecc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tauri-specta" description = "Completely typesafe Tauri commands" -version = "2.0.0-rc.11" +version = "2.0.0-rc.12" authors = ["Oscar Beaumont "] edition = "2021" license = "MIT" @@ -34,7 +34,7 @@ workspace = true specta = { workspace = true, features = ["function"] } specta-typescript = { workspace = true, optional = true } specta-jsdoc = { workspace = true, optional = true } -tauri-specta-macros = { version = "=2.0.0-rc.5", optional = true, path = "./macros" } +tauri-specta-macros = { version = "=2.0.0-rc.6", optional = true, path = "./macros" } serde = "1" serde_json = "1" thiserror = "1" @@ -65,18 +65,13 @@ panic_in_result_fn = { level = "warn", priority = -1 } [workspace.dependencies] tauri = { version = "=2.0.0-beta.25" } -specta = { version = "=2.0.0-rc.16" } -specta-typescript = { version = "0.0.3" } -specta-jsdoc = { version = "0.0.3" } +specta = { version = "=2.0.0-rc.18" } +specta-typescript = { version = "0.0.5" } +specta-jsdoc = { version = "0.0.5" } -[patch.crates-io] +# [patch.crates-io] # tauri = { git = "https://github.com/oscartbeaumont/tauri.git", rev = "ddc64b706a7f2db271d40e9b216187b1aa153efa" } # tauri-build = { git = "https://github.com/oscartbeaumont/tauri.git", rev = "ddc64b706a7f2db271d40e9b216187b1aa153efa" } - -# specta = { git = "https://github.com/oscartbeaumont/specta.git", rev = "cfa98fa10484e55923497f3cc21edf7418667c76" } -# specta-util = { git = "https://github.com/oscartbeaumont/specta.git", rev = "cfa98fa10484e55923497f3cc21edf7418667c76" } -# specta-typescript = { git = "https://github.com/oscartbeaumont/specta.git", rev = "cfa98fa10484e55923497f3cc21edf7418667c76" } - -specta = { path = "../specta/specta" } -specta-typescript = { path = "../specta/specta-typescript" } -specta-jsdoc = { path = "../specta/specta-jsdoc" } \ No newline at end of file +# specta = { path = "../specta/specta" } +# specta-typescript = { path = "../specta/specta-typescript" } +# specta-jsdoc = { path = "../specta/specta-jsdoc" } \ No newline at end of file diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 389e540..78fb5e5 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tauri-specta-macros" description = "Completely typesafe Tauri commands" -version = "2.0.0-rc.5" +version = "2.0.0-rc.6" authors = ["Oscar Beaumont "] edition = "2021" license = "MIT" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index d7aacc0..73c1236 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,3 +1,9 @@ +#![doc( + // TODO: Tauri Specta logo + html_logo_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png", + html_favicon_url = "https://github.com/oscartbeaumont/specta/raw/main/.github/logo-128.png" +)] + use heck::ToKebabCase; use quote::quote; use syn::{parse_macro_input, DeriveInput}; diff --git a/src/lang/js.rs b/src/lang/js.rs index ba32d84..bccbbaf 100644 --- a/src/lang/js.rs +++ b/src/lang/js.rs @@ -24,6 +24,7 @@ impl LanguageExt for specta_jsdoc::JSDoc { &self.0.header, render_commands(&self.0, cfg)?, render_events(&self.0, cfg)?, + false, ) } } diff --git a/src/lang/js_ts.rs b/src/lang/js_ts.rs index 0a3849a..3667501 100644 --- a/src/lang/js_ts.rs +++ b/src/lang/js_ts.rs @@ -2,14 +2,13 @@ //! //! Typescript is a superset of Javascript so they share a lot of logic. -use std::{any::TypeId, borrow::Cow, collections::BTreeMap}; +use std::{borrow::Cow, collections::BTreeMap}; use heck::ToLowerCamelCase; use specta::{ datatype::{self, DataType, FunctionResultVariant}, TypeMap, }; -use specta_jsdoc::JSDoc; use specta_typescript::{self as ts}; use specta_typescript::{ExportError, Typescript}; @@ -17,37 +16,36 @@ use crate::{apply_as_prefix, ExportContext, ItemType, LanguageExt}; const DO_NOT_EDIT: &str = "// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually."; -pub fn render_all_parts( +pub fn render_all_parts( cfg: &ExportContext, dependant_types: &str, globals: &str, header: &str, commands: String, events: String, + as_const: bool, ) -> Result { let constants = cfg .constants .iter() .map(|(name, value)| { - let mut as_const = None; - match &value { - serde_json::Value::Null => {} - serde_json::Value::Bool(_) - | serde_json::Value::Number(_) - | serde_json::Value::String(_) - | serde_json::Value::Array(_) - | serde_json::Value::Object(_) => as_const = Some(" as const"), - } - - if TypeId::of::() == TypeId::of::() { - as_const = None; + let mut as_constt = None; + if as_const { + match &value { + serde_json::Value::Null => {} + serde_json::Value::Bool(_) + | serde_json::Value::Number(_) + | serde_json::Value::String(_) + | serde_json::Value::Array(_) + | serde_json::Value::Object(_) => as_constt = Some(" as const"), + } } format!( "export const {name} = {}{};", serde_json::to_string(&value) .expect("failed to serialize from `serde_json::Value`"), - as_const.unwrap_or("") + as_constt.unwrap_or("") ) }) .collect::>() @@ -188,7 +186,7 @@ pub fn events_map( ) -> String { events .iter() - .map(|(name, ty)| { + .map(|(name, _)| { let name_str = plugin_name .as_ref() .map(|n| apply_as_prefix(n, name, ItemType::Event)) diff --git a/src/lang/ts.rs b/src/lang/ts.rs index 7f911dd..e67491b 100644 --- a/src/lang/ts.rs +++ b/src/lang/ts.rs @@ -22,6 +22,7 @@ impl LanguageExt for specta_typescript::Typescript { &self.header, render_commands(self, cfg)?, render_events(self, cfg)?, + true, ) } } diff --git a/src/lib.rs b/src/lib.rs index d52fba6..13832af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,14 +14,14 @@ //! //! ```sh //! # Always required -//! cargo add tauri@=2.0.0-beta.25 specta@=2.0.0-rc.16 +//! cargo add tauri@=2.0.0-beta.25 specta@=2.0.0-rc.18 //! //! # Typescript -//! cargo add specta-typescript@0.0.3 +//! cargo add specta-typescript@0.0.5 //! cargo add tauri-specta@=2.0.0-rc.12 --features derive,typescript //! //! # JSDoc -//! cargo add specta-jsdoc@0.0.3 +//! cargo add specta-jsdoc@0.0.5 //! cargo add tauri-specta@=2.0.0-rc.12 --features derive,javascript //! ``` //!