perf: add plop

This commit is contained in:
kailong321200875 2022-04-08 19:54:59 +08:00
parent 47edf7b270
commit fa54a1704f
10 changed files with 800 additions and 838 deletions

View File

@ -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",

View File

@ -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
plop/component/index.hbs Normal file
View File

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

38
plop/component/prompt.js Normal file
View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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
plop/view/prompt.js Normal file
View File

@ -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
plop/view/view.hbs Normal file
View File

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

View File

@ -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 Load Diff