1.0.1 • Published 6 years ago
plop-decorators v1.0.1
plop-decorators
Helpers for plopjs generator
Inculde 3 decorators: withHelpers, withActions, withGenerators
withHelpers- to add extra functions to .hbs templateswithActions- automatically addsprependaction and allows to add custom actions. If you created customHelpers don't forget to add them towithActionsso thatprependaction could work properly with your functions.withGenerators- by default searches for every files in.plop/generatorsfolder
Include 1 custom action prepend
The action injects the replacement before the market and not after
Installation
yarn add --dev plop plop-decoratorsAPI
- Create
index.jsinside.plopfolder 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/generatorsfolder 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.jsonadd the next command toscriptssection:
"scripts": {
"gen": "plop --plopfile .plop/index.js",
...
}- Run
yarn gen