craft_runner 0.1.0
craft_runner: ^0.1.0 copied to clipboard
Code generation runner for riverpod_craft. 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 .craft.dart files on save.
dart run riverpod_craft_cli
# or explicitly:
dart run riverpod_craft_cli watch
On startup, watch mode:
- Cleans up orphaned
.craft.dartfiles (where the source file no longer has annotations) - Processes all existing annotated files
- Watches for file changes
generate <file_path> #
Generates the .craft.dart file for a single source file.
dart run riverpod_craft_cli generate lib/providers/my_provider.dart
clean #
Removes all generated .craft.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.craft.dart - Connected via
part 'my_provider.craft.dart';(added automatically to source)
If you remove all annotations from a source file, the CLI automatically deletes the corresponding .craft.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
.craft.dartfile and ensures thepartdirective exists in the source
Requirements #
- Dart SDK: ^3.8.1