plopfile.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. export default plop => {
  2. plop.setGenerator('module', {
  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: 'view',
  22. value: 'view',
  23. checked: true
  24. },
  25. {
  26. name: 'router',
  27. value: 'router',
  28. checked: true
  29. }
  30. ]
  31. }
  32. ],
  33. actions: data => {
  34. const actions = []
  35. data.type.forEach(type => {
  36. if (type === 'router') {
  37. actions.push({
  38. type: 'append',
  39. pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
  40. path: 'src/router/asyncRouter.ts',
  41. templateFile: 'plop-template/router.hbs'
  42. })
  43. } else if (type === 'view') {
  44. actions.push({
  45. type: 'add',
  46. path: 'src/views/{{camelCase name}}/{{pascalCase name}}.vue',
  47. templateFile: `plop-template/${type}.hbs`
  48. })
  49. } else {
  50. actions.push({
  51. type: 'add',
  52. path: `src/api/{{camelCase name}}.ts`,
  53. templateFile: `plop-template/${type}.hbs`
  54. })
  55. }
  56. })
  57. return actions
  58. }
  59. })
  60. plop.setGenerator('micro', {
  61. description: '生成一个微服务',
  62. prompts: [
  63. {
  64. type: 'input',
  65. name: 'name',
  66. message: '微服务名称: '
  67. }
  68. ],
  69. actions: [
  70. {
  71. type: 'add',
  72. path: 'src/views/micro/{{pascalCase name}}.vue',
  73. templateFile: 'plop-template/micro.hbs'
  74. },
  75. {
  76. type: 'append',
  77. pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
  78. path: 'src/router/asyncRouter.ts',
  79. templateFile: 'plop-template/microRouter.hbs'
  80. }
  81. ]
  82. })
  83. plop.setHelper('upperCase', string => string.charAt(0).toUpperCase() + string.slice(1))
  84. }