Works with new build runner, etc.
This commit is contained in:
parent
759ce7c59e
commit
79608562aa
11 changed files with 83 additions and 21 deletions
21
.gitignore
vendored
21
.gitignore
vendored
|
@ -1 +1,22 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
.idea/**/mongoSettings.xml
|
||||
*.iws
|
||||
/out/
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/serialize.iml" filepath="$PROJECT_DIR$/.idea/serialize.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
22
.idea/serialize.iml
Normal file
22
.idea/serialize.iml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$/angel_serialize">
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize/packages" />
|
||||
</content>
|
||||
<content url="file://$MODULE_DIR$/angel_serialize_generator">
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/packages" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/test/models/packages" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/test/packages" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/angel_serialize_generator/tool/packages" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -21,7 +21,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
Element element, ConstantReader reader, BuildStep buildStep) async {
|
||||
if (element.kind != ElementKind.CLASS)
|
||||
throw 'Only classes can be annotated with a @Serializable() annotation.';
|
||||
var ctx = buildContext(
|
||||
var ctx = await buildContext(
|
||||
element,
|
||||
serializable,
|
||||
buildStep,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
|
@ -16,18 +17,18 @@ const TypeChecker serializableTypeChecker =
|
|||
const TypeChecker.fromRuntime(Serializable);
|
||||
|
||||
// TODO: Should add id, createdAt, updatedAt...
|
||||
BuildContext buildContext(
|
||||
Future<BuildContext> buildContext(
|
||||
ClassElement clazz,
|
||||
Serializable annotation,
|
||||
BuildStep buildStep,
|
||||
Resolver resolver,
|
||||
bool autoSnakeCaseNames,
|
||||
bool autoIdAndDateFields,
|
||||
{bool heedExclude: true}) {
|
||||
{bool heedExclude: true}) async {
|
||||
var ctx = new BuildContext(annotation,
|
||||
originalClassName: clazz.name,
|
||||
sourceFilename: p.basename(buildStep.inputId.path));
|
||||
var lib = resolver.getLibrary(buildStep.inputId);
|
||||
var lib = await resolver.libraryFor(buildStep.inputId);
|
||||
List<String> fieldNames = [];
|
||||
|
||||
for (var field in clazz.fields) {
|
||||
|
@ -62,10 +63,11 @@ BuildContext buildContext(
|
|||
}
|
||||
|
||||
DartType dateTime;
|
||||
['createdAt', 'updatedAt'].forEach((key) {
|
||||
for (var key in ['createdAt', 'updatedAt']) {
|
||||
if (!fieldNames.contains(key)) {
|
||||
if (dateTime == null) {
|
||||
var coreLib = resolver.libraries.singleWhere((lib) => lib.isDartCore);
|
||||
var coreLib =
|
||||
await resolver.libraries.singleWhere((lib) => lib.isDartCore);
|
||||
var dt = coreLib.getType('DateTime');
|
||||
dateTime = dt.type;
|
||||
}
|
||||
|
@ -75,7 +77,8 @@ BuildContext buildContext(
|
|||
ctx.fields.add(field);
|
||||
ctx.shimmed[key] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: angel_serialize_generator
|
||||
version: 1.0.0-alpha+2
|
||||
version: 1.0.0-alpha+3
|
||||
description: Model serialization generators, designed for use with Angel.
|
||||
author: Tobe O <thosakwe@gmail.com>
|
||||
homepage: https://github.com/angel-dart/serialize
|
||||
|
@ -13,5 +13,5 @@ dependencies:
|
|||
source_gen: ^0.7.0
|
||||
dev_dependencies:
|
||||
angel_framework: ^1.0.0
|
||||
build_runner: ^0.3.0
|
||||
build_runner: ^0.5.0
|
||||
test: ">= 0.12.13 < 0.13.0"
|
9
angel_serialize_generator/tool/actions.dart
Normal file
9
angel_serialize_generator/tool/actions.dart
Normal file
|
@ -0,0 +1,9 @@
|
|||
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()]),
|
||||
'angel_serialize_generator',
|
||||
inputs: const ['test/models/*.dart'])
|
||||
];
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'phases.dart';
|
||||
import 'actions.dart';
|
||||
|
||||
main() => build(PHASES, deleteFilesByDefault: true);
|
||||
main() => build(actions, deleteFilesByDefault: true);
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
import 'package:angel_serialize_generator/angel_serialize_generator.dart';
|
||||
|
||||
final PhaseGroup PHASES = new PhaseGroup.singleAction(
|
||||
new PartBuilder([const JsonModelGenerator()]),
|
||||
new InputSet('angel_serialize_generator', const ['test/models/*.dart']));
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:build_runner/build_runner.dart';
|
||||
import 'phases.dart';
|
||||
import 'actions.dart';
|
||||
|
||||
main() => watch(PHASES, deleteFilesByDefault: true);
|
||||
main() => watch(actions, deleteFilesByDefault: true);
|
||||
|
|
Loading…
Reference in a new issue