plopfile.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. export default plop => {
  2. plop.setGenerator('domain', {
  3. description: '生成一个领域',
  4. prompts: [
  5. {
  6. type: 'input',
  7. name: 'name',
  8. message: '领域名称: '
  9. },
  10. {
  11. type: 'checkbox',
  12. name: 'type',
  13. message: '勾选需要生成的模板: ',
  14. choices: [
  15. {
  16. name: 'api',
  17. value: 'api',
  18. checked: true
  19. },
  20. {
  21. name: 'entity',
  22. value: 'entity',
  23. checked: true
  24. },
  25. {
  26. name: 'service',
  27. value: 'service',
  28. checked: true
  29. },
  30. {
  31. name: 'view',
  32. value: 'view',
  33. checked: true
  34. },
  35. {
  36. name: 'router',
  37. value: 'router',
  38. checked: true
  39. }
  40. ]
  41. }
  42. ],
  43. actions: data => {
  44. const actions = []
  45. data.type.forEach(type => {
  46. if (type === 'router') {
  47. actions.push({
  48. type: 'append',
  49. pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
  50. path: 'src/router/asyncRouter.ts',
  51. templateFile: 'plop-template/router.hbs'
  52. })
  53. } else if (type === 'view') {
  54. actions.push({
  55. type: 'add',
  56. path: 'src/views/{{camelCase name}}/{{pascalCase name}}.vue',
  57. templateFile: `plop-template/${type}.hbs`
  58. })
  59. } else {
  60. actions.push({
  61. type: 'add',
  62. path: `src/domain/{{camelCase name}}/${type}.ts`,
  63. templateFile: `plop-template/${type}.hbs`
  64. })
  65. }
  66. })
  67. return actions
  68. }
  69. })
  70. plop.setGenerator('micro', {
  71. description: '生成一个微服务',
  72. prompts: [
  73. {
  74. type: 'input',
  75. name: 'name',
  76. message: '微服务名称: '
  77. }
  78. ],
  79. actions: [
  80. {
  81. type: 'add',
  82. path: 'src/views/micro/{{pascalCase name}}.vue',
  83. templateFile: 'plop-template/micro.hbs'
  84. },
  85. {
  86. type: 'append',
  87. pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
  88. path: 'src/router/asyncRouter.ts',
  89. templateFile: 'plop-template/microRouter.hbs'
  90. }
  91. ]
  92. })
  93. plop.setHelper('upperCase', string => string.charAt(0).toUpperCase() + string.slice(1))
  94. }