Skip to content

Commit da8a037

Browse files
committed
feat(generators): add generator config and blueprints for generators
1 parent 0e659da commit da8a037

10 files changed

+175
-7
lines changed

config/blueprints/dumb-component.ejs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, { Component, PropTypes } from 'react';
2+
3+
class <%= helpers.capitalize(name) %> extends Component {
4+
render() {
5+
return (
6+
);
7+
}
8+
}
9+
10+
<%= helpers.capitalize(name) %>.propTypes = propTypes = {
11+
};
12+
13+
export default <%= helpers.capitalize(name) %>;
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { PropTypes } from 'react';
2+
3+
function <%= helpers.capitalize(name) %>(props, context) {
4+
return (
5+
);
6+
}
7+
8+
<%= helpers.capitalize(name) %>.propTypes = {
9+
};
10+
11+
export default <%= helpers.capitalize(name) %>;
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import <%= helpers.capitalize(name) %> from '../models/<%= name %>';
2+
3+
export function getSomething(req, res) {
4+
return res.status(200).end();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Router } from 'express';
2+
import * as <%= helpers.capitalize(name) %>Controller from '../controllers/<%= name %>.controller';
3+
4+
const router = new Router();
5+
6+
7+
export default router;

config/blueprints/module/model.ejs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import mongoose from 'mongoose';
2+
const Schema = mongoose.Schema;
3+
4+
const <%= name %>Schema = new Schema({
5+
6+
});
7+
8+
export default mongoose.model('<%= helpers.capitalize(name) %>', <%= name %>Schema);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Export Constants
2+
3+
// Export Actions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Import Actions
2+
import { } from './<%= helpers.capitalize(name) %>Actions';
3+
4+
// Initial State
5+
const initialState = {};
6+
7+
const <%= helpers.capitalize(name) %>Reducer = (state = initialState, action) => {
8+
switch (action.type) {
9+
default:
10+
return state;
11+
}
12+
};
13+
14+
export default <%= helpers.capitalize(name) %>Reducer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* <%= helpers.capitalize(name) %> styles */

config/blueprints/module/module.ejs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import { connect } from 'react-redux';
3+
import { bindActionCreators } from 'redux';
4+
5+
// Import Style
6+
import styles from './<%= helpers.capitalize(name) %>.css';
7+
8+
class <%= helpers.capitalize(name) %> extends Component {
9+
render() {
10+
return (
11+
);
12+
}
13+
}
14+
15+
const mapStateToProps = (state) => {
16+
return {};
17+
};
18+
19+
const mapDispatchToProps = (dispatch) => {
20+
return {};
21+
};
22+
23+
<%= helpers.capitalize(name) %>.propTypes = {
24+
};
25+
26+
export default connect(
27+
mapStateToProps,
28+
mapDispatchToProps
29+
)(<%= helpers.capitalize(name) %>);

mern.json

+84-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,85 @@
11
{
2-
"container": "/shared/container",
3-
"dumb": "/shared/components",
4-
"functional": "/shared/components",
5-
"model": "/server/models",
6-
"route": "/server/routes",
7-
"controller": "/server/controllers"
8-
}
2+
"blueprints": [
3+
{
4+
"name": "dumb-s",
5+
"description": "Generates a dumb react component in shared components",
6+
"usage": "dumb-s [component-name]",
7+
"files": [
8+
{
9+
"blueprint-path": "config/blueprints/dumb-component.ejs",
10+
"target-path": "client/components/<%= helpers.capitalize(name) %>.js"
11+
}
12+
]
13+
},
14+
{
15+
"name": "dumb-m",
16+
"description": "Generates a dumb react component in a module directory",
17+
"usage": "dumb-m <module-name>/<component-name>",
18+
"files": [
19+
{
20+
"blueprint-path": "config/blueprints/dumb-component.ejs",
21+
"parent-path": "client/modules/<%= helpers.capitalize(parent) %>",
22+
"target-path": "components/<%= helpers.capitalize(name) %>/<%= helpers.capitalize(name) %>.js"
23+
}
24+
]
25+
},
26+
{
27+
"name": "functional-s",
28+
"description": "Generates a functional react component in shared components",
29+
"usage": "functional-s [component-name]",
30+
"files": [
31+
{
32+
"blueprint-path": "config/blueprints/functional-component.ejs",
33+
"target-path": "client/components/<%= helpers.capitalize(name) %>.js"
34+
}
35+
]
36+
},
37+
{
38+
"name": "functional-m",
39+
"description": "Generates a functional react component in a module directory",
40+
"usage": "functional-m <module-name>/<component-name>",
41+
"files": [
42+
{
43+
"blueprint-path": "config/blueprints/functional-component.ejs",
44+
"parent-path": "client/modules/<%= helpers.capitalize(parent) %>",
45+
"target-path": "components/<%= helpers.capitalize(name) %>/<%= helpers.capitalize(name) %>.js"
46+
}
47+
]
48+
},
49+
{
50+
"name": "module",
51+
"description": "Generates a module including react components, reducer, action, style & express route, controller, model",
52+
"usage": "module [module-name]",
53+
"files": [
54+
{
55+
"blueprint-path": "config/blueprints/module/module.ejs",
56+
"target-path": "client/modules/<%= helpers.capitalize(name) %>/<%= helpers.capitalize(name) %>.js"
57+
},
58+
{
59+
"blueprint-path": "config/blueprints/module/module-actions.ejs",
60+
"target-path": "client/modules/<%= helpers.capitalize(name) %>/<%= helpers.capitalize(name) %>Actions.js"
61+
},
62+
{
63+
"blueprint-path": "config/blueprints/module/module-reducer.ejs",
64+
"target-path": "client/modules/<%= helpers.capitalize(name) %>/<%= helpers.capitalize(name) %>Reducer.js"
65+
},
66+
{
67+
"blueprint-path": "config/blueprints/module/module-styles.ejs",
68+
"target-path": "client/modules/<%= helpers.capitalize(name) %>/<%= helpers.capitalize(name) %>.css"
69+
},
70+
{
71+
"blueprint-path": "config/blueprints/module/controller.ejs",
72+
"target-path": "server/controllers/<%= name %>.controller.js"
73+
},
74+
{
75+
"blueprint-path": "config/blueprints/module/express-route.ejs",
76+
"target-path": "server/routes/<%= name %>.routes.js"
77+
},
78+
{
79+
"blueprint-path": "config/blueprints/module/model.ejs",
80+
"target-path": "server/models/<%= name %>.js"
81+
}
82+
]
83+
}
84+
]
85+
}

0 commit comments

Comments
 (0)