prompt.js 1.2 KB

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