@rive-viewmodel/cli
v0.1.0
Published
CLI to generate ViewModel code from Rive (.riv) files
Downloads
27
Readme
rive-gen CLI
A Node.js CLI that generates Dart ViewModel wrapper code from Rive (.riv) files.
It uses @rive-app/canvas-advanced (the Rive JS/WASM runtime) to introspect .riv files and produces the same Dart output as the web app.
Prerequisites
- Node.js 18+
- npm 9+
Install
From npm (recommended)
npm install -g @rive-viewmodel/cliThen use it from anywhere:
rive-gen --input path/to/MyAnimation.rivUpdate to the latest published version:
npm install -g @rive-viewmodel/cli@latestUsage
From the repo root (development)
Build the CLI first:
cd packages/rive-viewmodel-cli
npm install
npm run buildThen run it:
node packages/rive-viewmodel-cli/dist/bin/rive-gen.js --input path/to/file.rivInstall globally via npm link
cd packages/rive-viewmodel-cli
npm install
npm run build
npm linkThen use it from anywhere:
rive-gen --input path/to/MyAnimation.rivOptions
| Flag | Short | Description | Default |
|------|-------|-------------|---------|
| --input <file> | -i | Path to the .riv file | required |
| --output <dir> | -o | Output directory | Same as input file |
| --name <name> | -n | Output file base name (no extension) | Input file name |
| --modern | | Use package:rive/rive.dart import | package:rive_native/rive_native.dart |
| --interface | | Implement RiveViewModel interface | false |
| --templates <dir> | | Custom Mustache templates directory | assets/templates/dart/ |
| --help | -h | Display help | |
| --version | -V | Display version | |
Examples
Generate with the legacy Rive import (default):
rive-gen -i assets/hero.riv -o lib/generatedGenerate using the modern package:rive import:
rive-gen -i assets/hero.riv -o lib/generated --modernGenerate with the RiveViewModel interface implemented:
rive-gen -i assets/hero.riv -o lib/generated --modern --interfaceCustom output file name:
rive-gen -i assets/hero_animation.riv -o lib/generated -n hero_view_modelImplementation notes
The WASM runtime is browser-first. For Node.js introspection (no rendering needed),
minimal DOM stubs (document, navigator, window) are installed before loading the
WASM. The Canvas/WebGL renderer is not used — only the File / ViewModel / DataEnum
APIs are called to read the .riv file structure.
Shared templates
The Mustache templates in assets/templates/dart/ are shared between this CLI and
the Flutter web app. Pass --templates to use a custom template directory.
At build time (npm run build) these templates are copied into the package
(templates/dart/, gitignored) so the published npm tarball is self-contained
and works when installed globally.
Publishing (maintainers)
The package is published to npm under the public @rive-viewmodel scope.
cd packages/rive-viewmodel-cli
npm login # one-time, needs access to the @rive-viewmodel org
npm version patch # or minor / major — bumps version + git tag
npm publish # runs prepublishOnly (build) automaticallyprepublishOnly rebuilds dist/ and re-bundles templates/ before every publish,
and publishConfig.access = public makes the scoped package public.
