Closed bilalrabibi closed 8 months ago
Try running dart run build_runner doctor
, which should complain about an unknown builder key.
Specifically, this builder actually comes from the drift_dev
package, so it should be something like drift_dev
or drift_dev:drift_dev
.
There are a lot of other builders too (see here), so depending on exactly what you want to achieve you might need to list some of those.
Thanks allot I was able to resolve it using below code
auto_models:
import: "package:auto_models/builder.dart"
builder_factories: ["dataModalBuilder"]
build_extensions: { ".dart": [ ".mapped.g.dart" ] }
auto_apply: dependents
build_to: source
runs_before: ["drift_dev|drift_dev"]
applies_builders: ["source_gen|combining_builder"]
The only problem i am not able to generate the code in a different folder like /generate using this
The only problem i am not able to generate the code in a different folder like /generate using this
Have you looked at using capture groups?
Yes sir. I have tried in main build.yaml file
auto_models:
options:
build_extensions:
"{{}}.dart": '{{dir}}/generated/{{file}}.mapped.g.dart'
full yaml file is
targets:
$default:
builders:
#general purpose .g.dart builder
source_gen|combining_builder:
enabled: true
generate_for:
- lib/**.dart
options:
build_extensions:
'^{{path}}/{{file}}.dart': '{{path}}/generated/{{file}}.g.dart'
#chopper
chopper_generator:
options:
# This assumes you want the files to end with `.chopper.g.dart`
# instead of the default `.chopper.dart`.
build_extensions:
"^{{path}}/{{file}}.dart": '{{path}}/generated/{{file}}.chopper.g.dart'
Package yaml file
targets:
$default:
builders:
auto_models|auto_models:
enabled: true
builders:
auto_models:
import: "package:auto_models/builder.dart"
builder_factories: ["dataModalBuilder"]
build_extensions: { ".dart": [ "generated/.mapped.g.dart" ] }
auto_apply: dependents
build_to: source
runs_before: ["drift_dev|drift_dev"]
applies_builders: ["source_gen|combining_builder"]
also tried
build_extensions: { ".dart": [ ".mapped.g.dart" ] }
but files are always generating inside same folder
Ah, this build_extensions
option support is something provided by the source_gen|combining
builder, it is not a core part of the platform. I don't think it supports capture groups.
This package only supports configuration in the builders
section, and not through builder options.
It's not clear to me what action we need to take on this issue.
You should be able to use capture groups in the build_extensions
argument of a builders
definition. (builders
-> auto_models
-> build_extensions
). The examples you show don't have an {{}}
. You do have examples of passing overridden build extension through the options (targets
-> $default
-> builders
-> chopper_generator
-> options
-> build_extension
) with {{}}
syntax, and can use similar arguments in your builder definition if you want your auto_models
builder to do directory moves by default.
If you want the auto_models
to support arguments like the chopper_generator
supports, that requires manual implementation within the builder. You can see an example of adding such support in https://github.com/dart-lang/source_gen/pull/564
I'm going to close this for now since I don't think there is any action for us to take.
I tried runs_before: ['drift:drift_dev'] and ['drift:drift_dev'] too
Please note both packages are added in pubspec.yaml file
I am trying to run this code generator before the one run by the
drift
database but i am not able to get the order correct.Dart SDK Version (
Dart SDK version: 3.2.0 (stable)
)What package(s) from this repo you are using, and the version (i.e.
build_runner: ^2.0.0
)What builder(s) you are using (or writing yourself). Try to give a short summary of what they do.
Generate model files for tables which are used by drift package