Skip to content

Instantly share code, notes, and snippets.

@malerba118
Created April 10, 2019 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malerba118/937283be55e7ee2be8e07d61e426cd4b to your computer and use it in GitHub Desktop.
Save malerba118/937283be55e7ee2be8e07d61e426cd4b to your computer and use it in GitHub Desktop.
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