dojo icon indicating copy to clipboard operation
dojo copied to clipboard

feat(sozo): scaffold ts base files on user behalf

Open MartianGreed opened this issue 1 year ago • 1 comments
trafficstars

Description

As a developper when I start a new project I don't want to copy/paste or type by hand every dojo files required for the project to run.

I want to be able to have a command to scaffold dojo files in order to ease project starting and be able to choose the frontend architecture I want.

Related issue

Tests

  • [x] Yes, but incomplete as I need guidance through building process

Added to documentation?

I have documented the code itself + PR here on dojo.js

Checklist

  • [x] I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • [x] I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • [x] I've commented my code
  • [ ] I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Introduced a new command-line option for building projects to generate TypeScript scaffolding files.
    • Added a TypescriptScaffoldPlugin to facilitate TypeScript code generation.
    • New TypeScript templates for client components, client models, setup, systems, and world creation.
  • Bug Fixes

    • Improved error handling in the TypeScript scaffolding plugin.
  • Tests

    • Added asynchronous unit tests for the TypescriptScaffoldPlugin to ensure correct functionality.

MartianGreed avatar Aug 08 '24 09:08 MartianGreed

Walkthrough

Ohayo, sensei! The recent changes introduce a scaffold option in the build command, which facilitates the automatic generation of TypeScript scaffolding files. This enhancement includes the integration of the TypescriptScaffoldPlugin into the dojo-bindgen crate, streamlining the creation of essential TypeScript files. A variety of templates for client components, models, and setup processes have been defined, significantly improving modularity and the developer experience when building Dojo applications.

Changes

Files Change Summary
bin/sozo/src/commands/build.rs Added scaffold boolean field to BuildArgs for TypeScript scaffolding. Updated command-line argument handling and default initialization.
crates/dojo-bindgen/Cargo.toml Introduced lazy_static and tera dependencies for static variable management and templating capabilities.
crates/dojo-bindgen/src/lib.rs, crates/dojo-bindgen/src/plugins/mod.rs Added TypescriptScaffoldPlugin to PluginManager and introduced typescript_scaffold module with TypescriptScaffold variant in BuiltinPlugins.
crates/dojo-bindgen/src/plugins/typescript_scaffold/mod.rs Implemented TypescriptScaffoldPlugin, utilizing Tera templates for generating TypeScript code with methods for various file types.
crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/*.tpl.ts Added various TypeScript templates (e.g., clientComponents, clientModels, setup, system, world) to support scaffolding for Dojo applications.
crates/dojo-bindgen/src/plugins/typescript_scaffold/tests.rs Created unit tests for TypescriptScaffoldPlugin to verify code generation and file validity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant BuildArgs
    participant PluginManager
    participant TypescriptScaffoldPlugin
    participant Tera

    User->>CLI: Initiates build command with --scaffold
    CLI->>BuildArgs: Parses command with scaffold=true
    BuildArgs->>PluginManager: Adds TypescriptScaffoldPlugin
    PluginManager->>TypescriptScaffoldPlugin: Creates instance
    TypescriptScaffoldPlugin->>Tera: Loads templates
    TypescriptScaffoldPlugin->>User: Generates TypeScript files

Recent review details

Configuration used: .coderabbit.yaml Review profile: CHILL

Commits

Files that changed from the base of the PR and between 10592c09e0010c186ddf84a8649e8f3caeafdb35 and 86e3aef3781d686810ed5fe27d0a1fe5373fbaaf.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (11)
  • bin/sozo/src/commands/build.rs (3 hunks)
  • crates/dojo-bindgen/Cargo.toml (1 hunks)
  • crates/dojo-bindgen/src/lib.rs (2 hunks)
  • crates/dojo-bindgen/src/plugins/mod.rs (3 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/mod.rs (1 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/clientComponents.tpl.ts (1 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/clientModels.tpl.ts (1 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/setup.tpl.ts (1 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/system.tpl.ts (1 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/world.tpl.ts (1 hunks)
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/tests.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • crates/dojo-bindgen/Cargo.toml
  • crates/dojo-bindgen/src/plugins/mod.rs
Files skipped from review as they are similar to previous changes (4)
  • bin/sozo/src/commands/build.rs
  • crates/dojo-bindgen/src/lib.rs
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/mod.rs
  • crates/dojo-bindgen/src/plugins/typescript_scaffold/tests.rs
Additional context used
Biome
crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/world.tpl.ts

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/clientModels.tpl.ts

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/clientComponents.tpl.ts

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/system.tpl.ts

[error] 27-27: Expected a statement but instead found '%'.

Expected a statement here.

(parse)


[error] 27-27: expected ( but instead found system

Remove system

(parse)


[error] 27-27: Expected an expression but instead found '}'.

Expected an expression here.

(parse)


[error] 28-28: Expected an identifier, a member name, or a rest pattern but instead found '{ system.name'.

Expected an identifier, a member name, or a rest pattern here.

(parse)


[error] 28-28: Object and Array patterns require initializers.

This pattern is declared, but it is not given an initialized value.

(parse)


[error] 28-28: Expected a statement but instead found '= async (account: AccountInterface) =>'.

Expected a statement here.

(parse)


[error] 32-32: Expected a statement but instead found '% endfor %'.

Expected a statement here.

(parse)


[error] 33-33: Expected a property, a shorthand property, a getter, a setter, or a method but instead found '{% for system in systems %'.

Expected a property, a shorthand property, a getter, a setter, or a method here.

(parse)


[error] 33-33: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)


[error] 33-33: Expected a statement but instead found ','.

Expected a statement here.

(parse)


[error] 33-33: Expected a statement but instead found '% endfor %'.

Expected a statement here.

(parse)


[error] 34-34: Expected a statement but instead found '}'.

Expected a statement here.

(parse)


[error] 36-38: Illegal return statement outside of a function

(parse)


[error] 38-39: Expected a statement but instead found '}'.

Expected a statement here.

(parse)


[error] 30-30: This code is unreachable

... because this statement will throw an exception beforehand

(lint/correctness/noUnreachable)


[error] 33-33: This code is unreachable

... because this statement will throw an exception beforehand

(lint/correctness/noUnreachable)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 27-27: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 28-30: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/setup.tpl.ts

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

Additional comments not posted (3)
crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/world.tpl.ts (1)

1-1: Remove the redundant block statement.

Ohayo, sensei! The block statement at the top is unnecessary and can be safely removed to simplify the code.

-{{ header }}
Tools
Biome

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/clientModels.tpl.ts (1)

1-1: Remove the redundant block statement.

Ohayo, sensei! The block statement at the top is unnecessary and can be safely removed to simplify the code.

-{{ header }}
Tools
Biome

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

crates/dojo-bindgen/src/plugins/typescript_scaffold/templates/clientComponents.tpl.ts (1)

1-1: Remove the redundant block statement.

Ohayo, sensei! The block statement at the top is unnecessary and can be safely removed to simplify the code.

-{{ header }}
Tools
Biome

[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.

(lint/complexity/noUselessLoneBlockStatements)


[error] 1-1: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code. Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 08 '24 09:08 coderabbitai[bot]

Will close this since the new bindgen is taking over, correct? Please comment if not. :)

glihm avatar Oct 31 '24 19:10 glihm