| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Container Generator | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const componentExists = require('../utils/componentExists'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   description: 'Add a container component', | 
					
						
							|  |  |  |   prompts: [{ | 
					
						
							|  |  |  |     type: 'input', | 
					
						
							|  |  |  |     name: 'name', | 
					
						
							|  |  |  |     message: 'What should it be called?', | 
					
						
							|  |  |  |     default: 'Form', | 
					
						
							|  |  |  |     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: 'wantHeaders', | 
					
						
							|  |  |  |     default: false, | 
					
						
							|  |  |  |     message: 'Do you want headers?', | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     type: 'confirm', | 
					
						
							|  |  |  |     name: 'wantCSS', | 
					
						
							|  |  |  |     default: false, | 
					
						
							|  |  |  |     message: 'Does it have styling?', | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     type: 'confirm', | 
					
						
							|  |  |  |     name: 'wantActionsAndReducer', | 
					
						
							|  |  |  |     default: true, | 
					
						
							|  |  |  |     message: 'Do you want an actions/constants/selectors/reducer tupel for this container?', | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     type: 'confirm', | 
					
						
							|  |  |  |     name: 'wantSagas', | 
					
						
							|  |  |  |     default: true, | 
					
						
							|  |  |  |     message: 'Do you want sagas for asynchronous flows? (e.g. fetching data)', | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     type: 'confirm', | 
					
						
							|  |  |  |     name: 'wantMessages', | 
					
						
							|  |  |  |     default: true, | 
					
						
							|  |  |  |     message: 'Do you want i18n messages (i.e. will this component use text)?', | 
					
						
							|  |  |  |   }], | 
					
						
							|  |  |  |   actions: (data) => { | 
					
						
							|  |  |  |     // Generate index.js and index.test.js
 | 
					
						
							|  |  |  |     const actions = [{ | 
					
						
							|  |  |  |       type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |       path: '../../../../../admin/src/containers/{{properCase name}}/index.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |       templateFile: './container/index.js.hbs', | 
					
						
							|  |  |  |       abortOnFail: true, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |       type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |       path: '../../../../../admin/src/containers/{{properCase name}}/tests/index.test.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |       templateFile: './container/test.js.hbs', | 
					
						
							|  |  |  |       abortOnFail: true, | 
					
						
							|  |  |  |     }]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 14:45:32 +02:00
										 |  |  |     // If they want a SCSS file, add styles.scss
 | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |     if (data.wantCSS) { | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/styles.scss', | 
					
						
							| 
									
										
										
										
											2017-01-26 17:53:47 +01:00
										 |  |  |         templateFile: './container/styles.scss.hbs', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If component wants messages
 | 
					
						
							|  |  |  |     if (data.wantMessages) { | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/messages.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/messages.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If they want actions and a reducer, generate actions.js, constants.js,
 | 
					
						
							|  |  |  |     // reducer.js and the corresponding tests for actions and the reducer
 | 
					
						
							|  |  |  |     if (data.wantActionsAndReducer) { | 
					
						
							|  |  |  |       // Actions
 | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/actions.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/actions.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/tests/actions.test.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/actions.test.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Constants
 | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/constants.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/constants.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Selectors
 | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/selectors.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/selectors.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/tests/selectors.test.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/selectors.test.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Reducer
 | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/reducer.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/reducer.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/tests/reducer.test.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/reducer.test.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Sagas
 | 
					
						
							|  |  |  |     if (data.wantSagas) { | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/sagas.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/sagas.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/containers/{{properCase name}}/tests/sagas.test.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './container/sagas.test.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return actions; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; |