riverpod_craft_cli 0.1.1
riverpod_craft_cli: ^0.1.1 copied to clipboard
CLI tool for riverpod_craft. Generates provider code from annotations. Watch mode, single file generation, and cleanup.
riverpod_craft_cli #
Code generation CLI for riverpod_craft. Parses Dart source files with @provider, @command, and @settable annotations and generates type-safe provider boilerplate.
Installation #
The CLI is included in the riverpod_craft_cli package. Add it as a dev dependency or run directly:
dev_dependencies:
riverpod_craft_cli:
path: ../riverpod_craft_cli
Commands #
watch (default) #
Monitors the lib/ directory and regenerates .pg.dart files on save.
dart run riverpod_craft_cli
# or explicitly:
dart run riverpod_craft_cli watch
On startup, watch mode:
- Cleans up orphaned
.pg.dartfiles (where the source file no longer has annotations) - Processes all existing annotated files
- Watches for file changes
generate <file_path> #
Generates the .pg.dart file for a single source file.
dart run riverpod_craft_cli generate lib/providers/my_provider.dart
clean #
Removes all generated .pg.dart files from the project.
dart run riverpod_craft_cli clean
init #
Sets up the project — installs Dart dependencies and VS Code extension.
dart run riverpod_craft_cli init
help #
Shows available commands.
dart run riverpod_craft_cli help
Generated Files #
- Source:
my_provider.dart - Output:
my_provider.pg.dart - Connected via
part 'my_provider.pg.dart';(added automatically to source)
If you remove all annotations from a source file, the CLI automatically deletes the corresponding .pg.dart file and removes the part directive.
What Gets Generated #
For each annotated provider, the CLI generates:
| Source | Generated |
|---|---|
@provider class with Future<T> create() |
DataNotifier base class, provider declaration, Ref/WidgetRef facades, extensions |
@provider class with T create() |
StateDataNotifier base class, provider declaration, facades with setState() |
@provider function |
Notifier class, provider declaration, facades, extensions |
@command methods |
CommandNotifier subclass, command facades with run()/reset()/retry() |
| Family parameters | Callable facade classes, invalidateFamily() |
How It Works #
- Parse — Uses the Dart
analyzerpackage to parse source files into AST - Collect — Walks the AST to find annotated classes/functions and extract metadata (types, parameters, annotations)
- Generate — Builds provider code from the collected metadata
- Write — Outputs the
.pg.dartfile and ensures thepartdirective exists in the source
Requirements #
- Dart SDK: ^3.8.1