niucloud/uni-app/scripts/generate-diy-registry.cjs
wangchen14709853322 5ed9a0ba81 v2.0-beta-20260626
v2框架公测版测试流程请看v2.0-beta.md
2026-07-01 12:25:30 +08:00

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 }