Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 410ff7e

Browse files
committed
chore(uptodate): generators
1 parent 7dab00a commit 410ff7e

File tree

8 files changed

+56
-26
lines changed

8 files changed

+56
-26
lines changed
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
/*
2-
*
3-
* {{ properCase name }}
4-
*
2+
*
3+
* {{ properCase name }}
4+
*
55
*/
66

77
import React from 'react'
88
import PropTypes from 'prop-types'
99

10-
// import { inject, observer } from 'mobx-react'
11-
// import Link from 'next/link'
12-
// import styled from 'styled-components'
13-
10+
{{#if wantStyle}}
11+
import { Wrapper } from './styles'
12+
{{/if}}
1413
{{#if wantMessages}}
1514
import { FormattedMessage } from 'react-intl'
1615
import messages from './messages'
1716
{{/if}}
1817

19-
// @inject('')
20-
// @observer
21-
class {{ properCase name }} extends React.Component {
18+
import { makeDebugger } from '../../utils'
19+
20+
/* eslint-disable no-unused-vars */
21+
const debug = makeDebugger('c:{{ properCase name }}:index')
22+
/* eslint-enable no-unused-vars */
23+
24+
class {{ properCase name }} extends React.PureComponent {
2225
componentDidMount() {}
2326

2427
componentWillUnmount() {}
2528

2629
render() {
2730
return (
2831
<div>
29-
{{ properCase name }} component
30-
{{#if wantMessages}}
31-
<FormattedMessage {...messages.header} />
32-
{{/if}}
32+
{{ properCase name }} component
33+
{{#if wantMessages}}
34+
<FormattedMessage {...messages.header} />
35+
{{/if}}
3336
</div>
3437
)
3538
}
3639
}
3740

38-
export default {{ properCase name }}
39-
40-
Index.propTypes = {
41+
{{ properCase name }}.propTypes = {
4142
// https://www.npmjs.com/package/prop-types
4243
}
4344

44-
Index.defaultProps = {}
45+
{{ properCase name }}.defaultProps = {}
46+
47+
export default {{ properCase name }}

utils/scripts/generators/component/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ module.exports = {
3636
{
3737
type: 'confirm',
3838
name: 'wantI18n',
39-
default: true,
39+
default: false,
4040
message: 'Do you want i18n messages (i.e. will this component use text)?',
4141
},
42+
{
43+
type: 'confirm',
44+
name: 'wantStyle',
45+
default: true,
46+
message: 'Does it have styles?',
47+
},
4248
],
4349
actions: data => {
4450
// Generate index.js and index.test.js
@@ -79,6 +85,15 @@ module.exports = {
7985
})
8086
}
8187

88+
if (data.wantStyle) {
89+
actions.push({
90+
type: 'add',
91+
path: '../../../components/{{properCase name}}/styles/index.js',
92+
templateFile: './component/styles.js.hbs',
93+
abortOnFail: true,
94+
})
95+
}
96+
8297
return actions
8398
},
8499
}

utils/scripts/generators/component/stateless.js.hbs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
/*
1+
/*
22
*
33
* {{ properCase name }}
44
*
5-
*/
5+
*/
66

77
import React from 'react'
88
import PropTypes from 'prop-types'
99

10+
{{#if wantStyle}}
11+
import { Wrapper } from './styles'
12+
{{/if}}
1013
{{#if wantI18n}}
1114
import { FormattedMessage as I18n } from 'react-intl'
1215
import lang from './lang'
1316
{{/if}}
1417

1518
import { makeDebugger } from '../../utils'
19+
1620
/* eslint-disable no-unused-vars */
1721
const debug = makeDebugger('c:{{ properCase name }}:index')
1822
/* eslint-enable no-unused-vars */
@@ -34,4 +38,4 @@ const {{ properCase name }} = (props) => {
3438

3539
{{ properCase name }}.defaultProps = {}
3640

37-
export default {{ properCase name }}
41+
export default React.memo({{ properCase name }})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import styled from 'styled-components'
2+
3+
// import Img from '../../Img'
4+
// import { theme } from '../../../utils'
5+
6+
export const Wrapper = styled.div``
7+
export const Title = styled.div``

utils/scripts/generators/container/class.js.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const debug = makeDebugger('C:{{ properCase name }}')
2222

2323
// NOTE: add me to ../containers/index
2424
class {{ properCase name }}Container extends React.Component {
25-
componentWillMount() {
25+
componentDidMount() {
2626
const {{preCurly ""}} {{ camelCase name}} {{afterCurly ""}} = this.props
2727
logic.init({{ camelCase name }})
2828
}

utils/scripts/generators/container/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
{
3636
type: 'confirm',
3737
name: 'wantI18n',
38-
default: true,
38+
default: false,
3939
message: 'Do you want i18n messages (i.e. will this container use text)?',
4040
},
4141
],

utils/scripts/generators/container/styles.js.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from 'styled-components'
2-
// import Img from '../../Img'
2+
3+
// import Img from '../../../components/Img'
34
// import { theme } from '../../../utils'
45

56
export const Wrapper = styled.div``

utils/scripts/generators/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const componentGenerator = require('./component/index.js')
22
const containerGenerator = require('./container/index.js')
33
const storeGenerator = require('./store/index.js')
44

5-
module.exports = function(plop) {
5+
module.exports = function generators(plop) {
66
// see: https://github.com/amwmedia/plop/issues/116
77
plop.setHelper('preCurly', t => `{${t}`)
88
plop.setHelper('afterCurly', t => `${t}}`)

0 commit comments

Comments
 (0)