Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add new TypeScript bindgen #1783

Merged
merged 21 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3cf6e25
feat: added new bindgen with all types and utility functions
RareSecond Mar 28, 2024
7b4ce70
feat: removed bunch of extracted functions and extracted models to fu…
RareSecond Mar 29, 2024
43f50e7
refactor: moved generating to main function to intertwine models and …
RareSecond Mar 29, 2024
241c3ae
feat: generated system calls
RareSecond Mar 29, 2024
8da8f12
cleanup: removed old contract generation code
RareSecond Mar 29, 2024
95a2bac
feat: finished bindgen
RareSecond Mar 29, 2024
cf051f7
refactor: renamed TypescriptNew to TypeScriptV2
RareSecond Mar 29, 2024
328f420
Merge branch 'main' into feature/add-new-typescript-bindgen
RareSecond Mar 29, 2024
0b9e065
Merge branch 'main' into feature/add-new-typescript-bindgen
RareSecond Apr 5, 2024
8f29c0a
Updated flag naming to typescript_v2
RareSecond Apr 5, 2024
a078827
Fixed some build and layout issues
RareSecond Apr 5, 2024
07f6793
Fixed empty line in models
RareSecond Apr 5, 2024
b808888
Renamed modules as well
RareSecond Apr 5, 2024
d708ded
Update crates/dojo-bindgen/src/plugins/typescript_v2/mod.rs
RareSecond Apr 8, 2024
7f94494
Fixed formatting
RareSecond Apr 8, 2024
ac55973
Updated return values
RareSecond Apr 8, 2024
2e64d4d
Added query function to class
RareSecond Apr 9, 2024
319f6c9
Added test for the generated file
RareSecond Apr 12, 2024
58c1ed8
Removed full file test for now until DojoData is sorted
RareSecond Apr 12, 2024
424db1d
Added comment
RareSecond Apr 12, 2024
3494fde
fix: move mocks to test_data
glihm Apr 15, 2024
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
16 changes: 14 additions & 2 deletions bin/sozo/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#[arg(help = "Generate Typescript bindings.")]
pub typescript: bool,

#[arg(long)]
#[arg(help = "Generate Typescript bindings.")]
pub typescript_v2: bool,

Check warning on line 16 in bin/sozo/src/commands/build.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/build.rs#L16

Added line #L16 was not covered by tests

#[arg(long)]
#[arg(help = "Generate Unity bindings.")]
pub unity: bool,
Expand All @@ -32,6 +36,10 @@
builtin_plugins.push(BuiltinPlugins::Typescript);
}

if self.typescript_v2 {
builtin_plugins.push(BuiltinPlugins::TypeScriptV2);
}

if self.unity {
builtin_plugins.push(BuiltinPlugins::Unity);
}
Expand Down Expand Up @@ -67,8 +75,12 @@
fn build_example_with_typescript_and_unity_bindings() {
let config = build_test_config("../../examples/spawn-and-move/Scarb.toml").unwrap();

let build_args =
BuildArgs { bindings_output: "generated".to_string(), typescript: true, unity: true };
let build_args = BuildArgs {
bindings_output: "generated".to_string(),
typescript: true,
unity: true,
typescript_v2: true,
};
let result = build_args.run(&config);
assert!(result.is_ok());
}
Expand Down
2 changes: 2 additions & 0 deletions crates/dojo-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use error::{BindgenResult, Error};

mod plugins;
use plugins::typescript::TypescriptPlugin;
use plugins::typescript_v2::TypeScriptV2Plugin;
use plugins::unity::UnityPlugin;
use plugins::BuiltinPlugin;
pub use plugins::BuiltinPlugins;
Expand Down Expand Up @@ -85,6 +86,7 @@ impl PluginManager {
let builder: Box<dyn BuiltinPlugin> = match plugin {
BuiltinPlugins::Typescript => Box::new(TypescriptPlugin::new()),
BuiltinPlugins::Unity => Box::new(UnityPlugin::new()),
BuiltinPlugins::TypeScriptV2 => Box::new(TypeScriptV2Plugin::new()),
};

let files = builder.generate_code(&data).await?;
Expand Down
3 changes: 3 additions & 0 deletions crates/dojo-bindgen/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ use crate::error::BindgenResult;
use crate::DojoData;

pub mod typescript;
pub mod typescript_v2;
pub mod unity;

#[derive(Debug)]
pub enum BuiltinPlugins {
Typescript,
Unity,
TypeScriptV2,
}

impl fmt::Display for BuiltinPlugins {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BuiltinPlugins::Typescript => write!(f, "typescript"),
BuiltinPlugins::Unity => write!(f, "unity"),
BuiltinPlugins::TypeScriptV2 => write!(f, "typescript_v2"),
}
}
}
Expand Down
Loading
Loading