mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2026-08-14 16:58:38 +00:00
55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
/**
|
|
* 扫描 DIY 微页面目录 → .build/diy-component-registry.json + .build/diy-component-registry.generated.ts
|
|
*/
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const { ROOT, BUILD_DIR, listAddonKeys } = require('./addon-utils.cjs')
|
|
const { scanAllDiyComponents } = require('./diy-component-scan.cjs')
|
|
|
|
const OUT_JSON = path.join(BUILD_DIR, 'diy-component-registry.json')
|
|
const OUT_TS = path.join(BUILD_DIR, 'diy-component-registry.generated.ts')
|
|
|
|
function generateDiyRegistry(options = {}) {
|
|
const addonKeys = options.addonKeys || listAddonKeys()
|
|
const { app, addon, all } = scanAllDiyComponents({ addonKeys })
|
|
|
|
const payload = {
|
|
version: 2,
|
|
generatedAt: new Date().toISOString(),
|
|
appCount: app.length,
|
|
addonCount: addon.length,
|
|
components: all
|
|
}
|
|
|
|
fs.mkdirSync(BUILD_DIR, { recursive: true })
|
|
fs.writeFileSync(OUT_JSON, JSON.stringify(payload, null, 2), 'utf-8')
|
|
|
|
const tsBody = `/* AUTO-GENERATED by generate-diy-registry.cjs — do not edit */
|
|
export interface DiyComponentMeta {
|
|
vueComponentName: string
|
|
scope: 'app' | 'addon'
|
|
folder: string
|
|
addonKey?: string
|
|
scrollBool?: boolean
|
|
formRef?: boolean
|
|
}
|
|
|
|
export const DIY_COMPONENT_REGISTRY: DiyComponentMeta[] = ${JSON.stringify(all, null, 4)} as DiyComponentMeta[]
|
|
|
|
export const DIY_COMPONENT_MAP: Record<string, DiyComponentMeta> = {
|
|
${all.map((e) => ` '${e.vueComponentName}': ${JSON.stringify(e)}`).join(',\n')}
|
|
}
|
|
`
|
|
fs.writeFileSync(OUT_TS, tsBody, 'utf-8')
|
|
|
|
console.log(
|
|
`[generate-diy-registry] ${all.length} components (app ${app.length}, addon ${addon.length}) -> ${path.relative(ROOT, OUT_JSON)}`
|
|
)
|
|
}
|
|
|
|
if (require.main === module) {
|
|
generateDiyRegistry()
|
|
}
|
|
|
|
module.exports = { generateDiyRegistry, OUT_JSON, OUT_TS }
|