From 2890860a04fdcf718c9d61b780407ac118fe23b6 Mon Sep 17 00:00:00 2001 From: flowing_sky Date: Mon, 22 Aug 2022 15:20:00 +0800 Subject: [PATCH] fix: Unable to generate files in different directories #54 https://github.com/smotastic/smartstruct/issues/54#issue-1257717629 --- example/build.yaml | 18 ++++++++++++++++++ example/otherlib/example/example.dart | 19 +++++++++++++++++++ generator/lib/integrations/builder.dart | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 example/build.yaml create mode 100644 example/otherlib/example/example.dart diff --git a/example/build.yaml b/example/build.yaml new file mode 100644 index 0000000..d30b7b5 --- /dev/null +++ b/example/build.yaml @@ -0,0 +1,18 @@ +# Use the different 'build_extensions' on the folder 'otherlib'. So that the code generated by +# smartstruct will be writed to the customized folder ('otherlib/gen'). + +targets: + $default: + sources: + exclude: + - otherlib/** + + $my-target: + sources: + - otherlib/** + + builders: + smartstruct_generator|mapper: + + options: + build_extensions: {"^otherlib/{{}}.dart": "otherlib/gen/{{}}.mapper.g.dart"} diff --git a/example/otherlib/example/example.dart b/example/otherlib/example/example.dart new file mode 100644 index 0000000..d0d7a42 --- /dev/null +++ b/example/otherlib/example/example.dart @@ -0,0 +1,19 @@ +import 'package:smartstruct/smartstruct.dart'; +part '../gen/example/example.mapper.g.dart'; + +class Source { + final String userName; + + Source(this.userName); +} + +class Target { + final String username; + + Target({required this.username}); +} + +@Mapper() +abstract class ExampleMapper { + Target fromSource(Source source); +} diff --git a/generator/lib/integrations/builder.dart b/generator/lib/integrations/builder.dart index 7fd409c..a6e86f4 100644 --- a/generator/lib/integrations/builder.dart +++ b/generator/lib/integrations/builder.dart @@ -4,4 +4,4 @@ import '../generators/mapper_generator.dart'; /// Main Builder for the [Mapping] Annotation Builder smartstructBuilder(BuilderOptions options) => - PartBuilder([MapperGenerator()], '.mapper.g.dart'); + PartBuilder([MapperGenerator()], '.mapper.g.dart', options: options);