How can I change the location where the files are going to be generated from this command dart run build_runner build
.
Current folder project structure after running that command:
├── lib
│ ├── entity_generator.dart
│ └── test_files
│ ├── annotation
│ │ └── annotation.dart
│ ├── classes2.dart
│ ├── classes2.entity.dart
│ ├── classes.dart
│ ├── classes.entity.dart
│ └── gen
├── pubspec.lock
└── pubspec.yaml
Current folder project structure after generating them into the custom folder:
├── lib
│ ├── entity_generator.dart
│ └── test_files
│ ├── annotation
│ │ └── annotation.dart
│ ├── classes2.dart
│ ├── classes.dart
│ └── gen
│ ├── classes.entity.dart
| └── classes2.entity.dart
├── pubspec.lock
└── pubspec.yaml
entity_generator.dart:
class EntityGenerator extends GeneratorForAnnotation<Entity> {
@override
generateForAnnotatedElement(Element element, ConstantReader annotation, BuildStep buildStep) {
if (element is! ClassElement) {
throw InvalidGenerationSourceError('`@Entity` can only be used on classes.', element: element);
}
final className = element.displayName;
final buffer = StringBuffer();
// Generate the class with entity exports
buffer.writeln('class $className extends Entity {}');
return buffer.toString();
}
}
Builder entityBuilder(BuilderOptions options) => LibraryBuilder(EntityGenerator(), generatedExtension: '.entity.dart');
build.yaml:
targets:
$default:
builders:
test_app|export_locating_builder:
enabled: true
builders:
export_locating_builder:
import: "package:test_app/entity_generator.dart"
builder_factories: [ "entityBuilder" ]
build_extensions: {
'^lib/test_files/{{}}.dart': ['lib/test_files/gen/{{}}.entity.dart']
}
auto_apply: dependents
build_to: source
For the moment even if I did the part {{}} the files will still be generated next to the original class instead of the gen
folder. Can anyone explain to me what exactly I am doing wrong here?