Browse Source

perf: add plop

kailong321200875 3 years ago
parent
commit
fa54a1704f

+ 1 - 1
package.json

@@ -24,7 +24,7 @@
     "lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js",
     "lint:pretty": "pretty-quick --staged",
     "postinstall": "husky install",
-    "plop": "plop"
+    "p": "plop"
   },
   "dependencies": {
     "@iconify/iconify": "^2.2.1",

+ 11 - 0
plop/component/component.hbs

@@ -0,0 +1,11 @@
+<script setup lang="ts">
+import { useDesign } from '@/hooks/web/useDesign'
+
+const { getPrefixCls } = useDesign()
+
+const prefixCls = getPrefixCls('{{ name }}')
+</script>
+
+<template>
+  <div :class="`${prefixCls}-{{ name }}`">{{ upperFirstName }}</div>
+</template>

+ 3 - 0
plop/component/index.hbs

@@ -0,0 +1,3 @@
+import {{ upperFirstName }} from './src/{{ upperFirstName }}.vue'
+
+export { {{ upperFirstName }} }

+ 38 - 0
plop/component/prompt.js

@@ -0,0 +1,38 @@
+const toUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1)
+
+module.exports = {
+  description: 'Create vue component',
+  prompts: [
+    {
+      type: 'input',
+      name: 'name',
+      message: '请输入组件名称(Please enter the component name)'
+    }
+  ],
+  actions: (data) => {
+    const { name } = data
+    const upperFirstName = toUpperCase(name)
+
+    const actions = []
+    if (name) {
+      actions.push({
+        type: 'add',
+        path: `./src/components/${upperFirstName}/src/${upperFirstName}.vue`,
+        templateFile: './plop/component/component.hbs',
+        data: {
+          name,
+          upperFirstName
+        }
+      }, {
+        type: 'add',
+        path: `./src/components/${upperFirstName}/index.ts`,
+        templateFile: './plop/component/index.hbs',
+        data: {
+          upperFirstName
+        }
+      })
+    }
+
+    return actions
+  }
+}

+ 0 - 38
plop/generator/newModule.js

@@ -1,38 +0,0 @@
-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
-  }
-}

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

@@ -1,20 +0,0 @@
-<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>

+ 37 - 0
plop/view/prompt.js

@@ -0,0 +1,37 @@
+const toUpperCase = (str) => str.charAt(0).toUpperCase() + str.slice(1)
+
+module.exports = {
+  description: 'Create vue view',
+  prompts: [
+    {
+      type: 'input',
+      name: 'path',
+      message: '请输入路径(Please enter a path)',
+      default: 'views'
+    },
+    {
+      type: 'input',
+      name: 'name',
+      message: '请输入模块名称(Please enter module name)'
+    }
+  ],
+  actions: (data) => {
+    const { name, path } = data
+    const upperFirstName = toUpperCase(name)
+
+    const actions = []
+    if (name) {
+      actions.push({
+        type: 'add',
+        path: `./src/${path}/${upperFirstName}.vue`,
+        templateFile: './plop/view/view.hbs',
+        data: {
+          name,
+          upperFirstName
+        }
+      })
+    }
+
+    return actions
+  }
+}

+ 7 - 0
plop/view/view.hbs

@@ -0,0 +1,7 @@
+<script setup lang="ts">
+import { ContentWrap } from '@/components/ContentWrap'
+</script>
+
+<template>
+  <ContentWrap title="{{ upperFirstName }}"> {{ name }} </ContentWrap>
+</template>

+ 5 - 5
plopfile.js

@@ -1,7 +1,7 @@
-const createNewModule = require('./plop/generator/newModule')
+const viewGenerator = require('./plop/view/prompt.js')
+const componentGenerator = require('./plop/component/prompt.js')
 
-function Cli(plop) {
-  plop.setGenerator('newModule', createNewModule)
+module.exports = function (plop) {
+  plop.setGenerator('view', viewGenerator)
+  plop.setGenerator('component', componentGenerator)
 }
-
-module.exports = Cli

File diff suppressed because it is too large
+ 71 - 462
pnpm-lock.yaml


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