diff --git a/lib/src/commands/make/service.dart b/lib/src/commands/make/service.dart index e1a742a..72b2b3b 100644 --- a/lib/src/commands/make/service.dart +++ b/lib/src/commands/make/service.dart @@ -85,7 +85,7 @@ class ServiceCommand extends Command { configureServer.body = new Block((block) { generator.applyToConfigureServer( - configureServer, block, name, rc.snakeCase); + serviceLib, configureServer, block, name, rc.snakeCase); // return (Angel app) async {} var closure = new Method((closure) { @@ -95,11 +95,11 @@ class ServiceCommand extends Command { ..name = 'app' ..type = refer('Angel'))); closure.body = new Block((block) { - generator.beforeService(block, name, rc.snakeCase); + generator.beforeService(serviceLib, block, name, rc.snakeCase); // app.use('/api/todos', new MapService()); - var service = - generator.createInstance(closure, name, rc.snakeCase); + var service = generator.createInstance( + serviceLib, closure, name, rc.snakeCase); if (argResults['typed'] as bool) { var tb = new TypeReference((b) => b diff --git a/lib/src/commands/service_generators/custom.dart b/lib/src/commands/service_generators/custom.dart index a1de5f3..d413460 100644 --- a/lib/src/commands/service_generators/custom.dart +++ b/lib/src/commands/service_generators/custom.dart @@ -20,8 +20,8 @@ class CustomServiceGenerator extends ServiceGenerator { } @override - Expression createInstance( - MethodBuilder methodBuilder, String name, String lower) { + Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder, + String name, String lower) { return refer('${name}Service').newInstance([]); } } diff --git a/lib/src/commands/service_generators/file_service.dart b/lib/src/commands/service_generators/file_service.dart index 7ff5457..278562d 100644 --- a/lib/src/commands/service_generators/file_service.dart +++ b/lib/src/commands/service_generators/file_service.dart @@ -14,8 +14,12 @@ class FileServiceGenerator extends ServiceGenerator { bool get goesFirst => true; @override - void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block, - String name, String lower) { + void applyToConfigureServer( + LibraryBuilder library, + MethodBuilder configureServer, + BlockBuilder block, + String name, + String lower) { configureServer.requiredParameters.add(new Parameter((b) => b ..name = 'dbDirectory' ..type = refer('Directory'))); @@ -26,13 +30,15 @@ class FileServiceGenerator extends ServiceGenerator { library.directives.addAll([ new Directive.import( 'package:angel_file_service/angel_file_service.dart'), - new Directive.import('package:file/file.dart'), ]); } @override - Expression createInstance( - MethodBuilder methodBuilder, String name, String lower) { + Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder, + String name, String lower) { + library.directives.addAll([ + new Directive.import('package:file/file.dart'), + ]); return refer('JsonFileService').newInstance([ refer('dbDirectory') .property('childFile') diff --git a/lib/src/commands/service_generators/generator.dart b/lib/src/commands/service_generators/generator.dart index 43b573f..6328958 100644 --- a/lib/src/commands/service_generators/generator.dart +++ b/lib/src/commands/service_generators/generator.dart @@ -27,13 +27,18 @@ class ServiceGenerator { void applyToLibrary(LibraryBuilder library, String name, String lower) {} - void beforeService(BlockBuilder builder, String name, String lower) {} + void beforeService(LibraryBuilder library, BlockBuilder builder, String name, + String lower) {} - void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block, - String name, String lower) {} + void applyToConfigureServer( + LibraryBuilder library, + MethodBuilder configureServer, + BlockBuilder block, + String name, + String lower) {} - Expression createInstance( - MethodBuilder methodBuilder, String name, String lower) => + Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder, + String name, String lower) => literal(null); @override diff --git a/lib/src/commands/service_generators/map.dart b/lib/src/commands/service_generators/map.dart index 4b1dec7..545961d 100644 --- a/lib/src/commands/service_generators/map.dart +++ b/lib/src/commands/service_generators/map.dart @@ -8,8 +8,8 @@ class MapServiceGenerator extends ServiceGenerator { bool get createsModel => false; @override - Expression createInstance( - MethodBuilder methodBuilder, String name, String lower) { + Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder, + String name, String lower) { return refer('MapService').newInstance([]); } } diff --git a/lib/src/commands/service_generators/mongo.dart b/lib/src/commands/service_generators/mongo.dart index f6b7044..9386f28 100644 --- a/lib/src/commands/service_generators/mongo.dart +++ b/lib/src/commands/service_generators/mongo.dart @@ -14,8 +14,12 @@ class MongoServiceGenerator extends ServiceGenerator { bool get createsModel => false; @override - void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block, - String name, String lower) { + void applyToConfigureServer( + LibraryBuilder library, + MethodBuilder configureServer, + BlockBuilder block, + String name, + String lower) { configureServer.requiredParameters.add(new Parameter((b) => b ..name = 'db' ..type = refer('Db'))); @@ -30,8 +34,8 @@ class MongoServiceGenerator extends ServiceGenerator { } @override - Expression createInstance( - MethodBuilder methodBuilder, String name, String lower) { + Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder, + String name, String lower) { return refer('MongoService').newInstance([ refer('db').property('collection').call([literal(pluralize(lower))]) ]); diff --git a/lib/src/commands/service_generators/rethink.dart b/lib/src/commands/service_generators/rethink.dart index dced10e..f36e7f1 100644 --- a/lib/src/commands/service_generators/rethink.dart +++ b/lib/src/commands/service_generators/rethink.dart @@ -14,8 +14,12 @@ class RethinkServiceGenerator extends ServiceGenerator { bool get createsModel => false; @override - void applyToConfigureServer(MethodBuilder configureServer, BlockBuilder block, - String name, String lower) { + void applyToConfigureServer( + LibraryBuilder library, + MethodBuilder configureServer, + BlockBuilder block, + String name, + String lower) { configureServer.requiredParameters.addAll([ new Parameter((b) => b ..name = 'connection' @@ -35,8 +39,8 @@ class RethinkServiceGenerator extends ServiceGenerator { } @override - Expression createInstance( - MethodBuilder methodBuilder, String name, String lower) { + Expression createInstance(LibraryBuilder library, MethodBuilder methodBuilder, + String name, String lower) { return refer('RethinkService').newInstance([ refer('connection'), refer('r').property('table').call([literal(pluralize(lower))])