Browse Source

refactor: add plop tool

niyonggui 3 years ago
parent
commit
28530b2744
5 changed files with 2953 additions and 1 deletions
  1. 3 1
      package.json
  2. 38 0
      plop/generator/newModule.js
  3. 11 0
      plop/template/newModule/index.hbs
  4. 7 0
      plopfile.js
  5. 2894 0
      pnpm-lock.yaml

+ 3 - 1
package.json

@@ -23,7 +23,8 @@
     "lint:style": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
     "lint:style": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
     "lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
     "lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
     "lint:pretty": "pretty-quick --staged",
     "lint:pretty": "pretty-quick --staged",
-    "postinstall": "husky install"
+    "postinstall": "husky install",
+    "plop": "plop"
   },
   },
   "dependencies": {
   "dependencies": {
     "@iconify/iconify": "^2.1.2",
     "@iconify/iconify": "^2.1.2",
@@ -43,6 +44,7 @@
     "nprogress": "^0.2.0",
     "nprogress": "^0.2.0",
     "pinia": "^2.0.12",
     "pinia": "^2.0.12",
     "pinia-plugin-persist": "^1.0.0",
     "pinia-plugin-persist": "^1.0.0",
+    "plop": "^3.0.5",
     "qrcode": "^1.5.0",
     "qrcode": "^1.5.0",
     "qs": "^6.10.3",
     "qs": "^6.10.3",
     "vue": "3.2.31",
     "vue": "3.2.31",

+ 38 - 0
plop/generator/newModule.js

@@ -0,0 +1,38 @@
+const PAGE_PATH = 'src/views/'
+
+const toUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1)
+
+module.exports = {
+  description: 'Create a new Module',
+  prompts: [
+    {
+      type: 'input',
+      name: 'pagePath',
+      message: 'What is the path to the page?'
+    },
+    {
+      type: 'input',
+      name: 'moduleName',
+      message: 'What is the name of the module?'
+    }
+  ],
+  actions: (data) => {
+    const { pagePath, moduleName } = data
+    const upperFirstName = toUpperCase(moduleName)
+
+    const actions = []
+    if (moduleName) {
+      actions.push({
+        type: 'add',
+        path: `${PAGE_PATH}${pagePath}/${moduleName}/index.vue`,
+        templateFile: 'plop/template/newModule/index.hbs',
+        data: {
+          name: moduleName,
+          upperFirstName
+        }
+      })
+    }
+
+    return actions
+  }
+}

+ 11 - 0
plop/template/newModule/index.hbs

@@ -0,0 +1,11 @@
+<script setup lang='ts'>
+  import { ElButton } from 'element-plus' import { useI18n } from '@/hooks/web/useI18n' import { ref
+  } from 'vue' defineOptions({ name: '{{upperFirstName}}', components: { ElButton }, setup() {} })
+  const { t } = useI18n()
+</script>
+
+<template>
+  <ContentWrap>
+    <ElButton type='primary'>{{name}}</ElButton>
+  </ContentWrap>
+</template>

+ 7 - 0
plopfile.js

@@ -0,0 +1,7 @@
+const createNewModule = require('./plop/generator/newModule')
+
+function Cli(plop) {
+  plop.setGenerator('newModule', createNewModule)
+}
+
+module.exports = Cli

File diff suppressed because it is too large
+ 2894 - 0
pnpm-lock.yaml


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