source_gen
This commit is contained in:
parent
4ad42ae682
commit
3c8cab050e
6 changed files with 40 additions and 22 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,6 +2,9 @@
|
||||||
### Dart template
|
### Dart template
|
||||||
# See https://www.dartlang.org/tools/private-files.html
|
# See https://www.dartlang.org/tools/private-files.html
|
||||||
|
|
||||||
|
# source_gen
|
||||||
|
*.g.dart
|
||||||
|
|
||||||
# Files and directories created by pub
|
# Files and directories created by pub
|
||||||
.buildlog
|
.buildlog
|
||||||
.packages
|
.packages
|
||||||
|
|
|
@ -1,14 +1,26 @@
|
||||||
library angel.models.user;
|
library angel.models.user;
|
||||||
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:angel_mongo/model.dart';
|
import 'package:angel_mongo/model.dart';
|
||||||
|
import 'package:source_gen/generators/json_serializable.dart';
|
||||||
|
|
||||||
class User extends Model {
|
part 'user.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class User extends Model with _$UserSerializerMixin {
|
||||||
|
@JsonKey('email')
|
||||||
String email;
|
String email;
|
||||||
|
|
||||||
|
@JsonKey('username')
|
||||||
String username;
|
String username;
|
||||||
|
|
||||||
|
@JsonKey('password')
|
||||||
String password;
|
String password;
|
||||||
|
|
||||||
|
@JsonKey('roles')
|
||||||
final List<String> roles = [];
|
final List<String> roles = [];
|
||||||
|
|
||||||
|
factory User.fromJson(Map json) => _$UserFromJson(json);
|
||||||
|
|
||||||
User(
|
User(
|
||||||
{String id,
|
{String id,
|
||||||
this.email,
|
this.email,
|
||||||
|
@ -21,23 +33,4 @@ class User extends Model {
|
||||||
this.roles.addAll(roles);
|
this.roles.addAll(roles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
factory User.fromJson(String json) => new User.fromMap(JSON.decode(json));
|
|
||||||
|
|
||||||
factory User.fromMap(Map data) => new User(
|
|
||||||
id: data['id'],
|
|
||||||
email: data['email'],
|
|
||||||
username: data['username'],
|
|
||||||
password: data['password'],
|
|
||||||
roles: data['roles']);
|
|
||||||
|
|
||||||
Map toJson() {
|
|
||||||
return {
|
|
||||||
'id': id,
|
|
||||||
'email': email,
|
|
||||||
'username': username,
|
|
||||||
'password': password,
|
|
||||||
'roles': roles
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,10 @@ dependencies:
|
||||||
mailer: ^1.1.0+4
|
mailer: ^1.1.0+4
|
||||||
validate: ^1.5.2
|
validate: ^1.5.2
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
build_runner: ^0.1.1
|
||||||
grinder: ^0.8.0+2
|
grinder: ^0.8.0+2
|
||||||
http: ^0.11.3
|
http: ^0.11.3
|
||||||
|
source_gen: ^0.5.2
|
||||||
test: ^0.12.13
|
test: ^0.12.13
|
||||||
transformers:
|
transformers:
|
||||||
- angel_configuration
|
- angel_configuration
|
||||||
|
|
4
tool/build.dart
Normal file
4
tool/build.dart
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import 'package:build_runner/build_runner.dart';
|
||||||
|
import 'phases.dart';
|
||||||
|
|
||||||
|
main() => build(PHASES, deleteFilesByDefault: true);
|
12
tool/phases.dart
Normal file
12
tool/phases.dart
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import 'package:build_runner/build_runner.dart';
|
||||||
|
import 'package:source_gen/builder.dart';
|
||||||
|
import 'package:source_gen/generators/json_serializable_generator.dart';
|
||||||
|
|
||||||
|
final PhaseGroup PHASES = new PhaseGroup.singleAction(
|
||||||
|
new GeneratorBuilder(const [const JsonSerializableGenerator()]),
|
||||||
|
new InputSet('angel', const [
|
||||||
|
'bin/**/*.dart',
|
||||||
|
'lib/**/*.dart',
|
||||||
|
'views/**/*.dart',
|
||||||
|
'web/**/*.dart'
|
||||||
|
]));
|
4
tool/watch.dart
Normal file
4
tool/watch.dart
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import 'package:build_runner/build_runner.dart';
|
||||||
|
import 'phases.dart';
|
||||||
|
|
||||||
|
main() => watch(PHASES, deleteFilesByDefault: true);
|
Loading…
Reference in a new issue