Skip to content

Commit f84429d

Browse files
author
Cristian Escudero
committed
Added services/directives scaffolding feature.
Summary: Renamed folders for consistency. Creation of the initial sample files for scaffolding. Added missing parenthesis. Added modification in README to include the new feature. Depends on D12359. Test Plan: Created a test project, run generators and the outcome went as expected. Reviewers: jmsotuyo Reviewed By: jmsotuyo Subscribers: mbmihura Differential Revision: http://ph.monits.com/D12362
1 parent 01c1ccc commit f84429d

File tree

6 files changed

+152
-5
lines changed

6 files changed

+152
-5
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ Finally, initiate the generator:
4747
```bash
4848
yo angular-require-fullstack
4949
```
50-
It will guide you from there
50+
It will guide you from there.
51+
52+
Also, you can create your own services/directives/controllers using our templates by doing:
53+
54+
```bash
55+
yo angular-require-fullstack:whatiwant
56+
```
57+
58+
Replace `whatiwant` with the word `controller`, `service` or `directive` as you need. The rest is straightforward.
5159

5260
### Getting To Know Yeoman
5361

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
define(['<%= appname %>'], function(<%= appname %>) {
22

3-
'use strict';
4-
<%= appname %>.controller('<%= controllerName %>', function($scope) {
5-
6-
});
3+
'use strict';
4+
<%= appname %>.controller('<%= controllerName %>', function($scope) {
5+
6+
});
77

88
});

directive/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
var yeoman = require('yeoman-generator');
3+
var chalk = require('chalk');
4+
var yosay = require('yosay');
5+
6+
module.exports = yeoman.generators.Base.extend({
7+
initializing: function () {
8+
this.pkg = require('../package.json');
9+
10+
},
11+
constructor: function () {
12+
yeoman.generators.Base.apply(this, arguments);
13+
},
14+
15+
prompting: function () {
16+
var done = this.async();
17+
18+
// Have Yeoman greet the user.
19+
this.log(yosay(
20+
'Welcome to the brilliant ' + chalk.red('AngularRequireFullstack') + ' generator! by ' + chalk.blue('MONITS')
21+
));
22+
23+
this.log(
24+
'I am going to scaffold a directive for you.'
25+
);
26+
27+
var prompts = [{
28+
type: 'input',
29+
name: 'directiveName',
30+
message: 'Directive name:',
31+
default: this.appname
32+
}];
33+
34+
this.prompt(prompts, function (props) {
35+
this.props = props;
36+
37+
this.directiveName = this.props.directiveName;
38+
// To access props later use this.props.someOption;
39+
40+
done();
41+
}.bind(this));
42+
},
43+
44+
writing: {
45+
directive: function () {
46+
// Directives
47+
this.fs.copyTpl(
48+
this.templatePath('/_directiveTemplate.js'),
49+
this.destinationPath('/app/scripts/directives/' + this.directiveName + '.js'),
50+
this
51+
);
52+
53+
}
54+
},
55+
56+
end: function () {
57+
this.log('Run ' + chalk.red('grunt serve') + ' to see the app in action or ' + chalk.blue('grunt build') + ' when you are ready to deploy it');
58+
this.log('Visit our blog at ' + chalk.blue('https://medium.com/monits-blog'));
59+
}
60+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define(['<%= appname %>'], function(<%= appname %>) {
2+
3+
'use strict';
4+
<%= appname %>.directive('<%= directiveName %>', function() {
5+
return {
6+
restrict: 'E',
7+
template: '<span>Sample</span>'
8+
}
9+
});
10+
11+
});

service/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
var yeoman = require('yeoman-generator');
3+
var chalk = require('chalk');
4+
var yosay = require('yosay');
5+
6+
module.exports = yeoman.generators.Base.extend({
7+
initializing: function () {
8+
this.pkg = require('../package.json');
9+
10+
},
11+
constructor: function () {
12+
yeoman.generators.Base.apply(this, arguments);
13+
},
14+
15+
prompting: function () {
16+
var done = this.async();
17+
18+
// Have Yeoman greet the user.
19+
this.log(yosay(
20+
'Welcome to the brilliant ' + chalk.red('AngularRequireFullstack') + ' generator! by ' + chalk.blue('MONITS')
21+
));
22+
23+
this.log(
24+
'I am going to scaffold a service for you.'
25+
);
26+
27+
var prompts = [{
28+
type: 'input',
29+
name: 'serviceName',
30+
message: 'Service name:',
31+
default: this.appname
32+
}];
33+
34+
this.prompt(prompts, function (props) {
35+
this.props = props;
36+
37+
this.serviceName = this.props.serviceName;
38+
// To access props later use this.props.someOption;
39+
40+
done();
41+
}.bind(this));
42+
},
43+
44+
writing: {
45+
service: function () {
46+
// Services
47+
this.fs.copyTpl(
48+
this.templatePath('/_serviceTemplate.js'),
49+
this.destinationPath('/app/scripts/services/' + this.serviceName + '.js'),
50+
this
51+
);
52+
53+
}
54+
},
55+
56+
end: function () {
57+
this.log('Run ' + chalk.red('grunt serve') + ' to see the app in action or ' + chalk.blue('grunt build') + ' when you are ready to deploy it');
58+
this.log('Visit our blog at ' + chalk.blue('https://medium.com/monits-blog'));
59+
}
60+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define(['<%= appname %>'], function(<%= appname %>) {
2+
3+
'use strict';
4+
<%= appname %>.service('<%= serviceName %>', function() {
5+
6+
});
7+
8+
});

0 commit comments

Comments
 (0)