prompt.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. };