Bump to 2.0.0, modify README

This commit is contained in:
Tobe O 2018-03-02 16:23:00 -05:00
parent ec494270f3
commit 9ccc406aa5
16 changed files with 74 additions and 66 deletions

1
.gitignore vendored
View file

@ -20,3 +20,4 @@ com_crashlytics_export_strings.xml
crashlytics.properties crashlytics.properties
crashlytics-build.properties crashlytics-build.properties
fabric.properties fabric.properties
.dart_tool

View file

@ -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: In your `pubspec.yaml`, you need to install the following dependencies:
```yaml ```yaml
dependencies: dependencies:
angel_serialize: ^2.0.0-alpha angel_serialize: ^2.0.0
dev_dependencies: dev_dependencies:
angel_serialize_generator: ^2.0.0-alpha angel_serialize_generator: ^2.0.0
build_runner: ^0.7.0 build_runner: ^0.7.0
``` ```
You'll want to create a Dart script, usually named `tool/phases.dart` that invokes With the recent updates to `package:build_runner`, you can build models in
`JsonModelGenerator` and `SerializerGenerator`. `lib/src/models/**.dart` automatically by running `pub run build_runner build`.
```dart To tweak this:
import 'package:build_runner/build_runner.dart'; https://pub.dartlang.org/packages/build_config
import 'package:source_gen/source_gen.dart';
import 'package:angel_serialize_generator/angel_serialize_generator.dart';
final List<BuildAction> actions = [
new BuildAction(new PartBuilder([const JsonModelGenerator()]),
'<package-name>',
inputs: const ['test/models/*.dart']),
new BuildAction(new PartBuilder([const SerializerGenerator()], generatedExtension: '.serializer.g.dart'),
'<package-name>',
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);
```
If you want to watch for file changes and re-build when necessary, replace the `build` call 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. with a call to `watch`. They take the same parameters.

View file

@ -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/ angel_serialize:lib/

View file

@ -0,0 +1,2 @@
# 2.0.0
* Dart 2+ constraint

View file

@ -0,0 +1,7 @@
import 'package:angel_serialize/angel_serialize.dart';
@serializable
class _Todo {
String text;
bool completed;
}

View file

@ -1,5 +1,7 @@
name: angel_serialize name: angel_serialize
version: 2.0.0-alpha version: 2.0.0
description: Static annotations powering Angel model serialization. description: Static annotations powering Angel model serialization. Combine with angel_serialize_generator for flexible modeling.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/serialize homepage: https://github.com/angel-dart/serialize
environment:
sdk: '>=2.0.0-dev.1.2 <2.0.0'

View file

@ -1,23 +1,28 @@
targets:
_json_model_builder:
_serializer_builder:
builders: builders:
json_model: angel_serialize:
target: "_json_model_builder" target: "angel_serialize_generator"
import: "package:angel_serialize_generator/angel_serialize_generator.dart" import: "package:angel_serialize_generator/angel_serialize_generator.dart"
builder_factories: builder_factories:
- jsonModel - jsonModelBuilder
auto_apply: dependents - serializerBuilder
auto_apply: root_package
build_to: source
build_extensions: build_extensions:
.dart: .dart:
- ".g.dart" - ".g.dart"
serializer: - ".serializer.g.dart"
target: "_serializer_builder" required_inputs:
import: "package:angel_serialize_generator/angel_serialize_generator.dart" - .dart
builder_factories: defaults:
- serializeGenerator generate_for:
auto_apply: dependents - "lib/src/models/**.dart"
build_extensions: - "test/**.dart"
.dart: targets:
- ".serializer.g.dart" _book:
sources:
- "test/models/book.dart"
$default:
dependencies:
- ":_book"
sources:
- "test/models/author.dart"

View file

@ -0,0 +1,7 @@
import 'package:angel_serialize/angel_serialize.dart';
@serializable
class _Todo {
String text;
bool completed;
}

View file

