mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2026-11-18 16:40: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. 小程序编译结构进行了优化,整个运行的速度更加快速。
125 lines
4.8 KiB
JavaScript
125 lines
4.8 KiB
JavaScript
/**
|
||
* 通用导出冲突扫描器
|
||
* 扫描目录下 .ts/.js 文件的 export,检测同名冲突,返回冲突映射。
|
||
*/
|
||
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
const DEFAULT_EXTENSIONS = ['.ts', '.js', '.tsx', '.jsx']
|
||
|
||
/**
|
||
* 去掉注释
|
||
*
|
||
* 本扫描器是按正则匹配源码文本、不做语法解析的。若注释里出现形如
|
||
* 「export { xxx }」的示例写法,会被误判成一个真实导出并写进生成的 barrel,
|
||
* 而那个名字在运行时并不存在,最终 Rollup 报 "xxx is not exported by ..."。
|
||
* 因此匹配前先剥离注释。
|
||
* @param {string} src
|
||
* @return {string}
|
||
*/
|
||
function stripComments(src) {
|
||
return src
|
||
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
||
// 排除 :// (如 http://)避免误伤 URL
|
||
.replace(/(^|[^:])\/\/[^\n]*/g, '$1')
|
||
}
|
||
|
||
/** 从源码中提取所有命名导出名称(仅运行时存在的值导出) */
|
||
function scanExports(src) {
|
||
const code = stripComments(src)
|
||
const names = []
|
||
// export const|let|var|function|class|enum NAME
|
||
// ★ 不含 type / interface:类型导出编译后并不存在于运行时,
|
||
// 而生成的 barrel 是按值重导出,收进去会报 "not exported by"
|
||
const declRe = /export\s+(?:const|let|var|function|class|enum)\s+(\w+)/g
|
||
for (const m of code.matchAll(declRe)) names.push(m[1])
|
||
// export { a, b, c as d }(export type { ... } 为纯类型导出,跳过)
|
||
const braceRe = /export\s*(type\s*)?\{([^}]+)\}/g
|
||
for (const m of code.matchAll(braceRe)) {
|
||
if (m[1]) continue
|
||
for (const item of m[2].split(',').map(s => s.trim()).filter(Boolean)) {
|
||
const parts = item.split(/\s+(?:as|:)\s+/)
|
||
names.push(parts.length > 1 ? parts[parts.length - 1].trim() : parts[0].trim())
|
||
}
|
||
}
|
||
return [...new Set(names)]
|
||
}
|
||
|
||
/** 扫描目录,返回文件列表 */
|
||
function scanDirExports(dir, opts = {}) {
|
||
const exclude = new Set(opts.exclude || [])
|
||
const exts = new Set(opts.extensions || DEFAULT_EXTENSIONS)
|
||
if (!fs.existsSync(dir)) return []
|
||
const out = []
|
||
for (const f of fs.readdirSync(dir)) {
|
||
const full = path.join(dir, f)
|
||
if (!fs.statSync(full).isFile()) continue
|
||
if (![...exts].some(e => f.endsWith(e))) continue
|
||
if (exclude.has(f) || exclude.has(full)) continue
|
||
out.push({ moduleKey: f.replace(/\.[^.]+$/, ''), path: full })
|
||
}
|
||
return out
|
||
}
|
||
|
||
/** 递归扫描目录 */
|
||
function scanRecursive(dir, opts = {}) {
|
||
const exclude = new Set(opts.exclude || [])
|
||
const exts = new Set(opts.extensions || DEFAULT_EXTENSIONS)
|
||
const out = []
|
||
if (!fs.existsSync(dir)) return out
|
||
function walk(base, rel) {
|
||
for (const name of fs.readdirSync(base)) {
|
||
const relPath = rel ? `${rel}/${name}` : name
|
||
if (exclude.has(relPath) || exclude.has(name)) continue
|
||
const full = path.join(base, name)
|
||
const stat = fs.statSync(full)
|
||
if (stat.isDirectory()) walk(full, relPath)
|
||
else if (stat.isFile() && [...exts].some(e => name.endsWith(e)))
|
||
out.push({ moduleKey: relPath.replace(/\.[^.]+$/, '').replace(/[\\/]/g, '_'), path: full })
|
||
}
|
||
}
|
||
walk(dir, '')
|
||
return out
|
||
}
|
||
|
||
/**
|
||
* 检测并解决导出冲突。按 moduleKey 字母序处理,
|
||
* 先导出的保留原名,后出现的加 moduleKey 前缀。
|
||
*/
|
||
function resolveConflicts(files, opts = {}) {
|
||
const sorted = [...files].sort((a, b) => a.moduleKey.localeCompare(b.moduleKey))
|
||
const exportedNames = new Set()
|
||
const conflicts = {}
|
||
const resolved = []
|
||
for (const file of sorted) {
|
||
const src = fs.readFileSync(file.path, 'utf-8')
|
||
const names = scanExports(src)
|
||
const normal = []; const renamed = []
|
||
for (const name of names) {
|
||
if (!exportedNames.has(name)) { exportedNames.add(name); normal.push(name) }
|
||
else {
|
||
const newName = opts.prefixer ? opts.prefixer(file, name) : file.moduleKey + '_' + name
|
||
exportedNames.add(newName); renamed.push(name)
|
||
conflicts[file.moduleKey + ':' + name] = newName
|
||
}
|
||
}
|
||
resolved.push({ module: file.moduleKey, normal, renamed, src: file.path })
|
||
}
|
||
return { resolved, conflicts }
|
||
}
|
||
|
||
/** 生成 re-export 语句 */
|
||
function buildReExportStatements(resolved, modulePathPrefix) {
|
||
const lines = []
|
||
for (const r of resolved) {
|
||
if (r.normal.length) lines.push(`export { ${r.normal.join(', ')} } from '${modulePathPrefix}/${r.module}'`)
|
||
if (r.renamed.length) {
|
||
const renamedStr = r.renamed.map(n => `${n} as ${r.module}_${n}`).join(', ')
|
||
lines.push(`export { ${renamedStr} } from '${modulePathPrefix}/${r.module}'`)
|
||
}
|
||
}
|
||
return lines
|
||
}
|
||
|
||
module.exports = { scanExports, scanDirExports, scanRecursive, resolveConflicts, buildReExportStatements }
|