Restructured+Travis
This commit is contained in:
parent
1ec4b89707
commit
209feddb53
26 changed files with 158 additions and 36 deletions
|
@ -1 +1,2 @@
|
|||
language: dart
|
||||
language: dart
|
||||
script: bash tool/.travis.sh
|
19
README.md
19
README.md
|
@ -2,12 +2,9 @@
|
|||
[![Pub](https://img.shields.io/pub/v/angel_serialize.svg)](https://pub.dartlang.org/packages/angel_serialize)
|
||||
[![build status](https://travis-ci.org/angel-dart/serialize.svg)](https://travis-ci.org/angel-dart/serialize)
|
||||
|
||||
**This project is currently in the early stages, and may change at any given
|
||||
time without warning.**
|
||||
|
||||
Source-generated serialization for Dart object. This package uses `package:source_gen` to eliminate
|
||||
Source-generated serialization for Dart objects. This package uses `package:source_gen` to eliminate
|
||||
the time you spend writing boilerplate serialization code for your models.
|
||||
`package:angel_serialize` also powers `package:angel_postgres` and other ORM functionality.
|
||||
`package:angel_serialize` also powers `package:angel_orm`.
|
||||
|
||||
* [Usage](#usage)
|
||||
* [Models](#models)
|
||||
|
@ -16,12 +13,12 @@ the time you spend writing boilerplate serialization code for your models.
|
|||
* [Nesting](#nesting)
|
||||
|
||||
# Usage
|
||||
In your `pubspec.yaml`:
|
||||
In your `pubspec.yaml`, you need to install the following dependencies:
|
||||
```yaml
|
||||
dependencies:
|
||||
angel_serialize:
|
||||
git: https://github.com/angel-dart/serialize.git
|
||||
angel_serialize: ^1.0.0-alpha
|
||||
dev_dependencies:
|
||||
angel_serialize_builder: ^1.0.0-alpha
|
||||
build_runner: ^0.3.0
|
||||
```
|
||||
|
||||
|
@ -31,7 +28,7 @@ the `JsonModelGenerator`.
|
|||
```dart
|
||||
import 'package:build_runner/build_runner.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:angel_serialize/builder.dart';
|
||||
import 'package:angel_serialize_builder/angel_serialize_builder.dart';
|
||||
|
||||
final PhaseGroup PHASES = new PhaseGroup.singleAction(
|
||||
new GeneratorBuilder([const JsonModelGenerator()]),
|
||||
|
@ -145,6 +142,10 @@ class Book extends _Book {
|
|||
};
|
||||
|
||||
static Book parse(Map map) => new Book.fromJson(map);
|
||||
|
||||
Book clone() {
|
||||
return new Book.fromJson(toJson());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
56
angel_serialize/.gitignore
vendored
Normal file
56
angel_serialize/.gitignore
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
# See https://www.dartlang.org/tools/private-files.html
|
||||
|
||||
# Files and directories created by pub
|
||||
../.packages
|
||||
.pub/
|
||||
build/
|
||||
# If you're building an application, you may want to check-in your pubspec.lock
|
||||
pubspec.lock
|
||||
|
||||
# Directory created by dartdoc
|
||||
# If you don't generate documentation locally you can remove this line.
|
||||
doc/api/
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
2
angel_serialize/.packages
Normal file
2
angel_serialize/.packages
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Generated by pub on 2017-07-10 11:01:13.581030.
|
||||
angel_serialize:lib/
|
5
angel_serialize/README.md
Normal file
5
angel_serialize/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# angel_serialize
|
||||
The frontend for Angel model serialization.
|
||||
See documentation in the main project repo:
|
||||
|
||||
https://github.com/angel-dart/serialize
|
5
angel_serialize/pubspec.yaml
Normal file
5
angel_serialize/pubspec.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name: angel_serialize
|
||||
version: 1.0.0-alpha+1
|
||||
description: Static annotations powering Angel model serialization.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/serialize
|
2
angel_serialize_generator/.analysis-options
Normal file
2
angel_serialize_generator/.analysis-options
Normal file
|
@ -0,0 +1,2 @@
|
|||
analyzer:
|
||||
strong-mode: true
|
21
angel_serialize_generator/LICENSE
Normal file
21
angel_serialize_generator/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 The Angel Framework
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
5
angel_serialize_generator/README.md
Normal file
5
angel_serialize_generator/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# angel_serialize_generator
|
||||
The builder for Angel's model serialization.
|
||||
|
||||
Find documentation in the main project repo:
|
||||
https://github.com/angel-dart/serialize
|
|
@ -1,12 +1,12 @@
|
|||
import 'dart:async';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:code_builder/code_builder.dart';
|
||||
import 'package:code_builder/dart/core.dart';
|
||||
import 'package:source_gen/src/annotation.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'angel_serialize.dart';
|
||||
import 'build_context.dart';
|
||||
import 'context.dart';
|
||||
|
||||
|
@ -45,6 +45,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
var genClassName = ctx.modelClassName;
|
||||
var genClass = new ClassBuilder(genClassName,
|
||||
asExtends: new TypeBuilder(ctx.originalClassName));
|
||||
var modelType = new TypeBuilder(genClassName);
|
||||
|
||||
// Now, add all fields to the base class
|
||||
ctx.fields.forEach((field) {
|
||||
|
@ -243,18 +244,25 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
|
||||
return out..[field.name] = value;
|
||||
});
|
||||
fromJson.addStatement(new TypeBuilder(genClassName)
|
||||
.newInstance([], named: namedParams).asReturn());
|
||||
fromJson
|
||||
.addStatement(modelType.newInstance([], named: namedParams).asReturn());
|
||||
genClass.addConstructor(fromJson);
|
||||
|
||||
// Create `parse` to just forward
|
||||
var parseMethod = new MethodBuilder('parse',
|
||||
returnType: new TypeBuilder(genClassName),
|
||||
returns: new TypeBuilder(genClassName)
|
||||
.newInstance([reference('map')], constructor: 'fromJson'));
|
||||
returnType: modelType,
|
||||
returns:
|
||||
modelType.newInstance([reference('map')], constructor: 'fromJson'));
|
||||
parseMethod.addPositional(parameter('map', [new TypeBuilder('Map')]));
|
||||
genClass.addMethod(parseMethod, asStatic: true);
|
||||
|
||||
// Create clone() method...
|
||||
var cloneMethod = new MethodBuilder('clone', returnType: modelType);
|
||||
cloneMethod.addStatement(modelType.newInstance(
|
||||
[reference('toJson').call([])],
|
||||
constructor: 'fromJson').asReturn());
|
||||
genClass.addMethod(cloneMethod);
|
||||
|
||||
return genClass;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'angel_serialize.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
|
||||
class BuildContext {
|
||||
final Map<String, String> aliases = {};
|
||||
|
@ -16,9 +16,6 @@ class BuildContext {
|
|||
? originalClassName.substring(1)
|
||||
: originalClassName;
|
||||
|
||||
String get queryClassName => modelClassName + 'Query';
|
||||
String get whereClassName => queryClassName + 'Where';
|
||||
|
||||
String resolveFieldName(String name) =>
|
||||
aliases.containsKey(name) ? aliases[name] : name;
|
||||
}
|
18
angel_serialize_generator/pubspec.yaml
Normal file
18
angel_serialize_generator/pubspec.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
name: angel_serialize_generator
|
||||
version: 1.0.0-alpha+1
|
||||
description: Model serialization generators, designed for use with Angel.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/serialize
|
||||
environment:
|
||||
sdk: ">=1.19.0"
|
||||
dependencies:
|
||||
angel_serialize: ^1.0.0-alpha
|
||||
build: ^0.9.0
|
||||
code_builder: ^1.0.0
|
||||
id: ^1.0.0
|
||||
recase: ^1.0.0
|
||||
source_gen: ^0.6.0
|
||||
dev_dependencies:
|
||||
angel_framework: ^1.0.0
|
||||
build_runner: ^0.3.0
|
||||
test: ">= 0.12.13 < 0.13.0"
|
|
@ -68,6 +68,10 @@ class Book extends _Book {
|
|||
};
|
||||
|
||||
static Book parse(Map map) => new Book.fromJson(map);
|
||||
|
||||
Book clone() {
|
||||
return new Book.fromJson(toJson());
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
|
@ -145,6 +149,10 @@ class Author extends _Author {
|
|||
};
|
||||
|
||||
static Author parse(Map map) => new Author.fromJson(map);
|
||||
|
||||
Author clone() {
|
||||
return new Author.fromJson(toJson());
|
||||
}
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
|
@ -200,4 +208,8 @@ class Library extends _Library {
|
|||
};
|
||||
|
||||
static Library parse(Map map) => new Library.fromJson(map);
|
||||
|
||||
Library clone() {
|
||||
return new Library.fromJson(toJson());
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:angel_serialize/builder.dart';
|
||||
import 'package:angel_serialize_generator/angel_serialize_generator.dart';
|
||||
|
||||
final PhaseGroup PHASES = new PhaseGroup.singleAction(
|
||||
new GeneratorBuilder([const JsonModelGenerator()]),
|
||||
new InputSet('angel_serialize', const ['test/models/*.dart']));
|
||||
new InputSet('angel_serialize_generator', const ['test/models/*.dart']));
|
14
pubspec.yaml
14
pubspec.yaml
|
@ -1,14 +0,0 @@
|
|||
name: angel_serialize
|
||||
version: 1.0.0-alpha
|
||||
description: Model serialization generators.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/serialize
|
||||
dependencies:
|
||||
code_builder: ^1.0.0
|
||||
id: ^1.0.0
|
||||
recase: ^1.0.0
|
||||
source_gen: ^0.5.8
|
||||
dev_dependencies:
|
||||
angel_framework: ^1.0.0
|
||||
build_runner: ^0.3.0
|
||||
test: ">= 0.12.13 < 0.13.0"
|
3
tool/.travis.sh
Normal file
3
tool/.travis.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
cd angel_serialize_generator
|
||||
dart tool/build.dart
|
||||
pub run test
|
Loading…
Reference in a new issue