Files
dvcp_v2_webapp/bin/scanApps.js
aixianling 2275590461 feat(scanApps): 增加扫描 core 工程的功能
- 在 start 函数中添加了对 VUE_APP_CORE 环境变量的检查
- 如果 VUE_APP_CORE 存在,将 'packages/core' 添加到扫描范围中
2025-01-07 08:57:23 +08:00

38 lines
1.4 KiB
JavaScript

const {chalkTag, findApp, fs, fsExtra} = require("./tools");
const compiler = require('vue-template-compiler')
const getAppInfo = (file, apps) => {
if (/[\\\/](App[A-Z][^\\\/]+)\.vue$/g.test(file)) {
const name = file.replace(/.+[\\\/](App[^\\\/]+)\.vue$/, '$1'),
source = fs.readFileSync(file).toString(),
parsed = compiler.parseComponent(source),
script = parsed.script?.content || "",
label = script.match(/label:[^,]+/)?.[0]?.replace(/.+["']([^"']+).+/, '$1')
const paths = file.split(/[\\\/]/)
apps.push({
id: file.replace(/\.vue$/, '').replace(/[\\\/]/g, '_'),
label: label || name,
path: `/${file.replace(/\.vue$/, '').replace(/[\\\/]/g, '/')}`,
workspace: paths.at(0),
esm: file.replace(/[\\\/]/g, '/'),
name
})
}
}
const start = () => {
chalkTag.info("开始扫描库工程...")
const {VUE_APP_SCOPE, VUE_APP_CORE} = process.env
const list = []
let scanScope = ['packages', 'project']
if (VUE_APP_SCOPE) scanScope = [`project/${VUE_APP_SCOPE}`]
if (VUE_APP_CORE) scanScope.push('packages/core')
Promise.all(scanScope.map(e => findApp(e, app => getAppInfo(app, list)))).then(() => {
fsExtra.outputFile('examples/router/apps.js', `export default [${list.map(e => {
const {name, label, path, esm} = e
return `{name:"${name}",label:"${label}",path:"${path}",component:()=>import("@${esm}")}`
}).join(',\n')}]`)
chalkTag.done("扫描完毕")
})
}
start()