tswarp
v0.2.1
Published
This package converts TS to Stylus
Downloads
15
Readme
Tswarp

🚀 Tswarp is a powerful tool that simplifies the process of converting TypeScript code to Stylus Rust and managing Stylus Rust projects. With just a few commands, you can initialize projects, compile TypeScript to Stylus Rust, and validate Stylus Rust projects using cargo stylus check.
Requirements
Before using tswarp, ensure your environment is properly set up with the following:
1. Rustup
Install Rustup, the Rust toolchain installer:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh2. Cargo
Cargo is the Rust package manager and is included with Rustup.
3. Add the WASM Compilation Target
Add the WebAssembly (WASM) target for Rust:
rustup target add wasm32-unknown-unknown
# Verify it's installed
rustup target list --installed | grep wasm4. Install cargo-stylus
Install the cargo-stylus package for Stylus Rust validation:
cargo install --force cargo-stylus
# Quick check to ensure it's installed
cargo stylus --version # Should show 0.4.0 or newer5. Install Node.js Dependencies
Globally install the required Node.js packages for TypeScript support:
npm install -g typescript ts-node @types/nodeEnsure that the above packages are properly installed before proceeding with the installation of tswarp.
Setting Up Your Local Development Environment
To set up a local Stylus Rust development environment, follow these steps:
Prerequisite: Install Docker
Ensure you have Docker installed on your system. You can download and install Docker from Docker's official website.
Steps:
- Clone the Devnode Repository
git clone https://github.com/OffchainLabs/nitro-devnode.git
cd nitro-devnode- Launch Your Local Arbitrum Chain
./run-dev-node.shThis command uses Docker to set up and run the local Arbitrum chain. Ensure Docker is running before executing this command.
Installation
Install the CLI via NPM
Install the tswarp CLI globally via npm:
npm install -g tswarpYou can now use tswarp as a global command.
Usage
Commands
1. Initialize a New Project
tswarp init <projectname>- Description: Creates a new project with a TypeScript converter and Stylus Rust logic templates.
- Example:
tswarp init myproject - Result:
- A new directory
myprojectis created. - TypeScript templates are placed under
converter/. - Stylus Rust templates are placed under
logic/.
- A new directory
2. Compile TypeScript to Stylus Rust
tswarp compile- Description: Compiles the TypeScript files in the
converterdirectory into Stylus Rust code. - Note: This command should be run inside the
converterdirectory. - Example:
cd converter tswarp compile
3. Run cargo stylus check
tswarp build- Description: Runs the
cargo stylus checkcommand in the current directory to validate Stylus Rust projects. - Note: This command should be run inside the
logicdirectory. - Example:
cd logic tswarp build
4. View CLI Version
tswarp --version- Description: Displays the current version of the Tswarp.
- Example:
tswarp --version
5. View Help Information
tswarp --help- Description: Shows the help menu with a list of all available commands.
- Example:
tswarp --help
Project Structure
When you initialize a new project with tswarp init <projectname>, the following structure is created:
<projectname>/
├── converter/ # TypeScript project
│ ├── counter.ts # TypeScript example file
│ ├── package.json # Node.js package configuration
│ └── node_modules/ # Node.js dependencies
├── logic/ # Stylus Rust project
│ ├── Cargo.toml # Stylus Rust package configuration
│ ├── Cargo.lock # Stylus Rust dependencies lock file
│ ├── rust-toolchain.toml # Stylus Rust toolchain configuration
│ ├── src/ # Stylus Rust source code
│ │ ├── main.rs # Main Stylus Rust entry point
│ │ └── lib.rs # Stylus Rust library code
│ └── examples/ # Example Stylus Rust files
│ └── counter.rsDevelopment Workflow
Initializing a Project
Create a New Project:
tswarp init myprojectNavigate to the Project Directory:
cd myproject
Compiling TypeScript to Stylus Rust
Run the Compiler:
cd converter tswarp compileCheck the Generated Stylus Rust Files:
- Output files will be added to the Stylus Rust
logicdirectory.
- Output files will be added to the Stylus Rust
Validating Stylus Rust Code
Run
cargo stylus check:cd logic tswarp buildFix Any Stylus Rust Issues:
- Review and fix any warnings or errors reported by the
cargo stylus checkcommand.
- Review and fix any warnings or errors reported by the
Contributing
Contributions are welcome! Please follow these steps:
- Fork this repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with clear messages.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- Stylus Rust: The powerful toolchain for systems programming.
- TypeScript: A strongly typed programming language for JavaScript.
- Node.js: The runtime for running the CLI.
Enjoy using Tswarp! 🚀
