Skip to content

Commit 7f92d35

Browse files
committed
readme and tool updates
1 parent 65a35e9 commit 7f92d35

File tree

4 files changed

+24
-42
lines changed

4 files changed

+24
-42
lines changed

README.md

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[![Build Status](https://travis-ci.org/dart-lang/source_gen.svg?branch=master)](https://travis-ci.org/dart-lang/source_gen)
22
[![Coverage Status](https://coveralls.io/repos/dart-lang/source_gen/badge.svg?branch=master)](https://coveralls.io/r/dart-lang/source_gen)
3-
[![Stories in Ready](https://badge.waffle.io/dart-lang/source_gen.png?label=ready&title=Ready)](https://waffle.io/dart-lang/source_gen)
43

54
_**Highly experimental. Expect breaking changes.**_
65

@@ -14,18 +13,20 @@ _**Highly experimental. Expect breaking changes.**_
1413

1514
## Example
1615

17-
Given a library `example.dart`:
16+
Given a library `example.dart` with an `Person` class annotated with
17+
`@JsonSerializable`:
1818

1919
```dart
20-
library source_gen.example.example;
20+
library source_gen.example;
2121
2222
import 'package:source_gen/generators/json_serializable.dart';
23-
2423
part 'example.g.dart';
2524
2625
@JsonSerializable()
2726
class Person extends Object with _$PersonSerializerMixin {
2827
final String firstName, middleName, lastName;
28+
29+
@JsonKey('date-of-birth')
2930
final DateTime dateOfBirth;
3031
3132
Person(this.firstName, this.lastName, {this.middleName, this.dateOfBirth});
@@ -37,31 +38,26 @@ class Person extends Object with _$PersonSerializerMixin {
3738
`source_gen` creates the corresponding part `example.g.dart`:
3839

3940
```dart
40-
part of source_gen.example.example;
41-
42-
// **************************************************************************
43-
// Generator: JsonGenerator
44-
// Target: class Person
45-
// **************************************************************************
41+
part of source_gen.example;
4642
47-
Person _$PersonFromJson(Map<String, Object> json) => new Person(
43+
Person _$PersonFromJson(Map json) => new Person(
4844
json['firstName'], json['lastName'],
4945
middleName: json['middleName'],
50-
dateOfBirth: json.containsKey('dateOfBirth')
51-
? DateTime.parse(json['dateOfBirth'])
52-
: null);
46+
dateOfBirth: json['date-of-birth'] == null
47+
? null
48+
: DateTime.parse(json['date-of-birth']));
5349
5450
abstract class _$PersonSerializerMixin {
5551
String get firstName;
5652
String get middleName;
5753
String get lastName;
5854
DateTime get dateOfBirth;
59-
Map<String, Object> toJson() => {
60-
'firstName': firstName,
61-
'middleName': middleName,
62-
'lastName': lastName,
63-
'dateOfBirth': dateOfBirth == null ? null : dateOfBirth.toIso8601String()
64-
};
55+
Map<String, dynamic> toJson() => <String, dynamic>{
56+
'firstName': firstName,
57+
'middleName': middleName,
58+
'lastName': lastName,
59+
'date-of-birth': dateOfBirth?.toIso8601String(),
60+
};
6561
}
6662
```
6763

@@ -76,15 +72,13 @@ Extend the `Generator` class to plug into `source_gen`.
7672

7773
## Running generators
7874

79-
Create a script that invokes the [generate][] method.
80-
81-
Alternatively, you can create a `build.dart` file which calls the [build]
82-
method. You can use the [build_system package][] to enjoy this automatic workflow.
83-
84-
*Note: The original design was meant to work with the
85-
[Dart Editor build system][]. Dart Editor is unsupported as of Dart 1.11.*
75+
`source_gen` is based on the `build` package (
76+
[pub](https://pub.dartlang.org/packages/build),
77+
[GitHub](https://github.com/dart-lang/build)).
8678

87-
See [build.dart][] in the repository for an example.
79+
See `build.dart` and `watch.dart` in the `tool` directory. Both reference
80+
`tool/phases.dart`, which contains information mapping `source_gen` generators
81+
to target files.
8882

8983
## source_gen vs Dart Transformers
9084
[Dart Transformers][] are often used to create and modify code and assets as part
@@ -111,5 +105,3 @@ detail*.
111105
[build.dart]: https://github.com/dart-lang/source_gen/blob/master/build.dart
112106
[generate]: http://www.dartdocs.org/documentation/source_gen/latest/index.html#source_gen/source_gen@id_generate
113107
[build]: http://www.dartdocs.org/documentation/source_gen/latest/index.html#source_gen/source_gen@id_build
114-
[Dart Editor build system]: https://www.dartlang.org/tools/editor/build.html
115-
[build_system package]: https://pub.dartlang.org/packages/build_system

build.dart

Lines changed: 0 additions & 10 deletions
This file was deleted.

tool/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import 'package:build/build.dart';
88
import 'phases.dart';
99

1010
main() async {
11-
build(phases, deleteFilesByDefault: true);
11+
await build(phases, deleteFilesByDefault: true);
1212
}

tool/travis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set -e
1010
pub run test
1111

1212
# Run the build.dart file - just to make sure it works
13-
dart --checked build.dart
13+
dart --checked tool/build.dart
1414

1515
# Install dart_coveralls; gather and send coverage data.
1616
if [ "$COVERALLS_TOKEN" ] && [ "$TRAVIS_DART_VERSION" = "stable" ]; then

0 commit comments

Comments
 (0)