Skip to content

Commit

Permalink
Add a basic plop generator
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed Apr 13, 2017
1 parent 0e59275 commit e122fb2
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ Run `yarn build` to create static site ready to host (`/public`)
- [ ] Code climate config
- [x] SEO
- [x] [Helmet](https://github.com/nfl/react-helmet)
- [ ] Lazyboy tools
- [ ] [plop](https://github.com/amwmedia/plop) templates -> `yarn generate`
- [x] Lazyboy tools
- [x] [plop](https://github.com/amwmedia/plop) templates -> `yarn generate`

## Files structure
```
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "gatsby build",
"test": "xo && tslint && jest",
"test:watch": "jest --watch",
"generate": "plop",
"precommit": "lint-staged"
},
"dependencies": {
Expand Down Expand Up @@ -45,6 +46,7 @@
"husky": "0.13.3",
"jest": "19.0.2",
"lint-staged": "3.4.0",
"plop": "^1.7.4",
"react-addons-test-utils": "^15.5.1",
"react-test-renderer": "^15.5.4",
"ts-jest": "19.0.8",
Expand All @@ -60,6 +62,10 @@
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"/node_modules/",
"/templates/"
],
"moduleFileExtensions": [
"ts",
"tsx",
Expand Down
32 changes: 32 additions & 0 deletions plopfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Plopfile generator
*
* https://github.com/amwmedia/plop
*/

module.exports = plop => {
plop.setGenerator('component', {
prompts: [
{
type: 'input',
name: 'name',
message: 'Component name?',
validate: value => /.+/.test(value) ? true : 'name is required'
}
],
actions: data => {
return [
{
type: 'add',
path: 'src/components/{{pascalCase name}}.tsx',
templateFile: 'templates/component.tsx'
},
{
type: 'add',
path: 'src/components/{{pascalCase name}}.test.tsx',
templateFile: 'templates/component.test.tsx'
}
];
}
});
};
11 changes: 11 additions & 0 deletions templates/component.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { shallow } from "enzyme";
import "jest";
import * as React from "react";
import {{pascalCase name}} from "./{{pascalCase name}}";

describe("{{pascalCase name}} component", () => {
it("should have the correct text", () => {
const {{name}} = shallow(<{{pascalCase name}} />);
expect({{name}}.text()).toBe("My awesome component");
});
});
11 changes: 11 additions & 0 deletions templates/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from "react";

interface {{pascalCase name}}Props extends React.HTMLProps<HTMLDivElement> {

}

export default (props: {{pascalCase name}}Props) => {
return (
<div>My awesome component</div>
);
};
Loading

0 comments on commit e122fb2

Please sign in to comment.