This commit is contained in:
thosakwe 2017-03-01 22:31:00 -05:00
parent 6cd3b65a0c
commit 1db250ca16
3 changed files with 16 additions and 11 deletions

View file

@ -3,6 +3,7 @@ import 'package:args/command_runner.dart';
import 'package:code_builder/code_builder.dart'; import 'package:code_builder/code_builder.dart';
import 'package:console/console.dart'; import 'package:console/console.dart';
import 'package:inflection/inflection.dart'; import 'package:inflection/inflection.dart';
import 'package:pubspec/pubspec.dart';
import 'package:recase/recase.dart'; import 'package:recase/recase.dart';
import 'service_generators/service_generators.dart'; import 'service_generators/service_generators.dart';
import 'init.dart' show preBuild; import 'init.dart' show preBuild;
@ -25,6 +26,7 @@ class ServiceCommand extends Command {
@override @override
run() async { run() async {
var pubspec = await PubSpec.load(Directory.current);
var name = await readInput('Name of Service (not plural): '); var name = await readInput('Name of Service (not plural): ');
var chooser = new Chooser<String>( var chooser = new Chooser<String>(
GENERATORS.map<String>((g) => g.name).toList(), GENERATORS.map<String>((g) => g.name).toList(),
@ -102,7 +104,7 @@ class ServiceCommand extends Command {
export '../models/$lower.dart'; export '../models/$lower.dart';
*/ */
lib.addMember( lib.addMember(
new ImportBuilder('package:angel_framework/angel_framework.dart')); new ImportBuilder('package:angel_common/angel_common.dart'));
generator.applyToLibrary(lib, name, lower); generator.applyToLibrary(lib, name, lower);
if (generator.createsModel == true) { if (generator.createsModel == true) {
@ -180,8 +182,14 @@ class $name extends Model {
await file.writeAsString(''' await file.writeAsString('''
import 'package:angel_validate/angel_validate.dart'; import 'package:angel_validate/angel_validate.dart';
final Validator CREATE_$constantCase = final Validator $constantCase = new Validator({
new Validator({'name*': isString, 'desc*': isString}); 'name': [isString, isNotEmpty],
'desc': [isString, isNotEmpty]
});
final Validator CREATE_$constantCase = $constantCase.extend({})
..requiredFields.addAll(['name', 'desc']);
''' '''
.trim()); .trim());
} }
@ -198,11 +206,11 @@ final Validator CREATE_$constantCase =
.trim(); .trim();
} }
_generateTests(String lower, String type) { _generateTests(PubSpec pubspec, String lower, String type) {
return ''' return '''
import 'dart:io'; import 'dart:io';
import 'package:angel/angel.dart'; import 'package:${pubspec.name}/${pubspec.name}.dart';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel_common/angel_common.dart';
import 'package:angel_test/angel_test.dart'; import 'package:angel_test/angel_test.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';

View file

@ -13,10 +13,7 @@ class MongoServiceGenerator extends ServiceGenerator {
@override @override
void applyToLibrary(LibraryBuilder library, String name, String lower) { void applyToLibrary(LibraryBuilder library, String name, String lower) {
library.addMembers([ library.addMember(new ImportBuilder('package:mongo_dart/mongo_dart.dart'));
'package:angel_mongo/angel_mongo.dart',
'package:mongo_dart/mongo_dart.dart'
].map((str) => new ImportBuilder(str)));
} }
@override @override

View file

@ -2,7 +2,7 @@ author: "Tobe O <thosakwe@gmail.com>"
description: "Command-line tools for the Angel framework." description: "Command-line tools for the Angel framework."
homepage: "https://github.com/angel-dart/angel_cli" homepage: "https://github.com/angel-dart/angel_cli"
name: "angel_cli" name: "angel_cli"
version: "1.0.2" version: "1.0.3"
dependencies: dependencies:
analyzer: "^0.29.0" analyzer: "^0.29.0"
args: "^0.13.7" args: "^0.13.7"