mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2026-11-18 19:10:29 +00:00
1. 云编译任务系统的全面升级。 整个云编译服务器使用高性能开发语言GO全面重建整个的任务,排队体系。框架的用户,全面引入了任务管理系统设计架构。把云编译,在线升级,插件打包,构建发布版本,小程序一键上传同步等流程,高度抽象为任务系统。整个任务的执行过程会详细记录下来,支持每个过程的原始执行情况回溯。每个步骤,执行错误,加入重试与取消机制。对于网络拥堵,网络暂时断开造成的上传下载过程中不可预测的中断开始支持断点续传重续。同时,云编译支持前端驱动,与后端Redis队列驱动两种模式。前端驱动模式为轻量模式,需要页面的持续保持任务的进行。Redis队列驱动模式,支持任务后台运行,在任务后台运行的同时,同步进行业务系统的正常使用 2. 多端口,自定义扩展端口的真正支持。历史版本中,在addon.info中,已经设计有自定义端口功能,但是在整个的云编译服务器,没有真正支持自定义端口的编译与部署。在本次版本中,服务器端,以及框架已经全部支持自定义端口使能。addon.info 文件中定义的端口,会在编译端口自动枚举展示。云编译过程,会按照设定的命令自动执行,并完成部署。同时,云编译支持框架独立编译,插件组合编译等,方便开发者使用。 3. 环境检测与数据库修复,在本版本中全面引入。数据库修复,支持全量比对,表比对,插件比对,字符集编码比对,数据库修复功能,可以按照插件比对出缺失字段,并通过一键修复按钮完成数据库的修复。对于第三方插件中数据库表与框架自身不同的情况,系统会自动修正并正确执行SQL脚本。 4. 补丁管理也在本版本中实现,对于小问题,及时问题的处理,会发布小版本补丁。用户可以及时下载补丁,实时完成系统缺漏的修复。 5. 菜单系统,加入了导入菜单,导出菜单功能。niucloud开发团队全力为开发者考虑,本版本导入导出菜单可以按照插件,或者整个框架把菜单结构导出为json格式。 6. 构建版本在本次升级新加入。构建版本可以把云编译及版本构建的版本发布过程保留下来。 7. 插件校验和框架系统校验。在本版本中全面引入。支持对插件和框架进行全面校验比对。支持一键修复二开或者异常代码修复。 8. 存储设置在本版本全面优化,支持新增多种不同存储厂商的配置,并支持在不同配置中切换使用。 9. 运营面板在本次升级中植入。运营面板相当于为应用和插件加入了admin端的管理入口。本次版本开放此功能,为开发者开发admin端口功能提供了基础。我们官方在本次版本中同步发布官方客服插件,在admin端加入了平台客服的演示案例,供大家感受学习。 10. 全面优化了admin端的界面风格,加入了新的站点端默认风格。框架内置Vben Admin 前端框架。其实niucloud优秀的架构设计,运行速度并不慢,加入Vben Admin后,页面的切换效果会让用户感受到更加的丝滑与现代。 11. 前端顶部轮播组件,加入了返回首页按钮。 装修后,完美支持美团,饿了么那种模块与主模块的完美切换。 12. 小程序编译结构进行了优化,整个运行的速度更加快速。
228 lines
8.1 KiB
JavaScript
228 lines
8.1 KiB
JavaScript
/**
|
||
* uni-app 插件构建公共工具
|
||
*/
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
const ROOT = path.resolve(__dirname, '..')
|
||
const ADDON_DIR = path.join(ROOT, 'src', 'addon')
|
||
const PAGES_JSON = path.join(ROOT, 'src', 'pages.json')
|
||
const BUILD_DIR = path.join(ROOT, '.build')
|
||
/** 分构建桥接层:addon 页面桥接 + 组件 stub(原 src/_bridge) */
|
||
const BRIDGE_DIR = path.join(BUILD_DIR, 'bridges')
|
||
const BRIDGE_ADDON_ROOT = path.join(BRIDGE_DIR, 'addon')
|
||
const BRIDGE_STUB_ROOT = path.join(BRIDGE_DIR, 'component-stubs')
|
||
const SKIP_ADDON_DIRS = new Set(['components'])
|
||
|
||
function stripJsonComments(text) {
|
||
return text
|
||
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||
.replace(/^(\s*)\/\/.*$/gm, '$1') // 移除行首注释(保留缩进)
|
||
.replace(/^(\s*),\s*$/gm, '$1') // 移除孤立逗号行(保留缩进)
|
||
.replace(/,\s*\/\/.*$/gm, ',') // 移除行内注释 "val", // comment → "val",
|
||
.replace(/,\s*([}\]])/g, '$1') // 移除尾部逗号
|
||
.replace(/,\s*,/g, ',') // 合并连续逗号
|
||
}
|
||
|
||
function parsePagesJson() {
|
||
const raw = stripJsonComments(fs.readFileSync(PAGES_JSON, 'utf-8'))
|
||
return JSON.parse(raw)
|
||
}
|
||
|
||
/**
|
||
* 基于 pages.json 中的 // {KEY}_PAGE_BEGIN ... // {KEY}_PAGE_END 注释区块,
|
||
* 以「注释声明」作为插件分包归属的权威来源(而非 root 命名),通用且无需写死。
|
||
*
|
||
* 实现:
|
||
* 1. 按行扫描原始文本,记录每个 KEY 对应的 BEGIN/END 行号区间;
|
||
* 2. 解析 JSON(保留 root 的所在行号),将每个 addon 分包 root 映射到所属 KEY。
|
||
*
|
||
* @returns {{ [key: string]: string[] }} key -> 该插件区块内所有 addon 分包 root
|
||
*/
|
||
function parseAddonBoundaries() {
|
||
if (!fs.existsSync(PAGES_JSON)) return {}
|
||
const lines = fs.readFileSync(PAGES_JSON, 'utf-8').split(/\r?\n/)
|
||
|
||
// 1. 收集每个 KEY 的 BEGIN/END 行号
|
||
const ranges = {} // key -> { begin, end }
|
||
const beginRe = /^\s*\/\/\s*([A-Z0-9_]+)_PAGE_BEGIN\s*$/
|
||
const endRe = /^\s*\/\/\s*([A-Z0-9_]+)_PAGE_END\s*$/
|
||
lines.forEach((line, idx) => {
|
||
const lb = line.match(beginRe)
|
||
if (lb) {
|
||
ranges[lb[1]] = { begin: idx, end: -1 }
|
||
return
|
||
}
|
||
const le = line.match(endRe)
|
||
if (le) {
|
||
if (!ranges[le[1]]) ranges[le[1]] = { begin: -1, end: idx }
|
||
else ranges[le[1]].end = idx
|
||
}
|
||
})
|
||
|
||
// 2. 解析分包 root 并定位行号
|
||
const core = parsePagesJson()
|
||
const result = {}
|
||
const subs = core.subPackages || []
|
||
subs.forEach((sub) => {
|
||
const root = sub.root
|
||
if (!root || !root.startsWith('addon/')) return
|
||
// 通过文本定位该 root 所在行
|
||
let rootLine = -1
|
||
for (let i = 0; i < lines.length; i++) {
|
||
if (lines[i].includes(`"root"`) && lines[i].includes(root)) {
|
||
rootLine = i
|
||
break
|
||
}
|
||
}
|
||
if (rootLine < 0) return
|
||
// 3. 判断落在哪个 KEY 区间
|
||
let matchedKey = null
|
||
for (const key of Object.keys(ranges)) {
|
||
const r = ranges[key]
|
||
if (r.begin >= 0 && r.end >= 0 && rootLine > r.begin && rootLine < r.end) {
|
||
matchedKey = key
|
||
break
|
||
}
|
||
}
|
||
if (!matchedKey) return
|
||
const normalizedKey = matchedKey.toLowerCase()
|
||
if (!result[normalizedKey]) result[normalizedKey] = []
|
||
if (!result[normalizedKey].includes(root)) result[normalizedKey].push(root)
|
||
})
|
||
|
||
for (const key of Object.keys(result)) result[key].sort()
|
||
return result
|
||
}
|
||
|
||
function listAddonKeys() {
|
||
if (!fs.existsSync(ADDON_DIR)) return []
|
||
return fs.readdirSync(ADDON_DIR, { withFileTypes: true })
|
||
.filter((d) => d.isDirectory() && !SKIP_ADDON_DIRS.has(d.name))
|
||
.map((d) => d.name)
|
||
.sort()
|
||
}
|
||
|
||
function walkFiles(dir, filter, base = dir) {
|
||
const out = []
|
||
if (!fs.existsSync(dir)) return out
|
||
for (const name of fs.readdirSync(dir)) {
|
||
const full = path.join(dir, name)
|
||
const stat = fs.statSync(full)
|
||
if (stat.isDirectory()) {
|
||
out.push(...walkFiles(full, filter, base))
|
||
} else if (filter(full)) {
|
||
out.push(path.relative(base, full).replace(/\\/g, '/'))
|
||
}
|
||
}
|
||
return out
|
||
}
|
||
|
||
/** 从 pages.json 解析插件分包页面(addonKey 以 // {KEY}_PAGE_BEGIN 注释区块为准) */
|
||
function scanSubPackagePages() {
|
||
const pagesJson = parsePagesJson()
|
||
const boundaries = parseAddonBoundaries()
|
||
// root -> key 反查,便于 O(1) 命中
|
||
const rootToKey = {}
|
||
for (const key of Object.keys(boundaries)) {
|
||
for (const root of boundaries[key]) rootToKey[root] = key
|
||
}
|
||
const rows = []
|
||
for (const sub of pagesJson.subPackages || []) {
|
||
const root = sub.root
|
||
if (!root || !root.startsWith('addon/')) continue
|
||
// 优先用注释区块归属;无匹配则回退到 root 第二段(兼容非注释区块场景)
|
||
const addonKey = rootToKey[root] || root.split('/')[1]
|
||
if (!addonKey || SKIP_ADDON_DIRS.has(addonKey)) continue
|
||
for (const page of sub.pages || []) {
|
||
if (!page.path) continue
|
||
const importPath = `${root.replace(/^addon\//, '')}/${page.path}`
|
||
rows.push({
|
||
addonKey,
|
||
root,
|
||
path: page.path,
|
||
importPath,
|
||
fullRoute: `/${root}/${page.path}`,
|
||
vueFile: path.join(ROOT, 'src', root, `${page.path}.vue`)
|
||
})
|
||
}
|
||
}
|
||
return rows
|
||
}
|
||
|
||
/** 扫描插件 pages 目录下所有 .vue(含 home_service 等多端结构) */
|
||
function scanAddonPages(key) {
|
||
const base = path.join(ADDON_DIR, key)
|
||
return walkFiles(base, (f) => f.includes(`${path.sep}pages${path.sep}`) && f.endsWith('.vue'), base)
|
||
.map((p) => p.replace(/\.vue$/, ''))
|
||
}
|
||
|
||
/**
|
||
* 扫描插件 locale
|
||
* @returns {Record<string, string[]>}
|
||
*/
|
||
function scanAddonLocale(key) {
|
||
const localeDir = path.join(ADDON_DIR, key, 'locale')
|
||
const out = {}
|
||
if (!fs.existsSync(localeDir)) return out
|
||
for (const locale of fs.readdirSync(localeDir)) {
|
||
const localePath = path.join(localeDir, locale)
|
||
if (!fs.statSync(localePath).isDirectory()) continue
|
||
out[locale] = fs.readdirSync(localePath)
|
||
.filter((f) => f.endsWith('.json'))
|
||
.map((f) => f.replace(/\.json$/, ''))
|
||
.sort()
|
||
}
|
||
return out
|
||
}
|
||
|
||
/** 扫描插件 diy 组件 */
|
||
function scanAddonDiyComponents(key) {
|
||
const diyDir = path.join(ADDON_DIR, key, 'components', 'diy')
|
||
const out = []
|
||
if (!fs.existsSync(diyDir)) return out
|
||
for (const name of fs.readdirSync(diyDir)) {
|
||
const compDir = path.join(diyDir, name)
|
||
if (!fs.statSync(compDir).isDirectory()) continue
|
||
if (fs.existsSync(path.join(compDir, 'index.vue'))) {
|
||
out.push(name)
|
||
}
|
||
}
|
||
return out.sort()
|
||
}
|
||
|
||
module.exports = {
|
||
ROOT,
|
||
ADDON_DIR,
|
||
PAGES_JSON,
|
||
BUILD_DIR,
|
||
BRIDGE_DIR,
|
||
BRIDGE_ADDON_ROOT,
|
||
BRIDGE_STUB_ROOT,
|
||
listAddonKeys,
|
||
walkFiles,
|
||
parsePagesJson,
|
||
parseAddonBoundaries,
|
||
scanSubPackagePages,
|
||
scanAddonPages,
|
||
scanAddonLocale,
|
||
scanAddonDiyComponents,
|
||
stripJsonComments,
|
||
resolveAddonEntry
|
||
}
|
||
|
||
/** 解析 addon 入口文件名:默认 index.js;启用内容哈希后为 index-[hash].js */
|
||
function resolveAddonEntry(addonDir) {
|
||
// 入口文件名来自构建期写入的 manifest.json(generateBundle 按 chunk.isEntry 精确记录 entry 字段),
|
||
// 直接读取即可,无需扫描目录:shop 等大插件的懒加载 chunk(components/xxx/index.vue)
|
||
// basename 也叫 index,目录里会同时存在多个 index-[hash].js,扫描文件名无法区分入口。
|
||
// 兼容未生成 manifest.json 的旧产物(入口固定为 index.js)
|
||
try {
|
||
const m = JSON.parse(fs.readFileSync(path.join(addonDir, 'manifest.json'), 'utf-8'))
|
||
if (m && typeof m.entry === 'string' && m.entry) {
|
||
return './' + m.entry.replace(/\\/g, '/')
|
||
}
|
||
} catch { /* 无 manifest.json(旧构建):入口固定为 index.js */ }
|
||
return './index.js'
|
||
}
|