| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- export default plop => {
- plop.setGenerator('domain', {
- description: '生成一个领域',
- prompts: [
- {
- type: 'input',
- name: 'name',
- message: '领域名称: '
- },
- {
- type: 'checkbox',
- name: 'type',
- message: '勾选需要生成的模板: ',
- choices: [
- {
- name: 'api',
- value: 'api',
- checked: true
- },
- {
- name: 'entity',
- value: 'entity',
- checked: true
- },
- {
- name: 'service',
- value: 'service',
- checked: true
- },
- {
- name: 'view',
- value: 'view',
- checked: true
- },
- {
- name: 'router',
- value: 'router',
- checked: true
- }
- ]
- }
- ],
- actions: data => {
- const actions = []
- data.type.forEach(type => {
- if (type === 'router') {
- actions.push({
- type: 'append',
- pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
- path: 'src/router/asyncRouter.ts',
- templateFile: 'plop-template/router.hbs'
- })
- } else if (type === 'view') {
- actions.push({
- type: 'add',
- path: 'src/views/{{camelCase name}}/{{pascalCase name}}.vue',
- templateFile: `plop-template/${type}.hbs`
- })
- } else {
- actions.push({
- type: 'add',
- path: `src/domains/{{camelCase name}}/${type}.ts`,
- templateFile: `plop-template/${type}.hbs`
- })
- }
- })
- return actions
- }
- })
- plop.setGenerator('micro', {
- description: '生成一个微服务',
- prompts: [
- {
- type: 'input',
- name: 'name',
- message: '微服务名称: '
- }
- ],
- actions: [
- {
- type: 'add',
- path: 'src/views/micro/{{pascalCase name}}.vue',
- templateFile: 'plop-template/micro.hbs'
- },
- {
- type: 'append',
- pattern: /(?=(\/\/ -- APPEND HERE --))/gi,
- path: 'src/router/asyncRouter.ts',
- templateFile: 'plop-template/microRouter.hbs'
- }
- ]
- })
- plop.setHelper('upperCase', string => string.charAt(0).toUpperCase() + string.slice(1))
- }
|