Skip to content

Commit

Permalink
Add support to plop generator
Browse files Browse the repository at this point in the history
  • Loading branch information
vczb committed Aug 20, 2022
1 parent b0157f6 commit 5a6e941
Show file tree
Hide file tree
Showing 9 changed files with 841 additions and 17 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ storybook-static
rollup.config.*
node_modules/
docs-build/
generators
.github
.tool-versions
./**/*/stories.*
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.hbs
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ You can contribute to this project by opening an issue or creating a pull reques
- `sb`: run the storybook at the address `localhost:6006`
- `prettier:check`: check formatting on all `src` directory
- `prettier:format`: formats all `src` directory
- `generate <Component name>`: create a component boilerplate

## Project structure

Expand Down
33 changes: 33 additions & 0 deletions generators/plopfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = function (plop) {
plop.setGenerator('component', {
description: 'application component',

// inquirer prompts
prompts: [
{
type: 'input',
name: 'name',
message: 'component name?'
}
],

// actions to perform
actions: [
{
type: 'add',
path: '../src/packages/{{pascalCase name}}/index.tsx',
templateFile: 'templates/index.tsx.hbs'
},
{
type: 'add',
path: '../src/packages/{{pascalCase name}}/stories.tsx',
templateFile: 'templates/stories.tsx.hbs'
},
{
type: 'add',
path: '../src/packages/{{pascalCase name}}/styles.ts',
templateFile: 'templates/styles.ts.hbs'
}
]
})
}
10 changes: 10 additions & 0 deletions generators/templates/index.tsx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import * as S from './styles'

const {{pascalCase name}} = () => (
<S.Wrapper>
<h1>{{pascalCase name}}</h1>
</S.Wrapper>
)

export default {{pascalCase name}}
10 changes: 10 additions & 0 deletions generators/templates/stories.tsx.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { Story, Meta } from '@storybook/react/types-6-0'
import Tag from '.'

export default {
title: 'Tag',
component: Tag
} as Meta

export const Default: Story = (args) => <Tag {...args} />
3 changes: 3 additions & 0 deletions generators/templates/styles.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import styled from 'styled-components'

export const Wrapper = styled.div``
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"prettier:format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
"prettier:check": "prettier -c \"src/**/*.{ts,tsx,js,jsx,json,md}\"",
"sb": "start-storybook -p 6006",
"build-storybook": "build-storybook"
"build-storybook": "build-storybook",
"generate": "yarn plop --plopfile ./generators/plopfile.js"
},
"keywords": [
"React",
Expand Down Expand Up @@ -45,6 +46,7 @@
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"plop": "^3.1.1",
"prettier": "^2.3.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
Loading

0 comments on commit 5a6e941

Please sign in to comment.