Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2fe0932
feat: add data binding
HayesGordon Jun 13, 2025
3bb0390
chore: clang formatting
HayesGordon Jun 13, 2025
0133ac5
chore: bump rive runtime submodule
HayesGordon Jun 15, 2025
b187809
feat: add windows build scripts
HayesGordon Jun 15, 2025
119715c
chore: fix build warnings
HayesGordon Jun 15, 2025
7442214
refactor: prefer camelCase
HayesGordon Jun 15, 2025
9704cce
Align with add-data-bindings branch on main repo
Aug 22, 2025
4f7a178
update rive version
Aug 22, 2025
2773903
Merge branch 'add-data-binding' into wn/codegen
Oct 2, 2025
e30f57b
update rive runtime and add relationship information to main.cpp
Oct 2, 2025
fe72778
fix build with premake5
Oct 2, 2025
43e6d50
no message
Oct 10, 2025
b4af108
Add support for Inja templating instead of mustache
Oct 21, 2025
a011886
Fixed the crash in the rive code generator for live_purchase_animatio…
Nov 7, 2025
dc3e62d
Remove mustache changes for now until we prove out the inja changes
Dec 22, 2025
bf9d939
no message
Jan 6, 2026
7517f0b
Merge upstream/main into wn/codegen
Jan 6, 2026
ac1acb9
no message
Jan 6, 2026
d6912d3
feat(lint): add --lint flag with configurable asset validation
cerupcat Apr 19, 2026
1212c8c
feat(rive-codegen): split monolithic main.cpp into focused modules an…
cerupcat Apr 19, 2026
d15d71b
fix(template-renderer): add missing inja data fields required by Swif…
cerupcat Apr 19, 2026
b0a95bd
fix(lint): detect embedded image format via magic bytes
cerupcat Apr 19, 2026
0fc4167
fix(lint): use FileAssetLoader to correctly detect embedded vs refere…
cerupcat Apr 19, 2026
e0c64bb
refactor(lint): use emplace to avoid redundant default construction i…
cerupcat Apr 19, 2026
7a918d3
chore: no-op lint.cpp (NoStateMachine check unchanged, rebuild for bi…
cerupcat Apr 19, 2026
843a873
Add ability to lint and get stats on file
cerupcat Jun 4, 2026
ed02a0e
Update Rive runtime for codegen imports
cerupcat Jun 17, 2026
2c306b5
Expose raw (non-uniquified) asset names to templates as asset_raw_name
cerupcat Jul 21, 2026
3c605e4
Merge pull request #5 from Whatnot-Inc/wn/expose-raw-asset-name
cerupcat Jul 21, 2026
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ examples/generated/
test/output/

# ci
.github/scripts/release/node_modules/
.github/scripts/release/node_modules/
out
.claude
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This tool parses Rive (`.riv`) files and extracts component names, artboards, st
- Diffing `.riv` files for version control purposes
- Generating complete code components

The tool uses [Mustache](https://mustache.github.io/) templating for flexible output generation.
The tool supports both [Mustache](https://mustache.github.io/) and [Inja](https://github.com/pantor/inja) template engines for flexible output generation.

:warning: Note that this tool is still experimental and untested. Feedback and contributions are appreciated.

Expand All @@ -69,13 +69,49 @@ Example:

## Custom Templates

You can use custom Mustache templates for code generation:
You can use custom templates for code generation with either Mustache or Inja template engines:

```sh
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/json_template.mustache
# Using Mustache template
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/mustache/json_template.mustache

# Using Inja template
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/inja/json_template.inja -e inja
```

Sample templates are available in the [`templates`](./templates) directory.
Sample templates are available in the [`templates`](./templates) directory:
- [`templates/mustache/`](./templates/mustache/) - Mustache templates
- [`templates/inja/`](./templates/inja/) - Inja templates

### Filtering Private Elements

Use the `--ignore-private` flag to exclude elements from code generation based on naming conventions:

```sh
./build/out/lib/release/rive_code_generator -i ./rive_files/ -o ./output/rive.json -t templates/mustache/json_template.mustache --ignore-private
```

When enabled, the following elements will be skipped:
- Elements starting with `_` (underscore)
- Elements starting with `internal` (case-insensitive)
- Elements starting with `private` (case-insensitive)

This applies to:
- **Artboards**: Artboards with private names are excluded
- **Animations**: Animations with private names are excluded from their artboards
- **State Machines**: State machines with private names are excluded from their artboards
- **View Models**: View models with private names are completely excluded
- **View Model Properties**: Properties with private names are excluded from their view models

**Example:**
```
# These will be excluded when --ignore-private is used:
- Artboard: "_InternalArtboard"
- Animation: "private_animation"
- State Machine: "internalStateMachine"
- View Model: "_TestViewModel"
- Property: "privateProperty"
```

### Template Syntax

Expand Down
14 changes: 7 additions & 7 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fi

OUT="out/lib/$CONFIG"
OUT="${OUT%/}" # Remove trailing slash if it exists
$PREMAKE --scripts=../rive-runtime/build/ --file=premake5_code_generator.lua $TARGET --config=$CONFIG --out=$OUT
$PREMAKE --scripts=../rive-runtime/build/ --file=premake5_code_generator.lua $TARGET --config=$CONFIG --out=$OUT --with_rive_tools

if [ "$OS" = "macosx" ]; then
NUM_CORES=$(($(sysctl -n hw.physicalcpu) + 1))
Expand Down Expand Up @@ -151,11 +151,11 @@ if [[ $RUN == true ]]; then
fi
if [[ $DEV == true ]]; then
pwd
# "$OUT/$EXECUTABLE" -i ../samples/signage_v03.riv -o out/rive_generated.dart -t ../templates/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/rating.riv -o out/rive_generated.dart -t ../templates/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_generated.dart -t ../templates/dart_template.mustache
"$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_viewmodel.dart -t ../templates/viewmodel_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive.json -t ../templates/json_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/signage_v03.riv -o out/rive_generated.dart -t ../templates/mustache/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/rating.riv -o out/rive_generated.dart -t ../templates/mustache/dart_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_generated.dart -t ../templates/mustache/dart_template.mustache
"$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive_viewmodel.dart -t ../templates/mustache/viewmodel_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/generated/rive.json -t ../templates/mustache/json_template.mustache
# "$OUT/$EXECUTABLE" -i ../samples/nested_test.riv -o out/rive_generated.dart --help
# "$OUT/$EXECUTABLE" -i ../samples/ -o out/rive_generated.dart
fi
fi
Binary file added dependencies/bin/premake5
Binary file not shown.
27 changes: 21 additions & 6 deletions examples/example.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Get the directory where this script is located
script_dir="$(cd "$(dirname "$0")" && pwd)"

# Define the possible paths
release_path="../build/out/lib/release/rive_code_generator"
debug_path="../build/out/lib/debug/rive_code_generator"
release_path="$script_dir/../build/out/lib/release/rive_code_generator"
debug_path="$script_dir/../build/out/lib/debug/rive_code_generator"

# Check for release build first, then debug build
if [[ -f "$release_path" ]]; then
Expand All @@ -15,9 +18,21 @@ fi
# Execute the generator with the stored path
"$generator_path" --help

# Generate a JSON file from all the sample .riv files using a custom template
"$generator_path" -i ../samples/ -o generated/rive_all.json -t ../templates/json_template.mustache
# Generate a JSON file from all the sample .riv files using Mustache template
"$generator_path" -i "$script_dir/../samples/" -o "$script_dir/generated/rive_all.json" -t "$script_dir/../templates/mustache/json_template.mustache"

# Generate a Dart file from one .riv file using Mustache template
"$generator_path" -i "$script_dir/../samples/rating.riv" -o "$script_dir/generated/rive_rating.dart" -t "$script_dir/../templates/mustache/dart_template.mustache"

# Generate Swift code using inja template with all sample .riv files
# Note: Using modular swift_example.inja with {% include %} directives
# Run from parent directory so includes can resolve correctly
(cd "$script_dir/.." && "$generator_path" -i "$script_dir/../samples/" -o "$script_dir/generated/rive_all.swift" -t "$script_dir/../templates/custom/Swift/swift_example.inja" -e inja)

# Generate a Dart file from one .riv file
"$generator_path" -i ../samples/rating.riv -o generated/rive_rating.dart -t ../templates/dart_template.mustache
# Generate Swift code using inja template for each individual .riv file
for riv_file in "$script_dir/../samples/"*.riv; do
filename=$(basename "$riv_file" .riv)
echo "Generating Swift code for $filename..."
(cd "$script_dir/.." && "$generator_path" -i "$riv_file" -o "$script_dir/generated/${filename}.swift" -t "$script_dir/../templates/custom/Swift/swift_example.inja" -e inja)
done

Loading