Aurélien Georget bd91a2ef93 Add 'packages/strapi-plugin-settings-manager/' from commit 'cd241c14c6a6239bca279e7accd709ba58e87cc8'
git-subtree-dir: packages/strapi-plugin-settings-manager
git-subtree-mainline: 80aa83d8460c95366547e143c74bf79ea6ae69f8
git-subtree-split: cd241c14c6a6239bca279e7accd709ba58e87cc8
2017-01-15 20:14:40 +01:00

75 lines
2.0 KiB
JavaScript

/**
* 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?',
}, {
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',
path: '../../app/components/{{properCase name}}/index.js',
templateFile: data.type === 'ES6 Class' ? './component/es6.js.hbs' : './component/stateless.js.hbs',
abortOnFail: true,
}, {
type: 'add',
path: '../../app/components/{{properCase name}}/tests/index.test.js',
templateFile: './component/test.js.hbs',
abortOnFail: true,
}];
// If they want a CSS file, add styles.css
if (data.wantCSS) {
actions.push({
type: 'add',
path: '../../app/components/{{properCase name}}/styles.css',
templateFile: './component/styles.css.hbs',
abortOnFail: true,
});
}
// If they want a i18n messages file
if (data.wantMessages) {
actions.push({
type: 'add',
path: '../../app/components/{{properCase name}}/messages.js',
templateFile: './component/messages.js.hbs',
abortOnFail: true,
});
}
return actions;
},
};