mirror of
https://github.com/jeecgboot/jeecg-uniapp.git
synced 2025-10-17 08:13:57 +00:00
框架完善及功能新增
This commit is contained in:
42
vite-plugins/generateComponentTypes.ts
Normal file
42
vite-plugins/generateComponentTypes.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Plugin } from 'vite'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
export function generateComponentTypes(): Plugin {
|
||||
return {
|
||||
name: 'generate-component-types',
|
||||
async buildStart() {
|
||||
const componentsDir = path.resolve(process.cwd(), 'src/components')
|
||||
const dtsPath = path.resolve(process.cwd(), 'src/components/components.d.ts')
|
||||
|
||||
// Get immediate subdirectories only
|
||||
const directories = fs
|
||||
.readdirSync(componentsDir, { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map((dirent) => dirent.name)
|
||||
|
||||
// Generate type definitions only for valid components
|
||||
const typeDefinitions = directories
|
||||
.filter((dir) => {
|
||||
// Check if ComponentName/ComponentName.vue exists
|
||||
const componentFile = path.join(componentsDir, dir, `${dir}.vue`)
|
||||
return fs.existsSync(componentFile)
|
||||
})
|
||||
.map((dir) => {
|
||||
return `${dir}: typeof import('./${dir}/${dir}.vue')['default']`
|
||||
})
|
||||
|
||||
// Create the type definition file content
|
||||
const content = `declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
${typeDefinitions.join('\n')}
|
||||
}
|
||||
}
|
||||
|
||||
export {}`
|
||||
|
||||
// Write the type definition file
|
||||
fs.writeFileSync(dtsPath, content, 'utf-8')
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user