From 5b6a4b66dd036dc1bab55e17a5aba8aa3446c95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88hm?= Date: Wed, 29 May 2013 20:12:51 +0200 Subject: [PATCH] refactor(service-generator): fix break in Angular-Sub-Generator API of service-generator, remove argument --type and create own generators for each type --- constant/USAGE | 9 +++++++++ constant/index.js | 20 ++++++++++++++++++++ factory/USAGE | 9 +++++++++ factory/index.js | 20 ++++++++++++++++++++ provider/USAGE | 9 +++++++++ provider/index.js | 20 ++++++++++++++++++++ service/index.js | 21 +-------------------- value/USAGE | 9 +++++++++ value/index.js | 20 ++++++++++++++++++++ 9 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 constant/USAGE create mode 100644 constant/index.js create mode 100644 factory/USAGE create mode 100644 factory/index.js create mode 100644 provider/USAGE create mode 100644 provider/index.js create mode 100644 value/USAGE create mode 100644 value/index.js diff --git a/constant/USAGE b/constant/USAGE new file mode 100644 index 000000000..2daf53a57 --- /dev/null +++ b/constant/USAGE @@ -0,0 +1,9 @@ +Description: + Creates a new AngularJS service. + Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services + +Example: + yo angular:constant thing [--coffee] [--minsafe] + + This will create: + app/scripts/services/thing.js diff --git a/constant/index.js b/constant/index.js new file mode 100644 index 000000000..44abcd031 --- /dev/null +++ b/constant/index.js @@ -0,0 +1,20 @@ +'use strict'; +var path = require('path'); +var util = require('util'); +var ScriptBase = require('../script-base.js'); +var angularUtils = require('../util.js'); + + +module.exports = Generator; + +function Generator() { + ScriptBase.apply(this, arguments); +} + +util.inherits(Generator, ScriptBase); + +Generator.prototype.createServiceFiles = function createServiceFiles() { + this.appTemplate('service/constant', 'scripts/services/' + this.name); + this.testTemplate('spec/service', 'services/' + this.name); + this.addScriptToIndex('services/' + this.name); +}; diff --git a/factory/USAGE b/factory/USAGE new file mode 100644 index 000000000..9bc3f0ecb --- /dev/null +++ b/factory/USAGE @@ -0,0 +1,9 @@ +Description: + Creates a new AngularJS service. + Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services + +Example: + yo angular:factory thing [--coffee] [--minsafe] + + This will create: + app/scripts/services/thing.js diff --git a/factory/index.js b/factory/index.js new file mode 100644 index 000000000..959ace579 --- /dev/null +++ b/factory/index.js @@ -0,0 +1,20 @@ +'use strict'; +var path = require('path'); +var util = require('util'); +var ScriptBase = require('../script-base.js'); +var angularUtils = require('../util.js'); + + +module.exports = Generator; + +function Generator() { + ScriptBase.apply(this, arguments); +} + +util.inherits(Generator, ScriptBase); + +Generator.prototype.createServiceFiles = function createServiceFiles() { + this.appTemplate('service/factory', 'scripts/services/' + this.name); + this.testTemplate('spec/service', 'services/' + this.name); + this.addScriptToIndex('services/' + this.name); +}; diff --git a/provider/USAGE b/provider/USAGE new file mode 100644 index 000000000..40fa37064 --- /dev/null +++ b/provider/USAGE @@ -0,0 +1,9 @@ +Description: + Creates a new AngularJS service. + Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services + +Example: + yo angular:provider thing [--coffee] [--minsafe] + + This will create: + app/scripts/services/thing.js diff --git a/provider/index.js b/provider/index.js new file mode 100644 index 000000000..5deb351ed --- /dev/null +++ b/provider/index.js @@ -0,0 +1,20 @@ +'use strict'; +var path = require('path'); +var util = require('util'); +var ScriptBase = require('../script-base.js'); +var angularUtils = require('../util.js'); + + +module.exports = Generator; + +function Generator() { + ScriptBase.apply(this, arguments); +} + +util.inherits(Generator, ScriptBase); + +Generator.prototype.createServiceFiles = function createServiceFiles() { + this.appTemplate('service/provider', 'scripts/services/' + this.name); + this.testTemplate('spec/service', 'services/' + this.name); + this.addScriptToIndex('services/' + this.name); +}; diff --git a/service/index.js b/service/index.js index 0b6ac302e..a539329fb 100644 --- a/service/index.js +++ b/service/index.js @@ -9,31 +9,12 @@ module.exports = Generator; function Generator() { ScriptBase.apply(this, arguments); - - var allowedTypes = [ - 'constant', - 'factory', - 'provider', - 'service', - 'value' - ]; - - this.argument('type', { - type: String, - defaults: 'factory', - banner: '[type]', - required: false - }); - - if (allowedTypes.indexOf(this.type) === -1) { - this.type = 'factory'; - } } util.inherits(Generator, ScriptBase); Generator.prototype.createServiceFiles = function createServiceFiles() { - this.appTemplate(path.join('service', this.type), 'scripts/services/' + this.name); + this.appTemplate('service/service', 'scripts/services/' + this.name); this.testTemplate('spec/service', 'services/' + this.name); this.addScriptToIndex('services/' + this.name); }; diff --git a/value/USAGE b/value/USAGE new file mode 100644 index 000000000..27aeca0cf --- /dev/null +++ b/value/USAGE @@ -0,0 +1,9 @@ +Description: + Creates a new AngularJS service. + Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services + +Example: + yo angular:value thing [--coffee] [--minsafe] + + This will create: + app/scripts/services/thing.js diff --git a/value/index.js b/value/index.js new file mode 100644 index 000000000..44abcd031 --- /dev/null +++ b/value/index.js @@ -0,0 +1,20 @@ +'use strict'; +var path = require('path'); +var util = require('util'); +var ScriptBase = require('../script-base.js'); +var angularUtils = require('../util.js'); + + +module.exports = Generator; + +function Generator() { + ScriptBase.apply(this, arguments); +} + +util.inherits(Generator, ScriptBase); + +Generator.prototype.createServiceFiles = function createServiceFiles() { + this.appTemplate('service/constant', 'scripts/services/' + this.name); + this.testTemplate('spec/service', 'services/' + this.name); + this.addScriptToIndex('services/' + this.name); +};