prompt.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. const { notEmpty } = require('../utils.js')
  11. module.exports = {
  12. description: 'generate vue component',
  13. prompts: [{
  14. type: 'input',
  15. name: 'name',
  16. message: 'component name please',
  17. validate: notEmpty('name')
  18. },
  19. {
  20. type: 'checkbox',
  21. name: 'blocks',
  22. message: 'Blocks:',
  23. choices: [{
  24. name: '<template>',
  25. value: 'template',
  26. checked: true
  27. },
  28. {
  29. name: '<script>',
  30. value: 'script',
  31. checked: true
  32. },
  33. {
  34. name: 'style',
  35. value: 'style',
  36. checked: true
  37. }
  38. ],
  39. validate(value) {
  40. if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
  41. return 'Components require at least a <script> or <template> tag.'
  42. }
  43. return true
  44. }
  45. }
  46. ],
  47. actions: data => {
  48. const name = '{{properCase name}}'
  49. const actions = [{
  50. type: 'add',
  51. path: `src/components/${name}/index.vue`,
  52. templateFile: 'plop-templates/component/index.hbs',
  53. data: {
  54. name: name,
  55. template: data.blocks.includes('template'),
  56. script: data.blocks.includes('script'),
  57. style: data.blocks.includes('style')
  58. }
  59. }]
  60. return actions
  61. }
  62. }