https://github.com/rive-app/rive-code-generator-wip
https://github.com/rive-app/rive-code-generator-wip
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rive-app/rive-code-generator-wip
- Owner: rive-app
- License: mit
- Created: 2024-10-11T14:56:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-15T13:49:16.000Z (about 1 year ago)
- Last Synced: 2025-07-13T21:23:27.785Z (12 months ago)
- Language: C++
- Size: 348 KB
- Stars: 11
- Watchers: 10
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.MD
- License: LICENSE
Awesome Lists containing this project
README
Rive Code Generator
Simplify Rive integration at runtime:
Generate type-safe wrappers for Rive files.
Releases
·
Usage
·
Custom Templates
·
Contribute
·
License
This tool parses Rive (`.riv`) files and extracts component names, artboards, state machine inputs, and other components in a human-readable format. Key features include:
- Creating type-safe wrappers for `.riv` files (e.g., static helper classes)
- Generating JSON representations of `.riv` files
- Diffing `.riv` files for version control purposes
- Generating complete code components
The tool uses [Mustache](https://mustache.github.io/) templating for flexible output generation.
:warning: Note that this tool is still experimental and untested. Feedback and contributions are appreciated.
## Releases
See the [release workflow](.github/workflows/release_workflow.yaml) for release details.
The latest release can be downloaded from the [Releases](https://github.com/rive-app/rive-code-generator-wip/releases) page.
## Usage
Run the code generator using:
```sh
./build/out/lib//rive_code_generator -i -o -l
```
Example:
```sh
./build/out/lib/release/rive_code_generator -i ./examples/rive_files/animation.riv -o ./examples/generated_code.dart -l dart
```
## Custom Templates
You can use custom Mustache templates for code generation:
```sh
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/json_template.mustache
```
Sample templates are available in the [`templates`](./templates) directory.
### Template Syntax
The tool uses [Mustache](https://mustache.github.io/) templating. Please refer to the [Mustache documentation](https://mustache.github.io/) for syntax details.
For each Rive file `{{#riv_files}}`, the following variables are available:
- `{{riv_pascal_case}}`: The Rive file name in PascalCase
- `{{riv_camel_case}}`: The Rive file name in camelCase
- `{{riv_snake_case}}`: The Rive file name in snake_case
- `{{riv_kebab_case}}`: The Rive file name in kebab-case
- `{{assets}}`: List of assets in the Rive file
- For each asset `{{#assets}}`:
- `{{asset_name}}`: Name of the asset
- `{{asset_camel_case}}`: Name of the asset in camelCase
- `{{asset_pascal_case}}`: Name of the asset in PascalCase
- `{{asset_snake_case}}`: Name of the asset in snake_case
- `{{asset_kebab_case}}`: Name of the asset in kebab-case
- `{{asset_type}}`: Type of the asset
- `{{asset_id}}`: ID of the asset
- `{{asset_cdn_uuid}}`: CDN UUID of the asset
- `{{asset_cdn_base_url}}`: CDN base URL of the asset
- For each artboard `{{#artboards}}`:
- `{{artboard_name}}`: The original artboard name
- `{{artboard_pascal_case}}`: The artboard name in PascalCase
- `{{artboard_camel_case}}`: The artboard name in camelCase
- `{{artboard_snake_case}}`: The artboard name in snake_case
- `{{artboard_kebab_case}}`: The artboard name in kebab-case
- `{{animations}}`: List of animation names for the artboard
- For each animation `{{#animations}}`:
- `{{animation_name}}`: Name of the animation
- `{{animation_camel_case}}`: Name of the animation in camelCase
- `{{animation_pascal_case}}`: Name of the animation in PascalCase
- `{{animation_snake_case}}`: Name of the animation in snake_case
- `{{animation_kebab_case}}`: Name of the animation in kebab-case
- `{{state_machines}}`: List of state machines for the artboard
- For each state machine `{{#state_machines}}`:
- `{{state_machine_name}}`: Name of the state machine
- `{{state_machine_camel_case}}`: Name of the state machine in camelCase
- `{{state_machine_pascal_case}}`: Name of the state machine in PascalCase
- `{{state_machine_snake_case}}`: Name of the state machine in snake_case
- `{{state_machine_kebab_case}}`: Name of the state machine in kebab-case
- `{{inputs}}`: List of inputs for the state machine
- For each input `{{#inputs}}`:
- `{{input_name}}`: Name of the input
- `{{input_type}}`: Type of the input
- `{{input_default_value}}`: Default value of the input
- `{{text_value_runs}}`: List of text value runs for the artboard
- For each text value run `{{#text_value_runs}}`:
- `{{text_value_run_name}}`: Name of the text value run
- `{{text_value_run_camel_case}}`: Name of the text value run in camelCase
- `{{text_value_run_pascal_case}}`: Name of the text value run in PascalCase
- `{{text_value_run_snake_case}}`: Name of the text value run in snake_case
- `{{text_value_run_kebab_case}}`: Name of the text value run in kebab-case
- `{{text_value_run_default}}`: Default value of the text value run
- `{{text_value_run_default_sanitized}}`: Default value of the text value run with special characters encoded
- For each nested text value run `{{#nested_text_value_runs}}`:
- `{{nested_text_value_run_name}}`: Name of the nested text value run
- `{{nested_text_value_run_path}}`: Path of the nested text value run
**:warning: Warning:** For duplicated names (e.g., multiple artboards, animations, or assets with the same name), the original unique names will be preserved. However, the case-converted versions (such as camelCase, PascalCase, etc.) will have a unique identifier attached to avoid conflicts.
For example:
- Original names: "MyArtboard", "MyArtboard"
- Unique camelCase: "myArtboard", "myArtboardU1"
This ensures that all generated code and references remain unique and valid.
## Supported Languages
At the moment, the tool supports Dart and JSON outputs. More defualt exports will be added. However, you can easily add your own by providing a custom template.
## Contribute
Contributions are welcome! Please see our [Contributing Guidelines](CONTRIBUTING.md) for more details.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.