Skip to content

Commit 5b6a4b6

Browse files
robinboehmbtford
authored andcommitted
refactor(service-generator): fix break in Angular-Sub-Generator API of service-generator, remove argument --type and create own generators for each type
1 parent 54edc9d commit 5b6a4b6

File tree

9 files changed

+117
-20
lines changed

9 files changed

+117
-20
lines changed

constant/USAGE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Description:
2+
Creates a new AngularJS service.
3+
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services
4+
5+
Example:
6+
yo angular:constant thing [--coffee] [--minsafe]
7+
8+
This will create:
9+
app/scripts/services/thing.js

constant/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
var path = require('path');
3+
var util = require('util');
4+
var ScriptBase = require('../script-base.js');
5+
var angularUtils = require('../util.js');
6+
7+
8+
module.exports = Generator;
9+
10+
function Generator() {
11+
ScriptBase.apply(this, arguments);
12+
}
13+
14+
util.inherits(Generator, ScriptBase);
15+
16+
Generator.prototype.createServiceFiles = function createServiceFiles() {
17+
this.appTemplate('service/constant', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
20+
};

factory/USAGE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Description:
2+
Creates a new AngularJS service.
3+
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services
4+
5+
Example:
6+
yo angular:factory thing [--coffee] [--minsafe]
7+
8+
This will create:
9+
app/scripts/services/thing.js

factory/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
var path = require('path');
3+
var util = require('util');
4+
var ScriptBase = require('../script-base.js');
5+
var angularUtils = require('../util.js');
6+
7+
8+
module.exports = Generator;
9+
10+
function Generator() {
11+
ScriptBase.apply(this, arguments);
12+
}
13+
14+
util.inherits(Generator, ScriptBase);
15+
16+
Generator.prototype.createServiceFiles = function createServiceFiles() {
17+
this.appTemplate('service/factory', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
20+
};

provider/USAGE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Description:
2+
Creates a new AngularJS service.
3+
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services
4+
5+
Example:
6+
yo angular:provider thing [--coffee] [--minsafe]
7+
8+
This will create:
9+
app/scripts/services/thing.js

provider/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
var path = require('path');
3+
var util = require('util');
4+
var ScriptBase = require('../script-base.js');
5+
var angularUtils = require('../util.js');
6+
7+
8+
module.exports = Generator;
9+
10+
function Generator() {
11+
ScriptBase.apply(this, arguments);
12+
}
13+
14+
util.inherits(Generator, ScriptBase);
15+
16+
Generator.prototype.createServiceFiles = function createServiceFiles() {
17+
this.appTemplate('service/provider', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
20+
};

service/index.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,12 @@ module.exports = Generator;
99

1010
function Generator() {
1111
ScriptBase.apply(this, arguments);
12-
13-
var allowedTypes = [
14-
'constant',
15-
'factory',
16-
'provider',
17-
'service',
18-
'value'
19-
];
20-
21-
this.argument('type', {
22-
type: String,
23-
defaults: 'factory',
24-
banner: '[type]',
25-
required: false
26-
});
27-
28-
if (allowedTypes.indexOf(this.type) === -1) {
29-
this.type = 'factory';
30-
}
3112
}
3213

3314
util.inherits(Generator, ScriptBase);
3415

3516
Generator.prototype.createServiceFiles = function createServiceFiles() {
36-
this.appTemplate(path.join('service', this.type), 'scripts/services/' + this.name);
17+
this.appTemplate('service/service', 'scripts/services/' + this.name);
3718
this.testTemplate('spec/service', 'services/' + this.name);
3819
this.addScriptToIndex('services/' + this.name);
3920
};

value/USAGE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Description:
2+
Creates a new AngularJS service.
3+
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services
4+
5+
Example:
6+
yo angular:value thing [--coffee] [--minsafe]
7+
8+
This will create:
9+
app/scripts/services/thing.js

value/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
var path = require('path');
3+
var util = require('util');
4+
var ScriptBase = require('../script-base.js');
5+
var angularUtils = require('../util.js');
6+
7+
8+
module.exports = Generator;
9+
10+
function Generator() {
11+
ScriptBase.apply(this, arguments);
12+
}
13+
14+
util.inherits(Generator, ScriptBase);
15+
16+
Generator.prototype.createServiceFiles = function createServiceFiles() {
17+
this.appTemplate('service/constant', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
20+
};

0 commit comments

Comments
 (0)