Browse Source

增加plop

tongshangming 1 year ago
parent
commit
168be6057d
6 changed files with 675 additions and 2 deletions
  1. 3 1
      package.json
  2. 21 0
      plop-template/api.hbs
  3. 27 0
      plop-template/service.hbs
  4. 25 0
      plopfile.js
  5. 598 1
      pnpm-lock.yaml
  6. 1 0
      tsconfig.json

+ 3 - 1
package.json

@@ -8,7 +8,8 @@
     "preview": "vite preview --port 4173",
     "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"
+    "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
+    "domain": "plop domain"
   },
   "dependencies": {
     "@element-plus/icons-vue": "^2.1.0",
@@ -46,6 +47,7 @@
     "eslint": "^8.54.0",
     "eslint-plugin-vue": "^9.18.1",
     "npm-run-all": "^4.1.5",
+    "plop": "^4.0.1",
     "prettier": "^3.1.0",
     "sass": "^1.69.5",
     "typescript": "~5.3.2",

+ 21 - 0
plop-template/api.hbs

@@ -0,0 +1,21 @@
+import request from '@/utils/request'
+
+export function create(data: any) {
+  return request.post('/create{{upperCase name}}', data)
+}
+
+export function update(data: any) {
+  return request.post('/update{{upperCase name}}', data)
+}
+
+export function del(data: any) {
+  return request.post('/delete{{upperCase name}}', data)
+}
+
+export function find(data: any) {
+  return request.get('/find{{upperCase name}}', data)
+}
+
+export function get(data?: any) {
+  return request.get('/get{{upperCase name}}List', data)
+}

+ 27 - 0
plop-template/service.hbs

@@ -0,0 +1,27 @@
+import * as api from './api'
+
+export const use{{upperCase name}}Service = () => {
+  const create = (data: any) => {
+    return api.create(data)
+  }
+  const update = (data: any) => {
+    return api.update(data)
+  }
+  const del = (data: any) => {
+    return api.del(data)
+  }
+  const find = (data: any) => {
+    return api.find(data)
+  }
+  const get = (data: any) => {
+    return api.get(data)
+  }
+
+  return {
+    create,
+    update,
+    del,
+    get,
+    find
+  }
+}

+ 25 - 0
plopfile.js

@@ -0,0 +1,25 @@
+export default plop => {
+  plop.setGenerator('domain', {
+    description: '生成一个领域',
+    prompts: [
+      {
+        type: 'input',
+        name: 'name',
+        message: 'domain name: '
+      }
+    ],
+    actions: [
+      {
+        type: 'add',
+        path: 'src/domain/{{name}}/api.ts',
+        templateFile: 'plop-template/api.hbs'
+      },
+      {
+        type: 'add',
+        path: 'src/domain/{{name}}/service.ts',
+        templateFile: 'plop-template/service.hbs'
+      }
+    ]
+  })
+  plop.setHelper('upperCase', string => string.charAt(0).toUpperCase() + string.slice(1))
+}

File diff suppressed because it is too large
+ 598 - 1
pnpm-lock.yaml


+ 1 - 0
tsconfig.json

@@ -6,6 +6,7 @@
     "src/**/*.vue"
   ],
   "compilerOptions": {
+    "module": "ESNext",
     "baseUrl": ".",
     "paths": {
       "@/*": [

Some files were not shown because too many files changed in this diff