Skip to content

Commit c27f5f6

Browse files
committed
improvement: change plop configuration to be similar to the way we actually create component
1 parent 877d644 commit c27f5f6

File tree

4 files changed

+45
-53
lines changed

4 files changed

+45
-53
lines changed

plop-templates/component.config.hbs

-7
This file was deleted.

plop-templates/component.test.hbs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import initStoryshots from "@storybook/addon-storyshots";
1+
import {{properCase name}} from './{{properCase name}}.component';
2+
import React from 'react';
3+
import { render } from '@testing-library/react';
24

3-
initStoryshots({
4-
configPath: "src/lib/components/{{lowerCase name}}/__snapshots__"
5-
});
5+
describe('{{properCase name}}', () => {
6+
test('default test', () => {
7+
const { debug } = render(<{{properCase name}} />);
8+
debug();
9+
});
10+
});

plop-templates/stories.hbs

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
//@flow
2-
import React from "react";
3-
import { storiesOf } from "@storybook/react";
2+
import React from 'react';
43
import {{properCase name}} from "../src/lib/components/{{lowerCase name}}/{{properCase name}}.component";
4+
import { Wrapper, Title } from './common';
55

6-
storiesOf("{{properCase name}}", module)
7-
.add("Default", () => {
8-
return (
9-
<div>
10-
<{{properCase name}} />
11-
</div>
12-
);
13-
});
6+
export default {
7+
title: 'Components/{{properCase name}}',
8+
component: {{properCase name}},
9+
};
10+
11+
export const Default = () => {
12+
return (
13+
<Wrapper>
14+
<Title>Basic usage</Title>
15+
<{{properCase name}} />
16+
</Wrapper>
17+
);
18+
};

plopfile.js

+21-32
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,38 @@
1-
module.exports = function(plop) {
2-
plop.addHelper("lowerCase", text => text.toLowerCase());
3-
plop.addHelper("properCase", text =>
4-
text.replace(/\w\S*/g, function(txt) {
1+
module.exports = function (plop) {
2+
plop.addHelper('lowerCase', (text) => text.toLowerCase());
3+
plop.addHelper('properCase', (text) =>
4+
text.replace(/\w\S*/g, function (txt) {
55
return txt.charAt(0).toUpperCase() + txt.substr(1);
6-
})
6+
}),
77
);
88

9-
plop.setGenerator("component", {
10-
description: "Add a react component",
9+
plop.setGenerator('component', {
10+
description: 'Add a react component',
1111
prompts: [
1212
{
13-
type: "input",
14-
name: "name",
15-
message: "Component name please (ex: layout, breadcrumbs, menuItem)!"
16-
}
13+
type: 'input',
14+
name: 'name',
15+
message: 'Component name please (ex: layout, breadcrumbs, menuItem)!',
16+
},
1717
],
1818
actions: [
1919
{
20-
type: "add",
20+
type: 'add',
2121
path:
22-
"src/lib/components/{{lowerCase name}}/{{properCase name}}.component.js",
23-
templateFile: "plop-templates/component.hbs"
22+
'src/lib/components/{{lowerCase name}}/{{properCase name}}.component.js',
23+
templateFile: 'plop-templates/component.hbs',
2424
},
2525
{
26-
type: "add",
26+
type: 'add',
2727
path:
28-
"src/lib/components/{{lowerCase name}}/{{properCase name}}.component.test.js",
29-
templateFile: "plop-templates/component.test.hbs"
30-
},
31-
{
32-
type: "add",
33-
path: "src/lib/components/{{lowerCase name}}/__snapshots__/config.js",
34-
templateFile: "plop-templates/component.config.hbs"
28+
'src/lib/components/{{lowerCase name}}/{{properCase name}}.component.test.js',
29+
templateFile: 'plop-templates/component.test.hbs',
3530
},
3631
{
37-
type: "add",
38-
path: "stories/{{lowerCase name}}.js",
39-
templateFile: "plop-templates/stories.hbs"
32+
type: 'add',
33+
path: 'stories/{{lowerCase name}}.stories.js',
34+
templateFile: 'plop-templates/stories.hbs',
4035
},
41-
{
42-
type: "append",
43-
path: "stories/index.js",
44-
template: 'import "./{{lowerCase name}}";',
45-
separator: ""
46-
}
47-
]
36+
],
4837
});
4938
};

0 commit comments

Comments
 (0)