Skip to content

Commit 12b3d2d

Browse files
committed
Stub out example package
1 parent 75d256b commit 12b3d2d

File tree

12 files changed

+304
-1
lines changed

12 files changed

+304
-1
lines changed

.travis.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ dart:
66
- stable
77

88
env:
9+
- PKG=example TASK=dartanalyzer
10+
- PKG=example TASK=dartfmt
11+
- PKG=example TASK=test
912
- PKG=json_annotation TASK=dartanalyzer
1013
- PKG=json_annotation TASK=dartfmt
1114
- PKG=json_serializable TASK=dartanalyzer
1215
- PKG=json_serializable TASK=dartfmt
13-
- PKG=json_serializable TASK=test
16+
- PKG=json_serializable TASK=test_1
1417

1518
matrix:
1619
exclude:
20+
- dart: stable
21+
env: PKG=example TASK=dartanalyzer
22+
- dart: stable
23+
env: PKG=example TASK=dartfmt
1724
- dart: stable
1825
env: PKG=json_serializable TASK=dartanalyzer
1926
- dart: stable

example/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Files and directories created by pub
2+
.packages
3+
.pub/
4+
build/
5+
pubspec.lock

example/.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: dart
2+
dart:
3+
- dev
4+
- stable
5+
6+
dart_task:
7+
- test
8+
9+
matrix:
10+
include:
11+
- dart: dev
12+
dart_task:
13+
dartfmt: sdk
14+
- dart: dev
15+
dart_task: dartanalyzer
16+
17+
# Only building master means that we don't run two builds for each pull request.
18+
branches:
19+
only: [master]
20+
21+
cache:
22+
directories:
23+
- $HOME/.pub-cache

example/lib/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}

example/lib/example.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// ignore_for_file: annotate_overrides
6+
library example;
7+
8+
import 'package:json_annotation/json_annotation.dart';
9+
part 'example.g.dart';
10+
11+
@JsonSerializable()
12+
class Person extends Object with _$PersonSerializerMixin {
13+
final String firstName;
14+
@JsonKey(includeIfNull: false)
15+
final String middleName;
16+
final String lastName;
17+
18+
@JsonKey(name: 'date-of-birth', nullable: false)
19+
final DateTime dateOfBirth;
20+
21+
@JsonKey(name: 'last-order')
22+
final DateTime lastOrder;
23+
24+
@JsonKey(nullable: false)
25+
List<Order> orders;
26+
27+
Person(this.firstName, this.lastName, this.dateOfBirth,
28+
{this.middleName, this.lastOrder, List<Order> orders})
29+
: this.orders = orders ?? <Order>[];
30+
31+
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
32+
}
33+
34+
@JsonSerializable(includeIfNull: false)
35+
class Order extends Object with _$OrderSerializerMixin {
36+
int count;
37+
int itemNumber;
38+
bool isRushed;
39+
Item item;
40+
41+
Order();
42+
43+
factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json);
44+
}
45+
46+
@JsonSerializable(createToJson: false)
47+
class Item {
48+
int count;
49+
int itemNumber;
50+
bool isRushed;
51+
52+
Item();
53+
54+
factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json);
55+
}
56+
57+
@JsonLiteral('data.json')
58+
Map get glossaryData => _$glossaryDataJsonLiteral;

example/lib/example.g.dart

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/pubspec.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: example
2+
author: Dart Team <misc@dartlang.org>
3+
4+
environment:
5+
sdk: '>=1.20.1 <2.0.0'
6+
7+
dependencies:
8+
json_annotation: ^0.2.1
9+
10+
dev_dependencies:
11+
build_runner: any
12+
json_serializable: ^0.2.5
13+
source_gen: ^0.7.2+1
14+
test: ^0.12.29
15+
16+
dependency_overrides:
17+
json_annotation:
18+
path: ../json_annotation
19+
json_serializable:
20+
path: ../json_serializable

example/test/example_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
import 'dart:convert';
5+
6+
import 'package:example/example.dart';
7+
import 'package:test/test.dart';
8+
9+
void main() {
10+
test('JsonSerializable', () {
11+
final person = new Person('Inigo', 'Montoya', new DateTime(1560, 5, 5));
12+
13+
final prettyJson = const JsonEncoder.withIndent(' ').convert(person);
14+
print(prettyJson);
15+
16+
final person2 =
17+
new Person.fromJson(JSON.decode(prettyJson) as Map<String, dynamic>);
18+
19+
expect(person.firstName, person2.firstName);
20+
expect(person.lastName, person2.lastName);
21+
expect(person.dateOfBirth, person2.dateOfBirth);
22+
});
23+
24+
test('JsonLiteral', () {
25+
expect(glossaryData, hasLength(1));
26+
});
27+
}

example/tool/build.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env dart --checked
2+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
3+
// for details. All rights reserved. Use of this source code is governed by a
4+
// BSD-style license that can be found in the LICENSE file.
5+
6+
import 'dart:io';
7+
8+
import 'package:build_runner/build_runner.dart';
9+
10+
import 'build_actions.dart';
11+
12+
main() async {
13+
var result = await build(buildActions, deleteFilesByDefault: true);
14+
if (result.status == BuildStatus.failure) {
15+
exitCode = 1;
16+
}
17+
}

example/tool/build_actions.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:build_runner/build_runner.dart';
6+
import 'package:json_serializable/generators.dart';
7+
import 'package:source_gen/source_gen.dart';
8+
9+
final List<BuildAction> buildActions = [
10+
new BuildAction(
11+
new PartBuilder(const [
12+
const JsonSerializableGenerator(),
13+
const JsonLiteralGenerator()
14+
]),
15+
'example',
16+
inputs: const [
17+
'lib/*.dart',
18+
],
19+
),
20+
];

0 commit comments

Comments
 (0)