12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- export default plop => {
- plop.setGenerator('module', {
- description: '生成一个模块',
- prompts: [
- {
- type: 'input',
- name: 'name',
- message: '模块名称: '
- },
- {
- type: 'checkbox',
- name: 'type',
- message: '勾选需要生成的模板: ',
- choices: [
- {
- name: 'api',
- value: 'api',
- 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/api/{{camelCase name}}.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))
- }
|