Created
April 10, 2019 04:53
-
-
Save malerba118/937283be55e7ee2be8e07d61e426cd4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = plop => { | |
plop.setGenerator('component', { | |
description: 'Create a reusable component', | |
prompts: [ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'What is your component name?', | |
}, | |
], | |
actions: [ | |
{ | |
type: 'add', | |
path: 'src/components/{{pascalCase name}}/{{pascalCase name}}.js', | |
templateFile: | |
'plop-templates/Component/Component.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/components/{{pascalCase name}}/{{pascalCase name}}.test.js', | |
templateFile: | |
'plop-templates/Component/Component.test.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: | |
'src/components/{{pascalCase name}}/{{pascalCase name}}.module.css', | |
templateFile: | |
'plop-templates/Component/Component.module.css.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/components/{{pascalCase name}}/index.js', | |
templateFile: 'plop-templates/Component/index.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/components/index.js', | |
templateFile: 'plop-templates/injectable-index.js.hbs', | |
skipIfExists: true, | |
}, | |
{ | |
type: 'append', | |
path: 'src/components/index.js', | |
pattern: `/* PLOP_INJECT_IMPORT */`, | |
template: `import {{pascalCase name}} from './{{pascalCase name}}';`, | |
}, | |
{ | |
type: 'append', | |
path: 'src/components/index.js', | |
pattern: `/* PLOP_INJECT_EXPORT */`, | |
template: `\t{{pascalCase name}},`, | |
}, | |
], | |
}) | |
plop.setGenerator('page', { | |
description: 'Create a page', | |
prompts: [ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'What is your page name?', | |
}, | |
], | |
actions: [ | |
{ | |
type: 'add', | |
path: 'src/pages/{{pascalCase name}}/{{pascalCase name}}.js', | |
templateFile: | |
'plop-templates/Page/Page.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/pages/{{pascalCase name}}/{{pascalCase name}}.test.js', | |
templateFile: | |
'plop-templates/Page/Page.test.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: | |
'src/pages/{{pascalCase name}}/{{pascalCase name}}.module.css', | |
templateFile: | |
'plop-templates/Page/Page.module.css.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/pages/{{pascalCase name}}/index.js', | |
templateFile: 'plop-templates/Page/index.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/pages/index.js', | |
templateFile: 'plop-templates/injectable-index.js.hbs', | |
skipIfExists: true, | |
}, | |
{ | |
type: 'append', | |
path: 'src/pages/index.js', | |
pattern: `/* PLOP_INJECT_IMPORT */`, | |
template: `import {{pascalCase name}} from './{{pascalCase name}}';`, | |
}, | |
{ | |
type: 'append', | |
path: 'src/pages/index.js', | |
pattern: `/* PLOP_INJECT_EXPORT */`, | |
template: `\t{{pascalCase name}},`, | |
}, | |
], | |
}) | |
plop.setGenerator('service', { | |
description: 'Create service', | |
prompts: [ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'What is your service name?', | |
}, | |
], | |
actions: [ | |
{ | |
type: 'add', | |
path: 'src/services/{{camelCase name}}.js', | |
templateFile: 'plop-templates/service.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/services/index.js', | |
templateFile: 'plop-templates/injectable-index.js.hbs', | |
skipIfExists: true, | |
}, | |
{ | |
type: 'append', | |
path: 'src/services/index.js', | |
pattern: `/* PLOP_INJECT_IMPORT */`, | |
template: `import {{camelCase name}} from './{{camelCase name}}';`, | |
}, | |
{ | |
type: 'append', | |
path: 'src/services/index.js', | |
pattern: `/* PLOP_INJECT_EXPORT */`, | |
template: `\t{{camelCase name}},`, | |
} | |
], | |
}) | |
plop.setGenerator('hook', { | |
description: 'Create a custom react hook', | |
prompts: [ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'What is your hook name?', | |
}, | |
], | |
actions: [ | |
{ | |
type: 'add', | |
path: 'src/hooks/{{camelCase name}}.js', | |
templateFile: 'plop-templates/hook.js.hbs', | |
}, | |
{ | |
type: 'add', | |
path: 'src/hooks/index.js', | |
templateFile: 'plop-templates/injectable-index.js.hbs', | |
skipIfExists: true, | |
}, | |
{ | |
type: 'append', | |
path: 'src/hooks/index.js', | |
pattern: `/* PLOP_INJECT_IMPORT */`, | |
template: `import {{camelCase name}} from './{{camelCase name}}';`, | |
}, | |
{ | |
type: 'append', | |
path: 'src/hooks/index.js', | |
pattern: `/* PLOP_INJECT_EXPORT */`, | |
template: `\t{{camelCase name}},`, | |
} | |
], | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment