prompt.js 1.4 KB

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