| | |
| | |
| | |
| |
|
| | |
| | |
| | 'use strict'; |
| |
|
| | const componentExists = require('../utils/componentExists'); |
| |
|
| | module.exports = { |
| | description: 'Add an unconnected component', |
| | prompts: [ |
| | { |
| | type: 'input', |
| | name: 'name', |
| | message: 'What should it be called?', |
| | default: 'Button', |
| | validate: value => { |
| | if (/.+/.test(value)) { |
| | return componentExists(value) |
| | ? 'A component or container with this name already exists' |
| | : true; |
| | } |
| |
|
| | return 'The name is required'; |
| | }, |
| | }, |
| | { |
| | type: 'confirm', |
| | name: 'memo', |
| | default: false, |
| | message: 'Do you want to wrap your component in React.memo?', |
| | }, |
| | { |
| | type: 'confirm', |
| | name: 'wantMessages', |
| | default: true, |
| | message: 'Do you want i18n messages (i.e. will this component use text)?', |
| | }, |
| | { |
| | type: 'confirm', |
| | name: 'wantLoadable', |
| | default: false, |
| | message: 'Do you want to load the component asynchronously?', |
| | }, |
| | ], |
| | actions: data => { |
| | |
| | const actions = [ |
| | { |
| | type: 'add', |
| | path: '../../app/components/{{properCase name}}/index.js', |
| | templateFile: './component/index.js.hbs', |
| | abortOnFail: true, |
| | }, |
| | { |
| | type: 'add', |
| | path: '../../app/components/{{properCase name}}/tests/index.test.js', |
| | templateFile: './component/test.js.hbs', |
| | abortOnFail: true, |
| | }, |
| | ]; |
| |
|
| | |
| | if (data.wantMessages) { |
| | actions.push({ |
| | type: 'add', |
| | path: '../../app/components/{{properCase name}}/messages.js', |
| | templateFile: './component/messages.js.hbs', |
| | abortOnFail: true, |
| | }); |
| | } |
| |
|
| | |
| | if (data.wantLoadable) { |
| | actions.push({ |
| | type: 'add', |
| | path: '../../app/components/{{properCase name}}/Loadable.js', |
| | templateFile: './component/loadable.js.hbs', |
| | abortOnFail: true, |
| | }); |
| | } |
| |
|
| | actions.push({ |
| | type: 'prettify', |
| | path: '/components/', |
| | }); |
| |
|
| | return actions; |
| | }, |
| | }; |
| |
|