| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Component Generator | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const componentExists = require('../utils/componentExists'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   description: 'Add an unconnected component', | 
					
						
							|  |  |  |   prompts: [{ | 
					
						
							|  |  |  |     type: 'list', | 
					
						
							|  |  |  |     name: 'type', | 
					
						
							|  |  |  |     message: 'Select the type of component', | 
					
						
							|  |  |  |     default: 'Stateless Function', | 
					
						
							|  |  |  |     choices: () => ['ES6 Class', 'Stateless Function'], | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     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: 'wantCSS', | 
					
						
							|  |  |  |     default: true, | 
					
						
							|  |  |  |     message: 'Does it have styling?', | 
					
						
							|  |  |  |   }], | 
					
						
							|  |  |  |   actions: (data) => { | 
					
						
							|  |  |  |     // Generate index.js and index.test.js
 | 
					
						
							|  |  |  |     const actions = [{ | 
					
						
							|  |  |  |       type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |       path: '../../../../../admin/src/components/{{properCase name}}/index.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |       templateFile: data.type === 'ES6 Class' ? './component/es6.js.hbs' : './component/stateless.js.hbs', | 
					
						
							|  |  |  |       abortOnFail: true, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |       type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |       path: '../../../../../admin/src/components/{{properCase name}}/tests/index.test.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |       templateFile: './component/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/components/{{properCase name}}/styles.scss', | 
					
						
							| 
									
										
										
										
											2017-05-10 14:45:32 +02:00
										 |  |  |         templateFile: './component/styles.scss.hbs', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If they want a i18n messages file
 | 
					
						
							|  |  |  |     if (data.wantMessages) { | 
					
						
							|  |  |  |       actions.push({ | 
					
						
							|  |  |  |         type: 'add', | 
					
						
							| 
									
										
										
										
											2017-06-08 17:16:20 +01:00
										 |  |  |         path: '../../../../../admin/src/components/{{properCase name}}/messages.js', | 
					
						
							| 
									
										
										
										
											2017-01-17 13:40:59 +01:00
										 |  |  |         templateFile: './component/messages.js.hbs', | 
					
						
							|  |  |  |         abortOnFail: true, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return actions; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; |