mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-14 04:33:41 +08:00
v4.3.0
This commit is contained in:
17
admin/plop-templates/component/index.hbs
Executable file
17
admin/plop-templates/component/index.hbs
Executable file
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
{{#if isGlobal}}
|
||||
defineOptions({
|
||||
name: '{{ properCase name }}',
|
||||
})
|
||||
{{/if}}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<!-- 布局 -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
// 样式
|
||||
</style>
|
||||
65
admin/plop-templates/component/prompt.js
Executable file
65
admin/plop-templates/component/prompt.js
Executable file
@@ -0,0 +1,65 @@
|
||||
import fs from 'node:fs'
|
||||
|
||||
function getFolder(path) {
|
||||
const components = []
|
||||
const files = fs.readdirSync(path)
|
||||
files.forEach((item) => {
|
||||
const stat = fs.lstatSync(`${path}/${item}`)
|
||||
if (stat.isDirectory() === true && item !== 'components') {
|
||||
components.push(`${path}/${item}`)
|
||||
components.push(...getFolder(`${path}/${item}`))
|
||||
}
|
||||
})
|
||||
return components
|
||||
}
|
||||
|
||||
export default {
|
||||
description: '创建组件',
|
||||
prompts: [
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'isGlobal',
|
||||
message: '是否为全局组件',
|
||||
default: false,
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'path',
|
||||
message: '请选择组件创建目录',
|
||||
choices: getFolder('src/views'),
|
||||
when: (answers) => {
|
||||
return !answers.isGlobal
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: '请输入组件名称',
|
||||
validate: (v) => {
|
||||
if (!v || v.trim === '') {
|
||||
return '组件名称不能为空'
|
||||
}
|
||||
else {
|
||||
return true
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: (data) => {
|
||||
let path = ''
|
||||
if (data.isGlobal) {
|
||||
path = 'src/components/{{properCase name}}/index.vue'
|
||||
}
|
||||
else {
|
||||
path = `${data.path}/components/{{properCase name}}/index.vue`
|
||||
}
|
||||
const actions = [
|
||||
{
|
||||
type: 'add',
|
||||
path,
|
||||
templateFile: 'plop-templates/component/index.hbs',
|
||||
},
|
||||
]
|
||||
return actions
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user