Skip to content

Commit

Permalink
perf: add plop
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Apr 8, 2022
1 parent 47edf7b commit fa54a17
Show file tree
Hide file tree
Showing 10 changed files with 882 additions and 920 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions 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 changes: 3 additions & 0 deletions plop/component/index.hbs
@@ -0,0 +1,3 @@
import {{ upperFirstName }} from './src/{{ upperFirstName }}.vue'

export { {{ upperFirstName }} }
38 changes: 38 additions & 0 deletions 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
}
}
38 changes: 0 additions & 38 deletions plop/generator/newModule.js

This file was deleted.

20 changes: 0 additions & 20 deletions plop/template/newModule/index.hbs

This file was deleted.

37 changes: 37 additions & 0 deletions 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 changes: 7 additions & 0 deletions 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>
10 changes: 5 additions & 5 deletions 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

0 comments on commit fa54a17

Please sign in to comment.