Kaynağa Gözat

plop增加微服务

tongshangming 1 yıl önce
ebeveyn
işleme
11f9727174
4 değiştirilmiş dosya ile 62 ekleme ve 2 silme
  1. 2 1
      package.json
  2. 25 0
      plop-template/micro.hbs
  3. 10 0
      plop-template/microRouter.hbs
  4. 25 1
      plopfile.js

+ 2 - 1
package.json

@@ -9,7 +9,8 @@
     "build-only": "vite build",
     "type-check": "vue-tsc --noEmit",
     "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
-    "domain": "plop domain"
+    "domain": "plop domain",
+    "micro": "plop micro"
   },
   "dependencies": {
     "@element-plus/icons-vue": "^2.1.0",

+ 25 - 0
plop-template/micro.hbs

@@ -0,0 +1,25 @@
+<script setup lang="ts">
+import { useMainMicro } from '@/hooks/useMainMicro'
+import { useUserStore } from '@/stores/user'
+
+const userStore = useUserStore()
+
+const microName = '{{name}}'
+const { micro, initWatch } = useMainMicro(microName)
+initWatch()
+
+const route = useRoute()
+</script>
+
+<template>
+  <WujieVue
+    width="100%"
+    height="100%"
+    :name="microName"
+    :url="micro.url + route.path"
+    :sync="true"
+    :props="{ token: userStore.token }"
+  ></WujieVue>
+</template>
+
+<style lang="scss" scoped></style>

+ 10 - 0
plop-template/microRouter.hbs

@@ -0,0 +1,10 @@
+  {
+    path: '/{{name}}',
+    name: '{{name}}',
+    component: () => import('@/views/micro/{{properCase name}}.vue'),
+    meta: {
+      title: '',
+      icon: ''
+    }
+  },
+  

+ 25 - 1
plopfile.js

@@ -5,7 +5,7 @@ export default plop => {
       {
         type: 'input',
         name: 'name',
-        message: 'domain name: '
+        message: '领域名称: '
       }
     ],
     actions: [
@@ -32,5 +32,29 @@ export default plop => {
       }
     ]
   })
+
+  plop.setGenerator('micro', {
+    description: '生成一个微服务',
+    prompts: [
+      {
+        type: 'input',
+        name: 'name',
+        message: '微服务名称: '
+      }
+    ],
+    actions: [
+      {
+        type: 'add',
+        path: 'src/views/micro/{{properCase 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))
 }