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...");
_pen();
await _pubGet(projectDir);
await _preBuild(projectDir);
var secret = rs.randomAlphaNumeric(32);
print('Generated new JWT secret: $secret');
await _key.changeSecret(
@ -59,8 +60,8 @@ class InitCommand extends Command {
projectDir.absolute.path
]);
git.stdout.transform(UTF8.decoder).listen(stdout.write);
git.stderr.transform(UTF8.decoder).listen(stderr.write);
stdout.addStream(git.stdout);
stderr.addStream(git.stderr);
if (await git.exitCode != 0) {
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 {
var pub = await Process.start("pub", ["get"],
workingDirectory: projectDir.absolute.path);
pub.stdout.pipe(stdout);
pub.stderr.pipe(stderr);
stdout.addStream(pub.stdout);
stderr.addStream(pub.stderr);
var code = await pub.exitCode;
print("Pub process exited with code $code");
}

View file

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

View file

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