Skip to content

Commit

Permalink
🎉 Release 2.0.0-rc.12
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Aug 1, 2024
1 parent 939d6e4 commit 70a84ef
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 42 deletions.
24 changes: 17 additions & 7 deletions Cargo.lock

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

23 changes: 9 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
# specta = { path = "../specta/specta" }
# specta-typescript = { path = "../specta/specta-typescript" }
# specta-jsdoc = { path = "../specta/specta-jsdoc" }
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
1 change: 1 addition & 0 deletions src/lang/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl LanguageExt for specta_jsdoc::JSDoc {
&self.0.header,
render_commands(&self.0, cfg)?,
render_events(&self.0, cfg)?,
false,
)
}
}
Expand Down
32 changes: 15 additions & 17 deletions src/lang/js_ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,50 @@
//!
//! 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};

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<L: LanguageExt + 'static>(
pub fn render_all_parts<L: LanguageExt>(
cfg: &ExportContext,
dependant_types: &str,
globals: &str,
header: &str,
commands: String,
events: String,
as_const: bool,
) -> Result<String, L::Error> {
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::<L>() == TypeId::of::<JSDoc>() {
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::<Vec<_>>()
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/lang/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl LanguageExt for specta_typescript::Typescript {
&self.header,
render_commands(self, cfg)?,
render_events(self, cfg)?,
true,
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected].3
//! cargo add [email protected].5
//! cargo add tauri-specta@=2.0.0-rc.12 --features derive,typescript
//!
//! # JSDoc
//! cargo add [email protected].3
//! cargo add [email protected].5
//! cargo add tauri-specta@=2.0.0-rc.12 --features derive,javascript
//! ```
//!
Expand Down

0 comments on commit 70a84ef

Please sign in to comment.