-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-components.js
More file actions
33 lines (26 loc) · 1.21 KB
/
gen-components.js
File metadata and controls
33 lines (26 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { join } from 'node:path/posix'
import { loadFile, writeFile } from 'magicast'
import { findExports, loadURL, resolveModuleExportNames, resolvePath } from 'mlly'
import { writeFile as $_writeFile, exists } from 'void-fs'
async function resolveModuleExportComponents(id) {
const url = await resolvePath(id)
const code = await loadURL(url)
const exports = findExports(code)
return exports
.filter((item) => /^[A-Z]/.test(item.name))
.map((item) => ({ filePath: join(id, item.specifier), name: item.name }))
}
const filename = 'src/config.ts'
if (!(await exists(filename))) {
await $_writeFile(filename, '')
}
const mod = await loadFile(filename)
const arco = await resolveModuleExportComponents('@arco-design/web-vue/es')
const arcoIcon = await resolveModuleExportComponents('@arco-design/web-vue/es/icon')
const vrxArco = await resolveModuleExportNames('@vrx-arco/pro-components')
const vrxArcoColorPicker = await resolveModuleExportNames('@vrx-arco/color-picker')
mod.exports.arco = arco
mod.exports.arcoIcon = arcoIcon
mod.exports.vrxArco = vrxArco.filter((key) => /^[A-Z]/.test(key))
mod.exports.vrxArcoColorPicker = vrxArcoColorPicker.filter((key) => /^[A-Z]/.test(key))
await writeFile(mod, filename)