Bump to 2.0.0, modify README
This commit is contained in:
parent
ec494270f3
commit
9ccc406aa5
16 changed files with 74 additions and 66 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -20,3 +20,4 @@ com_crashlytics_export_strings.xml
|
|||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.dart_tool
|
32
README.md
32
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<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);
|
||||
```
|
||||
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.
|
||||
|
|
|
@ -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/
|
||||
|
|
2
angel_serialize/CHANGELOG.md
Normal file
2
angel_serialize/CHANGELOG.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# 2.0.0
|
||||
* Dart 2+ constraint
|
7
angel_serialize/example/main.dart
Normal file
7
angel_serialize/example/main.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
|
||||
@serializable
|
||||
class _Todo {
|
||||
String text;
|
||||
bool completed;
|
||||
}
|
|
@ -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 <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/serialize
|
||||
environment:
|
||||
sdk: '>=2.0.0-dev.1.2 <2.0.0'
|
|
@ -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"
|
||||
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"
|
||||
|
|
7
angel_serialize_generator/example/main.dart
Normal file
7
angel_serialize_generator/example/main.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
|
||||
@serializable
|
||||
class _Todo {
|
||||
String text;
|
||||
bool completed;
|
||||
}
|
|
@ -25,7 +25,7 @@ Builder jsonModelBuilder(_) {
|
|||
Builder serializerBuilder(_) {
|
||||
return new PartBuilder(
|
||||
const [const SerializerGenerator()],
|
||||
generatedExtension: '.g.dart',
|
||||
generatedExtension: '.serializer.g.dart',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
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<Serializable> {
|
|||
|
||||
/// 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<Serializable> {
|
|||
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<Serializable> {
|
|||
|
||||
/// 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<Serializable> {
|
|||
|
||||
/// 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'
|
||||
|
|
|
@ -23,7 +23,7 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
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<Serializable> {
|
|||
|
||||
/// Generate a serializer class.
|
||||
void generateClass(
|
||||
List<int> serializers, BuildContext ctx, FileBuilder file) {
|
||||
List<int> 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<Serializable> {
|
|||
}
|
||||
|
||||
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<Serializable> {
|
|||
}
|
||||
|
||||
void generateFromMapMethod(
|
||||
ClassBuilder clazz, BuildContext ctx, FileBuilder file) {
|
||||
ClassBuilder clazz, BuildContext ctx, LibraryBuilder file) {
|
||||
clazz.methods.add(new Method((method) {
|
||||
method
|
||||
..static = true
|
||||
|
|
|
@ -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 <thosakwe@gmail.com>
|
||||
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"
|
|
@ -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<String> inputs) {
|
|||
inputs: inputs,
|
||||
);
|
||||
}
|
||||
|
||||
*/
|
|
@ -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);
|
||||
*/
|
|
@ -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);
|
||||
*/
|
Loading…
Reference in a new issue