plop-decorators
v1.0.1
Published
![GitHub package.json version](https://img.shields.io/github/package-json/v/darmikon/plop-decorators) ![npm](https://img.shields.io/npm/v/plop-decorators) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://co
Downloads
43
Maintainers
Readme
plop-decorators
Helpers for plopjs generator
Inculde 3 decorators: withHelpers
, withActions
, withGenerators
withHelpers
- to add extra functions to .hbs templateswithActions
- automatically addsprepend
action and allows to add custom actions. If you created customHelpers don't forget to add them towithActions
so thatprepend
action could work properly with your functions.withGenerators
- by default searches for every files in.plop/generators
folder
Include 1 custom action prepend
The action injects the replacement before the market and not after
Installation
yarn add --dev plop plop-decorators
API
- Create
index.js
inside.plop
folder of root directory
const { withHelpers, withActions, withGenerators } = require('plop-helpers');
global.cwd = process.cwd();
const customHelpers = {};
const customActions = {};
module.exports = plop => {
withHelpers(plop, customHelpers);
withActions(plop, customActions, customHelpers);
withGenerators(plop);
};
- Create generator files inside
.plop/generators
folder e.g.
module.exports = plop =>
plop.setGenerator('epic', {
description: 'Epic Injection',
prompts: [
{
type: 'input',
name: 'name',
message: 'Epic Name',
},
{
type: 'input',
name: 'moduleName',
message: 'Into module:',
},
],
actions: [
// EPIC
{
type: 'prepend',
path: `${cwd}/src/{{moduleName}}/epics.js`,
pattern: '//†epic',
template: `export const {{camelCase name}}Epic = (action$, state$) =>
of('MOCK').pipe(ignoreElements());`,
},
],
});
- In
package.json
add the next command toscripts
section:
"scripts": {
"gen": "plop --plopfile .plop/index.js",
...
}
- Run
yarn gen