plopfile.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export default plop => {
  2. plop.setGenerator('domain', {
  3. description: '生成一个领域',
  4. prompts: [
  5. {
  6. type: 'input',
  7. name: 'name',
  8. message: '领域名称: '
  9. }
  10. ],
  11. actions: [
  12. {
  13. type: 'add',
  14. path: 'src/views/{{name}}/{{properCase name}}.vue',
  15. templateFile: 'plop-template/view.hbs'
  16. },
  17. {
  18. type: 'add',
  19. path: 'src/domain/{{name}}/api.ts',
  20. templateFile: 'plop-template/api.hbs'
  21. },
  22. {
  23. type: 'add',
  24. path: 'src/domain/{{name}}/service.ts',
  25. templateFile: 'plop-template/service.hbs'
  26. },
  27. {
  28. type: 'append',
  29. pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
  30. path: 'src/router/asyncRouter.ts',
  31. templateFile: 'plop-template/router.hbs'
  32. }
  33. ]
  34. })
  35. plop.setGenerator('micro', {
  36. description: '生成一个微服务',
  37. prompts: [
  38. {
  39. type: 'input',
  40. name: 'name',
  41. message: '微服务名称: '
  42. }
  43. ],
  44. actions: [
  45. {
  46. type: 'add',
  47. path: 'src/views/micro/{{properCase name}}.vue',
  48. templateFile: 'plop-template/micro.hbs'
  49. },
  50. {
  51. type: 'append',
  52. pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
  53. path: 'src/router/asyncRouter.ts',
  54. templateFile: 'plop-template/microRouter.hbs'
  55. }
  56. ]
  57. })
  58. plop.setHelper('upperCase', string => string.charAt(0).toUpperCase() + string.slice(1))
  59. }