2
0

prompt.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const { notEmpty } = require('../utils.js')
  2. module.exports = {
  3. description: 'generate vue component',
  4. prompts: [{
  5. type: 'input',
  6. name: 'name',
  7. message: 'component name please',
  8. validate: notEmpty('name')
  9. },
  10. {
  11. type: 'checkbox',
  12. name: 'blocks',
  13. message: 'Blocks:',
  14. choices: [{
  15. name: '<template>',
  16. value: 'template',
  17. checked: true
  18. },
  19. {
  20. name: '<script>',
  21. value: 'script',
  22. checked: true
  23. },
  24. {
  25. name: 'style',
  26. value: 'style',
  27. checked: true
  28. }
  29. ],
  30. validate(value) {
  31. if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
  32. return 'Components require at least a <script> or <template> tag.'
  33. }
  34. return true
  35. }
  36. }
  37. ],
  38. actions: data => {
  39. const name = '{{properCase name}}'
  40. const actions = [{
  41. type: 'add',
  42. path: `src/components/${name}/index.vue`,
  43. templateFile: 'plop-templates/component/index.hbs',
  44. data: {
  45. name: name,
  46. template: data.blocks.includes('template'),
  47. script: data.blocks.includes('script'),
  48. style: data.blocks.includes('style')
  49. }
  50. }]
  51. return actions
  52. }
  53. }