@ -25,7 +25,7 @@ Builder jsonModelBuilder(_) {
Builder serializerBuilder(_) { Builder serializerBuilder(_) {
return new PartBuilder( return new PartBuilder(
const [const SerializerGenerator()], const [const SerializerGenerator()],
generatedExtension: '.g.dart', generatedExtension: '.serializer.g.dart',
); );
} }

View file

@ -14,7 +14,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
var ctx = await buildContext(element, annotation, buildStep, var ctx = await buildContext(element, annotation, buildStep,
await buildStep.resolver, true, autoIdAndDateFields != false); await buildStep.resolver, true, autoIdAndDateFields != false);
var lib = new File((b) { var lib = new Library((b) {
generateClass(ctx, b, annotation); generateClass(ctx, b, annotation);
}); });
@ -24,7 +24,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
/// Generate an extended model class. /// Generate an extended model class.
void generateClass( void generateClass(
BuildContext ctx, FileBuilder file, ConstantReader annotation) { BuildContext ctx, LibraryBuilder file, ConstantReader annotation) {
file.body.add(new Class((clazz) { file.body.add(new Class((clazz) {
clazz clazz
..name = ctx.modelClassNameRecase.pascalCase ..name = ctx.modelClassNameRecase.pascalCase
@ -35,8 +35,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
b b
..name = field.name ..name = field.name
..modifier = FieldModifier.final$ ..modifier = FieldModifier.final$
..annotations ..annotations.add(new CodeExpression(new Code('override')))
.add(new Annotation((b) => b.code = new Code('override')))
..type = convertTypeReference(field.type); ..type = convertTypeReference(field.type);
})); }));
} }
@ -60,7 +59,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
/// Generate a constructor with named parameters. /// Generate a constructor with named parameters.
void generateConstructor( void generateConstructor(
BuildContext ctx, ClassBuilder clazz, FileBuilder file) { BuildContext ctx, ClassBuilder clazz, LibraryBuilder file) {
clazz.constructors.add(new Constructor((constructor) { clazz.constructors.add(new Constructor((constructor) {
for (var field in ctx.fields) { for (var field in ctx.fields) {
constructor.optionalParameters.add(new Parameter((b) { constructor.optionalParameters.add(new Parameter((b) {
@ -75,7 +74,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
/// Generate a `copyWith` method. /// Generate a `copyWith` method.
void generateCopyWithMethod( void generateCopyWithMethod(
BuildContext ctx, ClassBuilder clazz, FileBuilder file) { BuildContext ctx, ClassBuilder clazz, LibraryBuilder file) {
clazz.methods.add(new Method((method) { clazz.methods.add(new Method((method) {
method method
..name = 'copyWith' ..name = 'copyWith'

View file

@ -23,7 +23,7 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
return null; return null;
} }
var lib = new File((b) { var lib = new Library((b) {
generateClass(serializers.map((s) => s.toIntValue()).toList(), ctx, b); generateClass(serializers.map((s) => s.toIntValue()).toList(), ctx, b);
}); });
@ -33,7 +33,7 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
/// Generate a serializer class. /// Generate a serializer class.
void generateClass( void generateClass(
List<int> serializers, BuildContext ctx, FileBuilder file) { List<int> serializers, BuildContext ctx, LibraryBuilder file) {
file.body.add(new Class((clazz) { file.body.add(new Class((clazz) {
clazz clazz
..name = '${ctx.modelClassNameRecase.pascalCase}Serializer' ..name = '${ctx.modelClassNameRecase.pascalCase}Serializer'
@ -51,7 +51,7 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
} }
void generateToMapMethod( void generateToMapMethod(
ClassBuilder clazz, BuildContext ctx, FileBuilder file) { ClassBuilder clazz, BuildContext ctx, LibraryBuilder file) {
clazz.methods.add(new Method((method) { clazz.methods.add(new Method((method) {
method method
..static = true ..static = true
@ -112,7 +112,7 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
} }
void generateFromMapMethod( void generateFromMapMethod(
ClassBuilder clazz, BuildContext ctx, FileBuilder file) { ClassBuilder clazz, BuildContext ctx, LibraryBuilder file) {
clazz.methods.add(new Method((method) { clazz.methods.add(new Method((method) {
method method
..static = true ..static = true

View file

@ -1,18 +1,18 @@
name: angel_serialize_generator name: angel_serialize_generator
version: 2.0.0-alpha version: 2.0.0
description: Model serialization generators, designed for use with Angel. description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/serialize homepage: https://github.com/angel-dart/serialize
environment: environment:
sdk: ">=1.19.0" sdk: '>=2.0.0-dev.1.2 <2.0.0'
dependencies: dependencies:
angel_serialize: ^2.0.0-alpha angel_serialize: ^2.0.0-alpha
build_config: ">=0.0.0 <2.0.0" build_config: ">=0.2.4 <2.0.0"
code_builder: ^2.0.0 code_builder: ^3.0.0
id: ^1.0.0 id: ^1.0.0
recase: ^1.0.0 recase: ^1.0.0
source_gen: ^0.7.0 source_gen: ^0.7.0
dev_dependencies: dev_dependencies:
angel_framework: ^1.0.0 angel_framework: ^1.0.0
build_runner: ^0.6.0 build_runner: ^0.7.0
test: ">= 0.12.13 < 0.13.0" test: ">= 0.12.13 < 0.13.0"

View file

@ -1,3 +1,4 @@
/*
import 'package:build_runner/build_runner.dart'; import 'package:build_runner/build_runner.dart';
import 'package:source_gen/source_gen.dart'; import 'package:source_gen/source_gen.dart';
import 'package:angel_serialize_generator/angel_serialize_generator.dart'; import 'package:angel_serialize_generator/angel_serialize_generator.dart';
@ -27,3 +28,5 @@ BuildAction angelSerialize(List<String> inputs) {
inputs: inputs, inputs: inputs,
); );
} }
*/

View file

@ -1,4 +1,5 @@
import 'package:build_runner/build_runner.dart'; /*import 'package:build_runner/build_runner.dart';
import 'actions.dart'; import 'actions.dart';
main() => build(actions, deleteFilesByDefault: true); main() => build(actions, deleteFilesByDefault: true);
*/

View file

@ -1,4 +1,5 @@
import 'package:build_runner/build_runner.dart'; /*import 'package:build_runner/build_runner.dart';
import 'actions.dart'; import 'actions.dart';
main() => watch(actions, deleteFilesByDefault: true); main() => watch(actions, deleteFilesByDefault: true);
*/