Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reenable Specta integration #2432

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ fern = { version = "0.7", features = ["colored"] }
num_enum = "0.7"
num-derive = "0.4"
num-traits = { version = "0.2", default-features = false, features = ["i128"] }
specta = { version = "2.0.0-rc.22", features = [
"glam",
specta = { version = "=2.0.0-rc.22", features = [
"derive",
# "typescript",
"glam",
] }
specta-typescript = { version = "=0.0.9" }
syn = { version = "2.0", default-features = false, features = [
"full",
"derive",
Expand Down
1 change: 1 addition & 0 deletions editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ futures = { workspace = true }
glam = { workspace = true, features = ["serde", "debug-glam-assert"] }
derivative = { workspace = true }
specta = { workspace = true }
specta-typescript = { workspace = true }
image = { workspace = true, features = ["bmp", "png"] }
dyn-any = { workspace = true }
num_enum = { workspace = true }
Expand Down
35 changes: 8 additions & 27 deletions editor/src/generate_ts_types.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
/// Running this test will generate a `types.ts` file at the root of the repo,
/// containing every type annotated with `specta::Type`
// #[cfg(all(test, feature = "specta-export"))]
#[ignore]

#[test]
fn generate_ts_types() {
// TODO: Un-comment this out when we figure out how to reenable the "typescript` Specta feature flag

// use crate::messages::prelude::FrontendMessage;
// use specta::ts::{export_named_datatype, BigIntExportBehavior, ExportConfig};
// use specta::{NamedType, TypeMap};
// use std::fs::File;
// use std::io::Write;

// let config = ExportConfig::new().bigint(BigIntExportBehavior::Number);

// let mut type_map = TypeMap::default();

// let datatype = FrontendMessage::definition_named_data_type(&mut type_map);

// let mut export = String::new();

// export += &export_named_datatype(&config, &datatype, &type_map).unwrap();

// type_map
// .iter()
// .map(|(_, v)| v)
// .flat_map(|v| export_named_datatype(&config, v, &type_map))
// .for_each(|e| export += &format!("\n\n{e}"));
use specta::TypeCollection;
use specta_typescript::{BigIntExportBehavior, Typescript};

// let mut file = File::create("../types.ts").unwrap();
use crate::messages::prelude::FrontendMessage;

// write!(file, "{export}").ok();
Typescript::default()
.bigint(BigIntExportBehavior::Number)
.export_to("../frontend/src/bindings.ts", TypeCollection::default().register::<FrontendMessage>())
.unwrap();
}
276 changes: 276 additions & 0 deletions frontend/bindings_from_node.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ web-sys = { workspace = true, features = [
"HtmlCanvasElement",
"IdleRequestOptions",
] }
specta = { workspace = true }
specta-typescript = { workspace = true }

# Optional workspace dependencies
ron = { workspace = true, optional = true }
Expand Down
7 changes: 7 additions & 0 deletions frontend/wasm/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import graphite, { get_specta_types } from "./pkg/graphite_wasm.js";

graphite(fs.readFileSync(path.join(import.meta.dirname, './pkg/graphite_wasm_bg.wasm'))).then(() =>
fs.writeFileSync("bindings_from_node.ts", get_specta_types())
);
12 changes: 12 additions & 0 deletions frontend/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ pub fn init_graphite() {
log::set_max_level(log::LevelFilter::Debug);
}

#[cfg(debug_assertions)]
#[wasm_bindgen]
pub fn get_specta_types() -> Result<String, String> {
use specta::TypeCollection;
use specta_typescript::{BigIntExportBehavior, Typescript};

Typescript::default()
.bigint(BigIntExportBehavior::Number)
.export(&TypeCollection::default().register::<FrontendMessage>())
.map_err(|err| err.to_string())
}

/// When a panic occurs, notify the user and log the error to the JS console before the backend dies
pub fn panic_hook(info: &panic::PanicHookInfo) {
let info = info.to_string();
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

Loading