prompt.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const notEmpty = (name) => {
  2. return (v) => {
  3. if (!v || v.trim === '') return `${name}为必填项`
  4. else return true
  5. }
  6. }
  7. export default {
  8. description: '创建curd',
  9. prompts: [
  10. {
  11. type: 'input',
  12. name: 'name',
  13. message: '请输入view名称,然后点击回车',
  14. validate: notEmpty('name'),
  15. },
  16. ],
  17. actions: () => {
  18. ///const pathCaseName = '{{ pathCase name }}'
  19. const properCaseName = '{{ properCase name }}'
  20. const camelCaseName = '{{ camelCase name }}'
  21. return [
  22. {
  23. type: 'add',
  24. path: `src/views/goods/${properCaseName}.vue`,
  25. templateFile: './plop-template/curd/index.hbs',
  26. },
  27. {
  28. type: 'add',
  29. path: `src/views/goods/vabAutoComponents/${properCaseName}Edit.vue`,
  30. templateFile: './plop-template/curd/edit.hbs',
  31. },
  32. {
  33. type: 'add',
  34. path: `mock/controller/${camelCaseName}.ts`,
  35. templateFile: './plop-template/curd/mock.hbs',
  36. },
  37. {
  38. type: 'add',
  39. path: `src/api/${camelCaseName}.ts`,
  40. templateFile: './plop-template/curd/api.hbs',
  41. },
  42. ]
  43. },
  44. }