Skip to content

Commit d14169a

Browse files
authored
Creating a stand-alone example (#80)
1 parent 75d256b commit d14169a

20 files changed

+277
-12
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ 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
@@ -14,6 +17,10 @@ env:
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

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [![Build Status](https://travis-ci.org/dart-lang/json_serializable.svg?branch=master)](https://travis-ci.org/dart-lang/json_serializable)
22

3-
Provides `source_gen` `Generator`s which generate code to
4-
make it simple to serialize to and from JSON.
3+
Provides [source_gen] `Generator`s to create code for JSON serialization and
4+
deserialization.
55

66
## [json_serializable]
77

@@ -15,5 +15,12 @@ The annotation package which has no dependencies.
1515

1616
Import it into your pubspec `dependencies:` section.
1717

18+
## [example]
19+
20+
A simple example showing how to setup and use [json_serializable] and
21+
[json_annotation].
22+
1823
[json_serializable]: https://github.com/dart-lang/json_serializable/blob/master/json_serializable/README.md
1924
[json_annotation]: https://github.com/dart-lang/json_serializable/blob/master/json_annotation/README.md
25+
[example]: https://github.com/dart-lang/json_serializable/blob/master/example/README.md
26+
[source_gen]: https://pub.dartlang.org/packages/source_gen

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

example/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
An simple example of a Dart package using [json_serializable].
2+
3+
* `lib/example.dart`: A library configured with annotations –
4+
`JsonSerializable` and `JsonLiteral` – to enable code generation.
5+
6+
* Note: the annotations are defined in `package:json_annotation`.
7+
This is the only package required in the `dependencies` section of your
8+
`pubspec.yaml`.
9+
10+
* `tool/`: Contains the code run during development to create and update
11+
generated code.
12+
13+
* `build_actions.dart`: A convention when using `package:build` to
14+
have one location to define the actions to be run by `build.dart` and
15+
`watch.dart`. See the comments in the source file for more information.
16+
17+
* `build.dart`: Runs one build using the actions defined in
18+
`build_actions.dart`.
19+
20+
* `watch.dart`: Starts a watcher that (re)runs the actions defined in
21+
`build_actions.dart` when files change.
22+
23+
[json_serializable]: https://pub.dartlang.org/packages/json_serializable

example/dart_test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tags:
2+
presubmit-only:
3+
skip: "Should only be run during presubmit"
File renamed without changes.

json_serializable/example/example.dart renamed to example/lib/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
// ignore_for_file: annotate_overrides
6-
library json_serializable.example;
6+
library example;
77

88
import 'package:json_annotation/json_annotation.dart';
99
part 'example.g.dart';

json_serializable/example/example.g.dart renamed to example/lib/example.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// GENERATED CODE - DO NOT MODIFY BY HAND
66

7-
part of json_serializable.example;
7+
part of example;
88

99
// **************************************************************************
1010
// Generator: JsonSerializableGenerator

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 <[email protected]>
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

0 commit comments

Comments
 (0)