Skip to content

Commit e9d5cb9

Browse files
committed
Subgenerators added for component, container, reducer, and action.
1 parent da82ae3 commit e9d5cb9

17 files changed

Lines changed: 409 additions & 0 deletions

File tree

generators/action/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
var yeoman = require('yeoman-generator');
3+
4+
module.exports = yeoman.generators.Base.extend({
5+
initializing: function () {
6+
this.argument('name', {
7+
required: true,
8+
type: String,
9+
desc: 'The subgenerator name'
10+
});
11+
12+
this.log('You called the WebpackReduxReact subgenerator with the argument ' + this.name + '.');
13+
},
14+
15+
writing: function () {
16+
this.fs.copy(
17+
this.templatePath('somefile.js'),
18+
this.destinationPath('somefile.js')
19+
);
20+
}
21+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// This is a file copied by your subgenerator

generators/component/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
var yeoman = require('yeoman-generator');
3+
var _ = require('lodash');
4+
5+
module.exports = yeoman.generators.Base.extend({
6+
initializing: function () {
7+
this.argument('name', {
8+
required: true,
9+
type: String,
10+
desc: 'The subgenerator name'
11+
});
12+
13+
this.log('You called the Component subgenerator with the argument ' + this.name + '.');
14+
},
15+
prompting: function () {
16+
var done = this.async();
17+
18+
var prompts = [{
19+
type: 'confirm',
20+
name: 'addStyle',
21+
message: 'Do you want to include an SCSS file for styles?',
22+
default: true
23+
}];
24+
25+
this.prompt(prompts, function (props) {
26+
this.props = props;
27+
// To access props later use this.props.someOption;
28+
done();
29+
}.bind(this));
30+
},
31+
writing: function () {
32+
if(this.props.addStyle){
33+
this.template('_style.js', 'components/'+ this.name + '/' + this.name + '.js', this.templateContext);
34+
this.template('_main.scss', 'components/'+ this.name + '/' + this.name + '.scss', this.templateContext);
35+
} else {
36+
this.template('_noStyle.js', 'components/'+ this.name + '/' + this.name + '.js', this.templateContext);
37+
}
38+
}
39+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.<%= name %> {
2+
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, {Component, PropTypes} from 'react';
2+
3+
class <%= name %> extends Component {
4+
constructor(props){
5+
super(props);
6+
}
7+
render(){
8+
return (
9+
<div>
10+
11+
</div>
12+
);
13+
}
14+
}
15+
16+
export default <%= name %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, {Component, PropTypes} from 'react';
2+
import './<%= name %>.scss';
3+
4+
class <%= name %> extends Component {
5+
constructor(props){
6+
super(props);
7+
}
8+
render(){
9+
return (
10+
<div className="<%= name %>">
11+
12+
</div>
13+
);
14+
}
15+
}
16+
17+
export default <%= name %>

generators/container/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
var yeoman = require('yeoman-generator');
3+
var _ = require('lodash');
4+
var chalk = require('chalk');
5+
6+
module.exports = yeoman.generators.Base.extend({
7+
initializing: function () {
8+
this.argument('name', {
9+
required: true,
10+
type: String,
11+
desc: 'The subgenerator name'
12+
});
13+
this.capsName = _.capitalize(this.name);
14+
this.camelName = this.name.toLowerCase().charAt(0).toUpperCase().slice(1); //Capitalize first letter only
15+
// this.log('You called the Component subgenerator with the argument ' + this.name + '.');
16+
},
17+
prompting: function () {
18+
var done = this.async();
19+
20+
var prompts = [{
21+
type: 'confirm',
22+
name: 'addAction',
23+
message: 'Do you want to create an action file for this component?\n' + chalk.red('WARNING:This will overwrite an existing action file of the same name.') + '\n',
24+
default: false
25+
}];
26+
27+
this.prompt(prompts, function (props) {
28+
this.props = props;
29+
// To access props later use this.props.someOption;
30+
done();
31+
}.bind(this));
32+
},
33+
writing: function () {
34+
if(this.props.addAction){
35+
this.template('_action.js', 'actions/' + this.name.toLowerCase() + '.js', this.templateContext);
36+
}
37+
this.template('_main.js', 'containers/'+ this.name + '/' + this.name + '.js', this.templateContext);
38+
this.template('_main.scss', 'containers/'+ this.name + '/' + this.name + '.scss',this.templateContext);
39+
}
40+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const ADD_<%= capsName %> = 'ADD_<%= capsName %>';
2+
export const REMOVE_<%= capsName %> = 'REMOVE_<%= capsName %>';
3+
export const UPDATE_<%= capsName %> = 'UPDATE_<%= capsName %>';
4+
5+
export function add<%= camelName %>(<%= name.toLowerCase() %>) {
6+
return {
7+
type: 'ADD_<%= capsName %>',
8+
payload: '<%= name.toLowerCase() %>'
9+
};
10+
}
11+
export function remove<%= camelName %>(<%= name.toLowerCase() %>) {
12+
return {
13+
type: 'REMOVE_<%= capsName %>',
14+
payload: '<%= name.toLowerCase() %>'
15+
};
16+
}
17+
export function update<%= camelName %>(<%= name.toLowerCase() %>) {
18+
return {
19+
type: 'UPDATE_<%= capsName %>',
20+
payload: '<%= name.toLowerCase() %>'
21+
};
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, {Component, PropTypes} from 'react';
2+
import {bindActionCreators} from 'redux';
3+
import {connect} from 'react-redux';
4+
5+
import * as Actions from '../../actions/<%= name %>';
6+
import './<%= name %>.scss';
7+
8+
class <%= name %> extends Component {
9+
constructor(props){
10+
super(props);
11+
}
12+
render(){
13+
return (
14+
<div className="<%= name %>">
15+
16+
</div>
17+
);
18+
}
19+
}
20+
21+
export default <%= name %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.<%= name %> {
2+
3+
}

0 commit comments

Comments
 (0)