Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/core-web-vitals"]
}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
- run: |
npm install
npx playwright install
npx playwright install --with-deps
npm run test:coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
68 changes: 68 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

### Development
- **Run development server**: `npm run dev`
- **Build Next.js app**: `npm run build` (runs prebuild script first)
- **Start production server**: `npm start`

### Testing
- **Run tests**: `npm test` (runs Vitest with browser mode)
- **Run tests with coverage**: `npm run test:coverage`
- **Run specific test**: `npx vitest run path/to/test.file`

### Ruby/WASM
- **Build Ruby WASM**: `make pack` (bundles Ruby code with dependencies into public/ruby.wasm)
- **Run Ruby specs**: `bundle exec rspec`
- **Guard for auto-testing**: `bundle exec guard`

### Linting
- **Next.js lint**: `npm run lint`
- **Ruby lint**: `bundle exec rubocop`

### WeakAura Encoding
- **Encode WeakAura JSON to export string**: `echo '{"d": "test"}' | npm run encode`

## Architecture

### Overview
WeakAuras Ruby DSL - A Next.js web application that provides a Ruby DSL for generating World of Warcraft WeakAuras. Users write Ruby code in the browser which gets compiled via Ruby WASM to generate WeakAura export strings.

### Key Components

#### Frontend (Next.js/React)
- **app/page.tsx**: Main application page with editor interface
- **components/weak-aura-editor.tsx**: Monaco editor component for Ruby code input
- **lib/compiler.ts**: Ruby WASM initialization and compilation logic, bridges browser JS with Ruby runtime

#### Ruby DSL Core
- **public/weak_aura.rb**: Base WeakAura class defining JSON structure for WeakAura exports
- **public/whack_aura.rb**: Main DSL implementation with high-level API methods
- **public/weak_aura/**: Submodules for groups, icons, triggers
- **dynamic_group.rb**: Dynamic group positioning and layout
- **triggers/**: Trigger implementations (auras, action_usable, events)

#### WASM Integration
- Ruby code runs in browser via `@ruby/wasm-wasi` package
- **public/ruby.wasm**: Bundled Ruby runtime with dependencies
- **public/make.rb**: CLI entry point for Ruby compilation
- Uses `require_relative` patching to load Ruby files from browser

#### Lua Encoding
- **public/lua/**: Lua libraries for encoding/decoding WeakAura strings
- **encode.ts**: Node.js wrapper for Lua encoding via wasmoon

### Data Flow
1. User writes Ruby DSL code in Monaco editor
2. Code sent to Ruby WASM runtime via `lib/compiler.ts`
3. Ruby evaluates DSL, builds WeakAura data structure
4. Exports as JSON, optionally encoded to WeakAura import string
5. User copies string to import in WoW

### Testing Strategy
- **TypeScript/React**: Vitest with Playwright browser testing
- **Ruby**: RSpec for DSL logic, Guard for auto-testing
- Test files colocated with source (*.test.tsx, *_spec.rb)
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,46 @@ end

### Build

Ruby WASM file is pre-built and included in `public/ruby.wasm`.

To rebuild (requires Ruby and bundler):
```
bundle exec rbwasm build -o public/ruby.wasm
make pack
```

`ruby_wasm` 2.5.1.pre.1 currently does not build for me, there is no other version on rubygems.org, so you'll have to build [ruby.wasm](https://github.com/ruby/ruby.wasm) @ 2.4.1
### Install

Install Node.js and npm dependencies:
```
npm install
```

Ruby dependencies are optional (only needed for rebuilding WASM):
```
apt install libclang-dev
rake build
bundle install # Optional - only if rebuilding WASM
```

### Install
### Run

Install your favorite ruby and node version. Check out [mise](https://mise.jdx.dev/)
Development server:
```
npm run dev
```

### Run
Build for production:
```
npm run build
```

Test:
```
npm test
```

See `make.rb`
Lint:
```
npm run lint
```

### The WASI Way

Expand Down
2 changes: 1 addition & 1 deletion lib/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Encoder {
}

export interface Decoder {
decode(input?: Iterable<number> | ArrayBuffer | ArrayBufferView): string;
decode(input?: Uint8Array | ArrayBuffer | ArrayBufferView): string;
}

export function bytesToBase64(bytes: Iterable<number>): string {
Expand Down
5 changes: 3 additions & 2 deletions lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export const initRuby = async (
};

const response = fetch("/ruby.wasm");
const module = await compileWebAssemblyModule(response);
return await DefaultRubyVM(module, options);
// eslint-disable-next-line @next/next/no-assign-module-variable
const wasmModule = await compileWebAssemblyModule(response);
return await DefaultRubyVM(wasmModule, options);
};

export const compile = async (ruby: RubyVM, source: string) => {
Expand Down
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
Loading