1.1.0 • Published 9 years ago
react-create-helper v1.1.0
react-create-helper
CLI tool to help with creating components, reducers and actions.
Features
#####Create react-* with predefined templates
- Components
- Redux actions
- Redux reducers
Install
npm i -g react-create-helperOptions
Add new string to package.json with name "react-create-helper"
base(string) - Base dir for components, actions, and reducers. Default - project root (./)actionsDir(string) - Base dir for actions, extendsbase. Default - project root (./)reducersDir(string) - Base dir for reducers, extendsbase. Default - project root (./)styleExtension(string) - Extensions for generated style file. Default -csscomponentName.prepend(string) - Prefix for generated component. Default -undefinedcomponentName.append(string) - Suffix for generated component. Default -undefinedtemplate.component(string) - Path for your own component template. Default -undefinedtemplate.reducer(string) - Path for your own reducer template. Default -undefinedtemplate.action(string) - Path for your own action template. Default -undefined
Example options
"react-create-helper": {
"base": "./src",
"actionsDir": "Actions",
"reducersDir": "Reducers",
"componentName": {
"prepend": "My",
"append": "Component"
},
"styleExtension": "scss"
}Basic usage
Cli options
-cgenerate component (default)-rgenerate reducer-agenerate action-mgenerate module-hhelp (options and usage examples)
rch Headeroutput
Header
├── Header.js
├── Header.scss
└── index.jsAlso you can specify path like rch my/path/Header
Generate action & reducers
$ rch -ar ExampleActionThis will generate something like this
src
├── Actions
│ └── ExampleAction.js
└── Reducers
└── ExampleReducer.jsGenerate module
$ rch -m ExampleModuleThis will generate something like this
ExampleModule
├── ExampleModule.js
├── ExampleModule.scss
├── index.js
└── redux
├── reducers.js
├── actions.js
└── constants.jsDefine own templates
"react-create-helper": {
"template": {
"component": "rch_templates/component.js",
"reducer": "rch_templates/reducer.js",
"action": "rch_templates/action.js",
},
}######Base template
{basename} is the name you provided with rch -c {basename}
./rch_templates/component.js
module.exports = ({basename}) =>
`import React, { Component } from 'react';
import { connect } from 'react-redux';
class ${basename} extends Component {
render() {
return (
<div></div>
)
}
}
const mapStateToProps = (state) => {
return {
}
};
const mapDispatchToProps = (dispatch) => {
return {
exampleName: (exampleProps) => {
dispatch(exampleActionName)
}
}
};
export default connect(mapStateToProps, mapDispatchToProps)(${basename});
`;The same for action, and reducer.
######Have fun