diff --git a/.gitignore b/.gitignore index eb3b7e56..ae3d0ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties +.dart_tool \ No newline at end of file diff --git a/README.md b/README.md index 27c5ecf9..e74a315f 100644 --- a/README.md +++ b/README.md @@ -18,37 +18,17 @@ the time you spend writing boilerplate serialization code for your models. In your `pubspec.yaml`, you need to install the following dependencies: ```yaml dependencies: - angel_serialize: ^2.0.0-alpha + angel_serialize: ^2.0.0 dev_dependencies: - angel_serialize_generator: ^2.0.0-alpha + angel_serialize_generator: ^2.0.0 build_runner: ^0.7.0 ``` -You'll want to create a Dart script, usually named `tool/phases.dart` that invokes - `JsonModelGenerator` and `SerializerGenerator`. +With the recent updates to `package:build_runner`, you can build models in +`lib/src/models/**.dart` automatically by running `pub run build_runner build`. -```dart -import 'package:build_runner/build_runner.dart'; -import 'package:source_gen/source_gen.dart'; -import 'package:angel_serialize_generator/angel_serialize_generator.dart'; - -final List actions = [ - new BuildAction(new PartBuilder([const JsonModelGenerator()]), - '', - inputs: const ['test/models/*.dart']), - new BuildAction(new PartBuilder([const SerializerGenerator()], generatedExtension: '.serializer.g.dart'), - '', - inputs: const ['test/models/*.dart']) -]; -``` - -And then, a `tool/build.dart` can build your serializers: -```dart -import 'package:build_runner/build_runner.dart'; -import 'phases.dart'; - -main() => build(actions, deleteFilesByDefault: true); -``` +To tweak this: +https://pub.dartlang.org/packages/build_config If you want to watch for file changes and re-build when necessary, replace the `build` call with a call to `watch`. They take the same parameters. diff --git a/angel_serialize/.packages b/angel_serialize/.packages index 636ac1bf..04b29188 100644 --- a/angel_serialize/.packages +++ b/angel_serialize/.packages @@ -1,2 +1,2 @@ -# Generated by pub on 2018-02-28 16:04:20.895086. +# Generated by pub on 2018-03-02 16:15:05.377739. angel_serialize:lib/ diff --git a/angel_serialize/CHANGELOG.md b/angel_serialize/CHANGELOG.md new file mode 100644 index 00000000..07b187c9 --- /dev/null +++ b/angel_serialize/CHANGELOG.md @@ -0,0 +1,2 @@ +# 2.0.0 +* Dart 2+ constraint \ No newline at end of file diff --git a/angel_serialize/.analysis-options b/angel_serialize/analysis_options.yaml similarity index 100% rename from angel_serialize/.analysis-options rename to angel_serialize/analysis_options.yaml diff --git a/angel_serialize/example/main.dart b/angel_serialize/example/main.dart new file mode 100644 index 00000000..7ad2b1e0 --- /dev/null +++ b/angel_serialize/example/main.dart @@ -0,0 +1,7 @@ +import 'package:angel_serialize/angel_serialize.dart'; + +@serializable +class _Todo { + String text; + bool completed; +} \ No newline at end of file diff --git a/angel_serialize/pubspec.yaml b/angel_serialize/pubspec.yaml index 31c1cd2c..f2a5d456 100644 --- a/angel_serialize/pubspec.yaml +++ b/angel_serialize/pubspec.yaml @@ -1,5 +1,7 @@ name: angel_serialize -version: 2.0.0-alpha -description: Static annotations powering Angel model serialization. +version: 2.0.0 +description: Static annotations powering Angel model serialization. Combine with angel_serialize_generator for flexible modeling. author: Tobe O -homepage: https://github.com/angel-dart/serialize \ No newline at end of file +homepage: https://github.com/angel-dart/serialize +environment: + sdk: '>=2.0.0-dev.1.2 <2.0.0' \ No newline at end of file diff --git a/angel_serialize_generator/build.yaml b/angel_serialize_generator/build.yaml index a1e57687..52e83344 100644 --- a/angel_serialize_generator/build.yaml +++ b/angel_serialize_generator/build.yaml @@ -1,23 +1,28 @@ -targets: - _json_model_builder: - _serializer_builder: - builders: - json_model: - target: "_json_model_builder" + angel_serialize: + target: "angel_serialize_generator" import: "package:angel_serialize_generator/angel_serialize_generator.dart" builder_factories: - - jsonModel - auto_apply: dependents + - jsonModelBuilder + - serializerBuilder + auto_apply: root_package + build_to: source build_extensions: .dart: - ".g.dart" - serializer: - target: "_serializer_builder" - import: "package:angel_serialize_generator/angel_serialize_generator.dart" - builder_factories: - - serializeGenerator - auto_apply: dependents - build_extensions: - .dart: - - ".serializer.g.dart" \ No newline at end of file + - ".serializer.g.dart" + required_inputs: + - .dart + defaults: + generate_for: + - "lib/src/models/**.dart" + - "test/**.dart" +targets: + _book: + sources: + - "test/models/book.dart" + $default: + dependencies: + - ":_book" + sources: + - "test/models/author.dart" diff --git a/angel_serialize_generator/example/main.dart b/angel_serialize_generator/example/main.dart new file mode 100644 index 00000000..7ad2b1e0 --- /dev/null +++ b/angel_serialize_generator/example/main.dart @@ -0,0 +1,7 @@ +import 'package:angel_serialize/angel_serialize.dart'; + +@serializable +class _Todo { + String text; + bool completed; +} \ No newline at end of file diff --git a/angel_serialize_generator/lib/angel_serialize_generator.dart b/angel_serialize_generator/lib/angel_serialize_generator.dart index 82191a7c..f07634a1 100644 --- a/angel_serialize_generator/lib/angel_serialize_generator.dart +++ b/angel_serialize_generator/lib/angel_serialize_generator.dart @@ -25,7 +25,7 @@ Builder jsonModelBuilder(_) { Builder serializerBuilder(_) { return new PartBuilder( const [const SerializerGenerator()], - generatedExtension: '.g.dart', + generatedExtension: '.serializer.g.dart', ); } diff --git a/angel_serialize_generator/lib/model.dart b/angel_serialize_generator/lib/model.dart index aea27c87..94df3147 100644 --- a/angel_serialize_generator/lib/model.dart +++ b/angel_serialize_generator/lib/model.dart @@ -14,7 +14,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { var ctx = await buildContext(element, annotation, buildStep, await buildStep.resolver, true, autoIdAndDateFields != false); - var lib = new File((b) { + var lib = new Library((b) { generateClass(ctx, b, annotation); }); @@ -24,7 +24,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { /// Generate an extended model class. void generateClass( - BuildContext ctx, FileBuilder file, ConstantReader annotation) { + BuildContext ctx, LibraryBuilder file, ConstantReader annotation) { file.body.add(new Class((clazz) { clazz ..name = ctx.modelClassNameRecase.pascalCase @@ -35,8 +35,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { b ..name = field.name ..modifier = FieldModifier.final$ - ..annotations - .add(new Annotation((b) => b.code = new Code('override'))) + ..annotations.add(new CodeExpression(new Code('override'))) ..type = convertTypeReference(field.type); })); } @@ -60,7 +59,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { /// Generate a constructor with named parameters. void generateConstructor( - BuildContext ctx, ClassBuilder clazz, FileBuilder file) { + BuildContext ctx, ClassBuilder clazz, LibraryBuilder file) { clazz.constructors.add(new Constructor((constructor) { for (var field in ctx.fields) { constructor.optionalParameters.add(new Parameter((b) { @@ -75,7 +74,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { /// Generate a `copyWith` method. void generateCopyWithMethod( - BuildContext ctx, ClassBuilder clazz, FileBuilder file) { + BuildContext ctx, ClassBuilder clazz, LibraryBuilder file) { clazz.methods.add(new Method((method) { method ..name = 'copyWith' diff --git a/angel_serialize_generator/lib/serialize.dart b/angel_serialize_generator/lib/serialize.dart index f1779484..4e3a270c 100644 --- a/angel_serialize_generator/lib/serialize.dart +++ b/angel_serialize_generator/lib/serialize.dart @@ -23,7 +23,7 @@ class SerializerGenerator extends GeneratorForAnnotation { return null; } - var lib = new File((b) { + var lib = new Library((b) { generateClass(serializers.map((s) => s.toIntValue()).toList(), ctx, b); }); @@ -33,7 +33,7 @@ class SerializerGenerator extends GeneratorForAnnotation { /// Generate a serializer class. void generateClass( - List serializers, BuildContext ctx, FileBuilder file) { + List serializers, BuildContext ctx, LibraryBuilder file) { file.body.add(new Class((clazz) { clazz ..name = '${ctx.modelClassNameRecase.pascalCase}Serializer' @@ -51,7 +51,7 @@ class SerializerGenerator extends GeneratorForAnnotation { } void generateToMapMethod( - ClassBuilder clazz, BuildContext ctx, FileBuilder file) { + ClassBuilder clazz, BuildContext ctx, LibraryBuilder file) { clazz.methods.add(new Method((method) { method ..static = true @@ -112,7 +112,7 @@ class SerializerGenerator extends GeneratorForAnnotation { } void generateFromMapMethod( - ClassBuilder clazz, BuildContext ctx, FileBuilder file) { + ClassBuilder clazz, BuildContext ctx, LibraryBuilder file) { clazz.methods.add(new Method((method) { method ..static = true diff --git a/angel_serialize_generator/pubspec.yaml b/angel_serialize_generator/pubspec.yaml index 650ca51d..d292cf35 100644 --- a/angel_serialize_generator/pubspec.yaml +++ b/angel_serialize_generator/pubspec.yaml @@ -1,18 +1,18 @@ name: angel_serialize_generator -version: 2.0.0-alpha -description: Model serialization generators, designed for use with Angel. +version: 2.0.0 +description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling. author: Tobe O homepage: https://github.com/angel-dart/serialize environment: - sdk: ">=1.19.0" + sdk: '>=2.0.0-dev.1.2 <2.0.0' dependencies: angel_serialize: ^2.0.0-alpha - build_config: ">=0.0.0 <2.0.0" - code_builder: ^2.0.0 + build_config: ">=0.2.4 <2.0.0" + code_builder: ^3.0.0 id: ^1.0.0 recase: ^1.0.0 source_gen: ^0.7.0 dev_dependencies: angel_framework: ^1.0.0 - build_runner: ^0.6.0 + build_runner: ^0.7.0 test: ">= 0.12.13 < 0.13.0" \ No newline at end of file diff --git a/angel_serialize_generator/tool/actions.dart b/angel_serialize_generator/tool/actions.dart index e4db08eb..f99df7c7 100644 --- a/angel_serialize_generator/tool/actions.dart +++ b/angel_serialize_generator/tool/actions.dart @@ -1,3 +1,4 @@ +/* import 'package:build_runner/build_runner.dart'; import 'package:source_gen/source_gen.dart'; import 'package:angel_serialize_generator/angel_serialize_generator.dart'; @@ -27,3 +28,5 @@ BuildAction angelSerialize(List inputs) { inputs: inputs, ); } + +*/ \ No newline at end of file diff --git a/angel_serialize_generator/tool/build.dart b/angel_serialize_generator/tool/build.dart index 35f708bc..5b5a2c9d 100644 --- a/angel_serialize_generator/tool/build.dart +++ b/angel_serialize_generator/tool/build.dart @@ -1,4 +1,5 @@ -import 'package:build_runner/build_runner.dart'; +/*import 'package:build_runner/build_runner.dart'; import 'actions.dart'; main() => build(actions, deleteFilesByDefault: true); +*/ \ No newline at end of file diff --git a/angel_serialize_generator/tool/watch.dart b/angel_serialize_generator/tool/watch.dart index 0d243320..97f5bbf1 100644 --- a/angel_serialize_generator/tool/watch.dart +++ b/angel_serialize_generator/tool/watch.dart @@ -1,4 +1,5 @@ -import 'package:build_runner/build_runner.dart'; +/*import 'package:build_runner/build_runner.dart'; import 'actions.dart'; main() => watch(actions, deleteFilesByDefault: true); +*/ \ No newline at end of file