befly 3.5.1 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apis/admin/del.ts +1 -1
- package/apis/admin/info.ts +1 -1
- package/apis/admin/ins.ts +1 -1
- package/apis/admin/list.ts +1 -1
- package/apis/admin/roleDetail.ts +1 -1
- package/apis/admin/roleSave.ts +1 -1
- package/apis/admin/upd.ts +1 -1
- package/apis/api/all.ts +1 -1
- package/apis/auth/login.ts +1 -1
- package/apis/auth/logout.ts +1 -1
- package/apis/auth/register.ts +1 -1
- package/apis/auth/sendSmsCode.ts +3 -2
- package/apis/cache/refresh.ts +1 -1
- package/apis/dashboard/addonList.ts +1 -1
- package/apis/dashboard/changelog.ts +1 -1
- package/apis/dashboard/configStatus.ts +1 -1
- package/apis/dashboard/environmentInfo.ts +1 -1
- package/apis/dashboard/performanceMetrics.ts +1 -1
- package/apis/dashboard/permissionStats.ts +1 -1
- package/apis/dashboard/serviceStatus.ts +2 -2
- package/apis/dashboard/systemInfo.ts +3 -2
- package/apis/dashboard/systemOverview.ts +1 -1
- package/apis/dashboard/systemResources.ts +1 -1
- package/apis/dict/all.ts +1 -1
- package/apis/dict/del.ts +1 -1
- package/apis/dict/detail.ts +1 -1
- package/apis/dict/ins.ts +1 -1
- package/apis/dict/list.ts +1 -1
- package/apis/dict/upd.ts +1 -1
- package/apis/menu/all.ts +1 -1
- package/apis/menu/del.ts +1 -1
- package/apis/menu/ins.ts +1 -1
- package/apis/menu/list.ts +1 -1
- package/apis/menu/upd.ts +1 -1
- package/apis/role/apiDetail.ts +1 -1
- package/apis/role/apiSave.ts +1 -1
- package/apis/role/del.ts +1 -1
- package/apis/role/detail.ts +1 -1
- package/apis/role/ins.ts +1 -1
- package/apis/role/list.ts +1 -1
- package/apis/role/menuDetail.ts +1 -1
- package/apis/role/menuSave.ts +1 -1
- package/apis/role/save.ts +1 -1
- package/apis/role/upd.ts +1 -1
- package/bin/index.ts +18 -131
- package/checks/conflict.ts +1 -1
- package/checks/table.ts +6 -8
- package/commands/index.ts +2 -98
- package/commands/sync.ts +61 -29
- package/commands/syncApi.ts +23 -53
- package/commands/syncDb/apply.ts +1 -1
- package/commands/syncDb/constants.ts +2 -2
- package/commands/syncDb/ddl.ts +1 -1
- package/commands/syncDb/helpers.ts +1 -1
- package/commands/syncDb/index.ts +33 -33
- package/commands/syncDb/schema.ts +2 -2
- package/commands/syncDb/sqlite.ts +1 -1
- package/commands/syncDb/state.ts +1 -1
- package/commands/syncDb/table.ts +1 -1
- package/commands/syncDb/tableCreate.ts +1 -1
- package/commands/syncDb/types.ts +1 -1
- package/commands/syncDb/version.ts +2 -2
- package/commands/syncDb.ts +6 -6
- package/commands/syncDev.ts +37 -35
- package/commands/syncMenu.ts +26 -77
- package/commands/util.ts +1 -1
- package/lib/cipher.ts +1 -1
- package/lib/database.ts +2 -11
- package/lib/dbHelper.ts +1 -1
- package/lib/jwt.ts +2 -2
- package/lib/logger.ts +9 -7
- package/lib/middleware.ts +2 -2
- package/lib/redisHelper.ts +2 -2
- package/lib/sqlBuilder.ts +1 -1
- package/lib/validator.ts +1 -1
- package/lib/xml.ts +1 -1
- package/lifecycle/bootstrap.ts +2 -2
- package/lifecycle/checker.ts +9 -26
- package/lifecycle/lifecycle.ts +6 -35
- package/lifecycle/loader.ts +11 -101
- package/main.ts +2 -2
- package/package.json +2 -4
- package/paths.ts +1 -1
- package/plugins/cache.ts +1 -1
- package/plugins/db.ts +3 -3
- package/plugins/logger.ts +1 -1
- package/plugins/redis.ts +2 -2
- package/router/api.ts +2 -2
- package/router/root.ts +2 -2
- package/router/static.ts +2 -2
- package/types/addon.d.ts +1 -1
- package/types/api.d.ts +1 -1
- package/types/befly.d.ts +1 -1
- package/types/common.d.ts +1 -1
- package/types/context.d.ts +1 -1
- package/types/crypto.d.ts +1 -1
- package/types/database.d.ts +1 -1
- package/types/env.ts +67 -0
- package/types/index.ts +5 -0
- package/types/jwt.d.ts +1 -1
- package/types/logger.d.ts +1 -1
- package/types/plugin.d.ts +1 -1
- package/types/redis.d.ts +1 -1
- package/types/tool.d.ts +1 -1
- package/types/util.d.ts +1 -1
- package/types/validator.d.ts +1 -1
- package/util.ts +2 -2
- package/commands/build.ts +0 -62
- package/config/env.ts +0 -202
package/apis/admin/del.ts
CHANGED
package/apis/admin/info.ts
CHANGED
package/apis/admin/ins.ts
CHANGED
package/apis/admin/list.ts
CHANGED
package/apis/admin/roleDetail.ts
CHANGED
package/apis/admin/roleSave.ts
CHANGED
package/apis/admin/upd.ts
CHANGED
package/apis/api/all.ts
CHANGED
package/apis/auth/login.ts
CHANGED
package/apis/auth/logout.ts
CHANGED
package/apis/auth/register.ts
CHANGED
package/apis/auth/sendSmsCode.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* 发送短信验证码接口
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { Yes } from '../../util.js';
|
|
6
|
+
import { Env } from '../../env.js';
|
|
6
7
|
import adminTable from '../../tables/admin.json';
|
|
7
8
|
|
|
8
9
|
export default {
|
|
@@ -28,7 +29,7 @@ export default {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
// 开发环境下返回验证码(生产环境应该删除)
|
|
31
|
-
const isDev =
|
|
32
|
+
const isDev = Env.NODE_ENV === 'development';
|
|
32
33
|
|
|
33
34
|
return Yes('验证码已发送', isDev ? { code } : null);
|
|
34
35
|
}
|
package/apis/cache/refresh.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* 获取系统信息
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { Yes } from '../../util.js';
|
|
6
|
+
import { Env } from '../../env.js';
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
name: '获取系统信息',
|
|
@@ -14,7 +15,7 @@ export default {
|
|
|
14
15
|
const uptime = Math.floor(process.uptime() * 1000);
|
|
15
16
|
|
|
16
17
|
// 环境
|
|
17
|
-
const environment =
|
|
18
|
+
const environment = Env.NODE_ENV || 'development';
|
|
18
19
|
|
|
19
20
|
return Yes('获取成功', {
|
|
20
21
|
environment: environment,
|
package/apis/dict/all.ts
CHANGED
package/apis/dict/del.ts
CHANGED
package/apis/dict/detail.ts
CHANGED
package/apis/dict/ins.ts
CHANGED
package/apis/dict/list.ts
CHANGED
package/apis/dict/upd.ts
CHANGED
package/apis/menu/all.ts
CHANGED
package/apis/menu/del.ts
CHANGED
package/apis/menu/ins.ts
CHANGED
package/apis/menu/list.ts
CHANGED
package/apis/menu/upd.ts
CHANGED
package/apis/role/apiDetail.ts
CHANGED
package/apis/role/apiSave.ts
CHANGED
package/apis/role/del.ts
CHANGED
package/apis/role/detail.ts
CHANGED
package/apis/role/ins.ts
CHANGED
package/apis/role/list.ts
CHANGED
package/apis/role/menuDetail.ts
CHANGED
package/apis/role/menuSave.ts
CHANGED
package/apis/role/save.ts
CHANGED
package/apis/role/upd.ts
CHANGED
package/bin/index.ts
CHANGED
|
@@ -1,147 +1,34 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
3
|
* Befly CLI - 命令行工具入口
|
|
4
|
-
*
|
|
4
|
+
* 只提供 sync 命令,用于同步所有数据
|
|
5
|
+
*
|
|
6
|
+
* 使用方法:
|
|
7
|
+
* befly sync # 使用当前环境(默认 development)
|
|
5
8
|
*
|
|
6
9
|
* 环境变量加载:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* Bun 自动根据 NODE_ENV 加载对应的 .env 文件:
|
|
11
|
+
* - NODE_ENV=development → .env.development
|
|
12
|
+
* - NODE_ENV=production → .env.production
|
|
13
|
+
* - NODE_ENV=test → .env.test
|
|
10
14
|
*/
|
|
11
15
|
|
|
12
|
-
import { Command } from 'commander';
|
|
13
|
-
import { buildCommand } from '../commands/build.js';
|
|
14
16
|
import { syncCommand } from '../commands/sync.js';
|
|
15
|
-
import { syncDbCommand } from '../commands/syncDb.js';
|
|
16
|
-
import { syncApiCommand } from '../commands/syncApi.js';
|
|
17
|
-
import { syncMenuCommand } from '../commands/syncMenu.js';
|
|
18
|
-
import { syncDevCommand } from '../commands/syncDev.js';
|
|
19
17
|
import { Logger } from '../lib/logger.js';
|
|
20
|
-
import { join } from 'pathe';
|
|
21
|
-
import { getPackageVersion } from '../commands/util.js';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 读取 package.json 版本号
|
|
25
|
-
*/
|
|
26
|
-
function getVersion(): string {
|
|
27
|
-
const coreDir = join(import.meta.dir, '..');
|
|
28
|
-
return getPackageVersion(coreDir);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Bun 版本要求
|
|
33
|
-
*/
|
|
34
|
-
const REQUIRED_BUN_VERSION = '1.3.0';
|
|
35
18
|
|
|
36
19
|
/**
|
|
37
|
-
*
|
|
20
|
+
* 主函数
|
|
38
21
|
*/
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
const parts2 = v2.split('.').map(Number);
|
|
42
|
-
|
|
43
|
-
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
44
|
-
const num1 = parts1[i] || 0;
|
|
45
|
-
const num2 = parts2[i] || 0;
|
|
46
|
-
|
|
47
|
-
if (num1 > num2) return 1;
|
|
48
|
-
if (num1 < num2) return -1;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 获取 Bun 版本
|
|
56
|
-
*/
|
|
57
|
-
function getBunVersion(): string | null {
|
|
22
|
+
async function main() {
|
|
23
|
+
// 执行 sync 命令
|
|
58
24
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const proc = Bun.spawnSync(['bun', '--version'], {
|
|
64
|
-
stdout: 'pipe',
|
|
65
|
-
stderr: 'pipe'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (proc.exitCode === 0) {
|
|
69
|
-
const version = proc.stdout.toString().trim();
|
|
70
|
-
return version;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return null;
|
|
74
|
-
} catch {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 检查 Bun 版本
|
|
81
|
-
*/
|
|
82
|
-
function checkBunVersion(): void {
|
|
83
|
-
const currentVersion = getBunVersion();
|
|
84
|
-
|
|
85
|
-
if (!currentVersion) {
|
|
86
|
-
Logger.error('未检测到 Bun 运行时');
|
|
87
|
-
Logger.info('\nBefly CLI 需要 Bun v1.3.0 或更高版本');
|
|
88
|
-
Logger.info('请访问 https://bun.sh 安装 Bun\n');
|
|
89
|
-
Logger.info('安装命令:');
|
|
90
|
-
Logger.info(' Windows (PowerShell): powershell -c "irm bun.sh/install.ps1 | iex"');
|
|
91
|
-
Logger.info(' macOS/Linux: curl -fsSL https://bun.sh/install | bash\n');
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const comparison = compareVersions(currentVersion, REQUIRED_BUN_VERSION);
|
|
96
|
-
|
|
97
|
-
if (comparison < 0) {
|
|
98
|
-
Logger.error(`Bun 版本过低: ${currentVersion}`);
|
|
99
|
-
Logger.info(`\n需要 Bun v${REQUIRED_BUN_VERSION} 或更高版本`);
|
|
100
|
-
Logger.info('请升级 Bun:\n');
|
|
101
|
-
Logger.info(' bun upgrade\n');
|
|
25
|
+
await syncCommand();
|
|
26
|
+
Logger.printEnv();
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
Logger.error('命令执行失败:', error.message || error);
|
|
102
29
|
process.exit(1);
|
|
103
30
|
}
|
|
104
31
|
}
|
|
105
32
|
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const program = new Command();
|
|
110
|
-
|
|
111
|
-
program.name('befly').description('Befly CLI - 为 Befly 框架提供命令行工具').version(getVersion());
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 包装命令处理函数,在执行后打印环境
|
|
115
|
-
*/
|
|
116
|
-
function wrapCommand<T extends (...args: any[]) => any>(fn: T): T {
|
|
117
|
-
return (async (...args: any[]) => {
|
|
118
|
-
const result = await fn(...args);
|
|
119
|
-
Logger.printEnv();
|
|
120
|
-
return result;
|
|
121
|
-
}) as T;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// build 命令 - 构建项目
|
|
125
|
-
program.command('build').description('构建项目').option('-o, --outdir <path>', '输出目录', 'dist').option('--minify', '压缩代码', false).option('--sourcemap', '生成 sourcemap', false).action(wrapCommand(buildCommand));
|
|
126
|
-
|
|
127
|
-
// sync 命令 - 一次性执行所有同步
|
|
128
|
-
program.command('sync').description('一次性执行所有同步操作(syncApi + syncMenu + syncDev)').option('--plan', '计划模式,只显示不执行', false).option('-e, --env <environment>', '指定环境 (development, production, test)').action(wrapCommand(syncCommand));
|
|
129
|
-
|
|
130
|
-
// syncDb 命令 - 同步数据库
|
|
131
|
-
program.command('syncDb').description('同步数据库表结构').option('-t, --table <name>', '指定表名').option('--dry-run', '预览模式,只显示不执行', false).option('-e, --env <environment>', '指定环境 (development, production, test)').action(wrapCommand(syncDbCommand));
|
|
132
|
-
|
|
133
|
-
// syncApi 命令 - 同步 API 接口
|
|
134
|
-
program.command('syncApi').description('同步 API 接口到数据库').option('--plan', '计划模式,只显示不执行', false).option('-e, --env <environment>', '指定环境 (development, production, test)').action(wrapCommand(syncApiCommand));
|
|
135
|
-
|
|
136
|
-
// syncMenu 命令 - 同步菜单
|
|
137
|
-
program.command('syncMenu').description('同步菜单配置到数据库').option('--plan', '计划模式,只显示不执行', false).option('-e, --env <environment>', '指定环境 (development, production, test)').action(wrapCommand(syncMenuCommand));
|
|
138
|
-
|
|
139
|
-
// syncDev 命令 - 同步开发者账号
|
|
140
|
-
program.command('syncDev').description('同步开发者管理员账号').option('--plan', '计划模式,只显示不执行', false).option('-e, --env <environment>', '指定环境 (development, production, test)').action(wrapCommand(syncDevCommand));
|
|
141
|
-
|
|
142
|
-
// 显示建议和错误
|
|
143
|
-
program.showSuggestionAfterError();
|
|
144
|
-
program.showHelpAfterError();
|
|
145
|
-
|
|
146
|
-
// 解析命令行参数
|
|
147
|
-
program.parse();
|
|
33
|
+
// 运行主函数
|
|
34
|
+
main();
|
package/checks/conflict.ts
CHANGED
package/checks/table.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* 表规则检查器 - TypeScript 版本
|
|
3
3
|
* 验证表定义文件的格式和规则
|
|
4
4
|
*/
|
|
@@ -221,7 +221,7 @@ export default async function (): Promise<boolean> {
|
|
|
221
221
|
|
|
222
222
|
if (fileValid) {
|
|
223
223
|
validFiles++;
|
|
224
|
-
Logger.info(`${fileType}表 ${fileName} 验证通过(${fileRules} 个字段)`);
|
|
224
|
+
// Logger.info(`${fileType}表 ${fileName} 验证通过(${fileRules} 个字段)`);
|
|
225
225
|
} else {
|
|
226
226
|
invalidFiles++;
|
|
227
227
|
}
|
|
@@ -232,17 +232,15 @@ export default async function (): Promise<boolean> {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
// 输出统计信息
|
|
235
|
-
Logger.info(
|
|
236
|
-
Logger.info(`
|
|
237
|
-
Logger.info(`
|
|
238
|
-
Logger.info(`
|
|
239
|
-
Logger.info(` 失败文件: ${invalidFiles}`);
|
|
235
|
+
// Logger.info(` 总文件数: ${totalFiles}`);
|
|
236
|
+
// Logger.info(` 总规则数: ${totalRules}`);
|
|
237
|
+
// Logger.info(` 通过文件: ${validFiles}`);
|
|
238
|
+
// Logger.info(` 失败文件: ${invalidFiles}`);
|
|
240
239
|
|
|
241
240
|
if (invalidFiles > 0) {
|
|
242
241
|
Logger.warn(`表定义检查失败,请修复上述错误后重试`);
|
|
243
242
|
return false;
|
|
244
243
|
} else {
|
|
245
|
-
Logger.info(`所有表定义检查通过 ✓`);
|
|
246
244
|
return true;
|
|
247
245
|
}
|
|
248
246
|
} catch (error: any) {
|