prompt.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { notEmpty } = require('../utils.js')
  2. module.exports = {
  3. description: 'generate a view',
  4. prompts: [{
  5. type: 'input',
  6. name: 'name',
  7. message: 'view 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 'View require at least a <script> or <template> tag.'
  33. }
  34. return true
  35. }
  36. }
  37. ],
  38. actions: data => {
  39. const name = '{{name}}'
  40. const actions = [{
  41. type: 'add',
  42. path: `src/views/${name}/index.vue`,
  43. templateFile: 'plop-templates/view/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. }