UNPKG

feds-cli

Version:

CLI for Front-end Dev Stack

86 lines (78 loc) 2.42 kB
/** * Component Generator */ const componentExists = require('../utils/componentExists'); const path = require('path') /* , { type: 'confirm', name: 'wantMessages', default: true, message: 'Do you want i18n messages (i.e. will this component use text)?', } */ 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: 'list', name: 'purpose', message: 'Select the purpose of component', default: 'Content', choices: () => ['Content', 'Form', 'Layout', 'Control'], }, { 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', path: 'src/application/components/{{lowerCase purpose}}/{{properCase name}}/index.js', templateFile: data.type === 'ES6 Class' ? path.resolve(__dirname, 'es6.js.hbs') : path.resolve(__dirname, 'stateless.js.hbs'), abortOnFail: true, }, { type: 'add', path: 'src/application/components/{{lowerCase purpose}}/{{properCase name}}/tests/index.test.js', templateFile: path.resolve(__dirname, 'test.js.hbs'), abortOnFail: true, }]; // If they want a CSS file, add styles.css if (data.wantCSS) { actions.push({ type: 'add', path: 'src/application/components/{{lowerCase purpose}}/{{properCase name}}/styles.scss', templateFile: path.resolve(__dirname, 'styles.css.hbs'), abortOnFail: true, }); } // If they want a i18n messages file if (/*data.wantMessages*/false) { actions.push({ type: 'add', path: 'src/application/components/{{lowerCase purpose}}/{{properCase name}}/messages.js', templateFile: path.resolve(__dirname, 'messages.js.hbs'), abortOnFail: true, }); } return actions; }, };