react-create-helper
Advanced tools
Comparing version
17
index.js
@@ -53,8 +53,19 @@ #! /usr/bin/env node | ||
let jsContent = require("./templates/component")({basename}); | ||
let actionContent = require("./templates/action")({basename}); | ||
let reducerContent = require("./templates/reducer")(); | ||
let reducerContent = require("./templates/reducer")({basename}); | ||
if(typeof config !== "undefined" && typeof config.template !== "undefined"){ | ||
if(config.template.component){ | ||
jsContent = require( path.resolve(process.cwd(), config.template.component) )({basename}); | ||
} | ||
if(config.template.action){ | ||
actionContent = require( path.resolve(process.cwd(), config.template.action) )({basename}); | ||
} | ||
if(config.template.reducer){ | ||
reducerContent = require( path.resolve(process.cwd(), config.template.reducer) )({basename}); | ||
} | ||
} | ||
let indexContent = `import ${basename} from "./${basename}"; | ||
@@ -132,3 +143,3 @@ export default ${basename}; | ||
program | ||
.version('0.1.6') | ||
.version('1.0.0') | ||
.on('--help', function(){ | ||
@@ -135,0 +146,0 @@ console.log(' Examples:'); |
{ | ||
"name": "react-create-helper", | ||
"version": "0.1.6", | ||
"description": "create components, reducers and actions easier", | ||
"version": "1.0.0", | ||
"description": "create components, reducers and actions, does not overwrite, make your own templates", | ||
"keywords": [ | ||
@@ -12,6 +12,9 @@ "react", | ||
"react redux action", | ||
"create react redux action", | ||
"redux reducer", | ||
"react redux reducer", | ||
"create redux reducer", | ||
"cli", | ||
"rch" | ||
"rch", | ||
"create-react" | ||
], | ||
@@ -18,0 +21,0 @@ "main": "index.js", |
126
README.md
@@ -1,3 +0,13 @@ | ||
# react-create-helper | ||
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 | ||
@@ -8,11 +18,23 @@ | ||
``` | ||
Options | ||
------- | ||
Add new string to `package.json` with name `"react-create-helper"` <br> | ||
- `base` (string) - Base dir for components, actions, and reducers. Default - project root (`./`) | ||
- `actionsDir` (string) - Base dir for actions, extends `base`. Default - project root (`./`) | ||
- `reducersDir` (string) - Base dir for reducers, extends `base`. Default - project root (`./`) | ||
- `styleExtension` (string) - Extensions for generated style file. Default - `css` | ||
- `componentName.prepend` (string) - Prefix for generated component. Default - `undefined` | ||
- `componentName.append` (string) - Suffix for generated component. Default - `undefined` | ||
- `template.component` (string) - Path for your own component template. Default - `undefined` | ||
- `template.reducer` (string) - Path for your own reducer template. Default - `undefined` | ||
- `template.action` (string) - Path for your own action template. Default - `undefined` | ||
## Options | ||
You can provide options in your package json like that | ||
## Example options | ||
```$js | ||
"react-create-helper": { | ||
"base": "./src", | ||
"actionsDir": "actions", | ||
"reducersDir": "reducers", | ||
"actionsDir": "Actions", | ||
"reducersDir": "Reducers", | ||
"componentName": { | ||
@@ -22,20 +44,14 @@ "prepend": "My", | ||
}, | ||
"styleExtension": "css" | ||
"styleExtension": "scss" | ||
} | ||
``` | ||
**base**: *base dir for components from your project root* | ||
**actionsDir**: *base dir of actions from base* | ||
### Basic usage | ||
**Cli options** | ||
- `-c` generate component (default) | ||
- `-r` generate reducer | ||
- `-a` generate action | ||
- `-h` help (options and usage examples) | ||
**reducersDir**: *base dir of reducers from base* | ||
**componentName**: *also you can configure prefix and suffix of component name.* | ||
**styleExtension**: *style extension)))* | ||
######Does not overwrite files | ||
### Generate component | ||
```$bash | ||
@@ -53,20 +69,7 @@ rch Header | ||
``` | ||
Also you can specify path like `rch my/path/Header` | ||
### Generate action & reducers | ||
#### `package.json` | ||
```$js | ||
"react-create-helper": { | ||
"base": "./src", | ||
"actionsDir": "Actions", | ||
"reducersDir": "Reducers", | ||
"componentName": { | ||
"prepend": "My", | ||
"append": "Component" | ||
}, | ||
"styleExtension": "css" | ||
} | ||
``` | ||
##### Generate action & reducers | ||
```bash | ||
$ rch -c Example | ||
$ rch -a ExampleAction | ||
@@ -79,6 +82,2 @@ $ rch -r ExampleReducer | ||
src | ||
├── MyExampleComponent | ||
│ ├── MyExampleComponent.js | ||
│ ├── MyExampleComponent.css | ||
│ └── index.js | ||
├── Actions | ||
@@ -90,2 +89,53 @@ │ └── ExampleAction.js | ||
Also you can use `rch -h`. To see all options and usage examples; | ||
## Define own templates | ||
```$js | ||
"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` | ||
```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 |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10896
22.98%171
6.88%1
-50%136
58.14%6
100%