I am trying to create a build_extensions rule in build.yaml for builders freezed and json_serializable to output all generated models in the directory lib/generated/model, irrespective of their original location that matches lib/**/*.dart.
What I have tried:
- I would expect
'^lib/**/{{}}.dart': 'lib/generated/model/{{}}.g.dart'to work, but it doesn't match any Dart files. - I also tried things like
'^lib/{{path}}/{{file}}.dart': 'lib/generated/model/{{file}}.g.dart'but{{path}}needs to be matched again in the destination, as per documentation (why even enforce this?).
Example:
- Base model location:
lib/core/feature/profile/profile.dart - Generated outputs after calling
flutter pub run build_runner build --delete-conflicting-outputs:lib/generated/model/profile.g.dartlib/generated/model/profile.freezed.dart
My current build.yaml (which generates .g.dart and .freezed.dart files in the child generated directory relative to the original model location) is as follows:
targets:
$default:
builders:
source_gen|combining_builder:
generate_for:
- lib/**.dart
options:
build_extensions:
# I want this line to "work":
# '^lib/**/{{}}.dart': 'lib/generated/model/{{}}.g.dart'
'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.g.dart'
freezed:
options:
build_extensions:
# I want this line to "work":
# '^lib/**/{{}}.dart': 'lib/generated/model/{{}}.freezed.dart'
'lib/{{path}}/{{file}}.dart': 'lib/{{path}}/generated/{{file}}.freezed.dart'
field_rename: snake
explicit_to_json: true
json_serializable:
options:
field_rename: snake
explicit_to_json: true