refactor: add plop tool
parent
e0297f4a9b
commit
28530b2744
@ -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
|
||||
}
|
||||
}
|
||||
@ -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>
|
||||
@ -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
Load Diff
Loading…
Reference in New Issue