This commit is contained in:
thosakwe 2016-12-31 11:39:00 -05:00
parent f9554a176d
commit 994a4cf97b
3 changed files with 55 additions and 41 deletions

View file

@ -29,6 +29,7 @@ class InitCommand extends Command {
"${Icon.CHECKMARK} Successfully initialized Angel project. Now running pub get..."); "${Icon.CHECKMARK} Successfully initialized Angel project. Now running pub get...");
_pen(); _pen();
await _pubGet(projectDir); await _pubGet(projectDir);
await _preBuild(projectDir);
var secret = rs.randomAlphaNumeric(32); var secret = rs.randomAlphaNumeric(32);
print('Generated new JWT secret: $secret'); print('Generated new JWT secret: $secret');
await _key.changeSecret( await _key.changeSecret(
@ -59,8 +60,8 @@ class InitCommand extends Command {
projectDir.absolute.path projectDir.absolute.path
]); ]);
git.stdout.transform(UTF8.decoder).listen(stdout.write); stdout.addStream(git.stdout);
git.stderr.transform(UTF8.decoder).listen(stderr.write); stderr.addStream(git.stderr);
if (await git.exitCode != 0) { if (await git.exitCode != 0) {
throw new Exception("Could not clone repo."); throw new Exception("Could not clone repo.");
@ -78,11 +79,24 @@ class InitCommand extends Command {
} }
} }
_preBuild(Directory projectDir) async {
// Run build
var build = await Process.start(Platform.executable, ['tool/build.dart'],
workingDirectory: projectDir.absolute.path);
stdout.addStream(build.stdout);
stderr.addStream(build.stderr);
var buildCode = await build.exitCode;
if (buildCode != 0) throw new Exception('Failed to pre-build resources.');
}
_pubGet(Directory projectDir) async { _pubGet(Directory projectDir) async {
var pub = await Process.start("pub", ["get"], var pub = await Process.start("pub", ["get"],
workingDirectory: projectDir.absolute.path); workingDirectory: projectDir.absolute.path);
pub.stdout.pipe(stdout); stdout.addStream(pub.stdout);
pub.stderr.pipe(stderr); stderr.addStream(pub.stderr);
var code = await pub.exitCode; var code = await pub.exitCode;
print("Pub process exited with code $code"); print("Pub process exited with code $code");
} }

View file

@ -36,12 +36,12 @@ class ServiceCommand extends Command {
if (type == MONGO) { if (type == MONGO) {
serviceSource = _generateMongoService(name); serviceSource = _generateMongoService(name);
await _generateMemoryModel(name);
} else if (type == MONGO_TYPED) { } else if (type == MONGO_TYPED) {
serviceSource = _generateMongoTypedService(name); serviceSource = _generateMongoTypedService(name);
await _generateMongoModel(name); await _generateMongoModel(name);
} else if (type == MEMORY) { } else if (type == MEMORY) {
serviceSource = _generateMemoryService(name); serviceSource = _generateMemoryService(name);
await _generateMemoryModel(name);
} else if (type == CUSTOM) { } else if (type == CUSTOM) {
serviceSource = _generateCustomService(name); serviceSource = _generateCustomService(name);
} else if (type == TRESTLE) { } else if (type == TRESTLE) {
@ -113,28 +113,23 @@ library angel.models.$lower;
import 'dart:convert'; import 'dart:convert';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:source_gen/generators/json_serializable.dart';
class $name extends MemoryModel { part '$lower.g.dart';
String name, desc;
@JsonSerializable()
class $name extends MemoryModel with _\$${name}SerializerMixin {
@JsonKey('name')
String name;
@JsonKey('desc')
String desc;
factory $name.fromJson(Map json) => _\$${name}fromJson(json);
$name({String id, this.name, this.desc}) { $name({String id, this.name, this.desc}) {
this.id = id; this.id = id;
} }
factory $name.fromJson(String json) => new $name.fromMap(JSON.decode(json));
factory $name.fromMap(Map data) => new $name(
id: data['id'],
name: data['name'],
desc: data['desc']);
Map toJson() {
return {
'id': id,
'name': name,
'desc': desc
};
}
} }
''' '''
.trim()); .trim());
@ -169,28 +164,23 @@ library angel.models.$lower;
import 'dart:convert'; import 'dart:convert';
import 'package:angel_mongo/model.dart'; import 'package:angel_mongo/model.dart';
import 'package:source_gen/generators/json_serializable.dart';
class $name extends Model { part '$lower.g.dart';
String name, desc;
@JsonSerializable()
class $name extends Model with _\$${name}SerializerMixin {
@JsonKey('name')
String name;
@JsonKey('desc')
String desc;
factory $name.fromJson(Map json) => _\$${name}fromJson(json);
$name({String id, this.name, this.desc}) { $name({String id, this.name, this.desc}) {
this.id = id; this.id = id;
} }
factory $name.fromJson(String json) => new $name.fromMap(JSON.decode(json));
factory $name.fromMap(Map data) => new $name(
id: data['id'],
name: data['name'],
desc: data['desc']);
Map toJson() {
return {
'id': id,
'name': name,
'desc': desc
};
}
} }
''' '''
.trim()); .trim());
@ -202,14 +192,24 @@ class $name extends Model {
return ''' return '''
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_framework/angel_framework.dart';
import 'package:angel_mongo/angel_mongo.dart'; import 'package:angel_mongo/angel_mongo.dart';
import 'package:angel_validate/angel_validate.dart';
import 'package:mongo_dart/mongo_dart.dart'; import 'package:mongo_dart/mongo_dart.dart';
final Validator ${lower}Schema = new Validator({
'name*': [isString, isNotEmpty],
'desc*': [isString, isNotEmpty]
});
configureServer(Db db) { configureServer(Db db) {
return (Angel app) async { return (Angel app) async {
app.use('/api/${lower}s', new ${name}Service(db.collection('${lower}s'))); app.use('/api/${lower}s', new ${name}Service(db.collection('${lower}s')));
HookedService service = app.service('api/${lower}s'); HookedService service = app.service('api/${lower}s');
app.container.singleton(service.inner); app.container.singleton(service.inner);
service
..beforeCreate.listen(validateEvent(${lower}Schema))
..beforeUpdate.listen(validateEvent(${lower}Schema));
}; };
} }
@ -282,7 +282,7 @@ main() async {
setUp(() async { setUp(() async {
app = await createServer(); app = await createServer();
client = await connectTo(app; client = await connectTo(app);
}); });
tearDown(() async { tearDown(() async {

View file

@ -1,5 +1,5 @@
name: angel_cli name: angel_cli
version: 1.0.0-dev+15 version: 1.0.0-dev+16
description: Command-line tools for the Angel framework. description: Command-line tools for the Angel framework.
environment: environment:
sdk: ">=1.19.0" sdk: ">=1.19.0"