befly 3.5.7 → 3.7.0
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/{checks/table.ts → check.ts} +14 -17
- package/lib/addon.ts +77 -0
- package/lib/logger.ts +6 -15
- package/lifecycle/checker.ts +22 -48
- package/lifecycle/lifecycle.ts +7 -5
- package/lifecycle/loader.ts +5 -6
- package/main.ts +12 -1
- package/package.json +3 -14
- package/paths.ts +5 -54
- package/plugins/cache.ts +0 -1
- package/plugins/db.ts +0 -1
- package/plugins/logger.ts +0 -1
- package/plugins/redis.ts +0 -6
- package/util.ts +1 -83
- package/apis/admin/del.ts +0 -35
- package/apis/admin/info.ts +0 -50
- package/apis/admin/ins.ts +0 -61
- package/apis/admin/list.ts +0 -20
- package/apis/admin/roleDetail.ts +0 -35
- package/apis/admin/roleSave.ts +0 -40
- package/apis/admin/upd.ts +0 -51
- package/apis/api/all.ts +0 -37
- package/apis/auth/login.ts +0 -78
- package/apis/auth/logout.ts +0 -23
- package/apis/auth/register.ts +0 -50
- package/apis/auth/sendSmsCode.ts +0 -36
- package/apis/cache/refresh.ts +0 -34
- package/apis/dashboard/addonList.ts +0 -47
- package/apis/dashboard/changelog.ts +0 -37
- package/apis/dashboard/configStatus.ts +0 -54
- package/apis/dashboard/environmentInfo.ts +0 -46
- package/apis/dashboard/performanceMetrics.ts +0 -23
- package/apis/dashboard/permissionStats.ts +0 -31
- package/apis/dashboard/serviceStatus.ts +0 -82
- package/apis/dashboard/systemInfo.ts +0 -26
- package/apis/dashboard/systemOverview.ts +0 -32
- package/apis/dashboard/systemResources.ts +0 -119
- package/apis/dict/all.ts +0 -25
- package/apis/dict/del.ts +0 -19
- package/apis/dict/detail.ts +0 -21
- package/apis/dict/ins.ts +0 -27
- package/apis/dict/list.ts +0 -18
- package/apis/dict/upd.ts +0 -31
- package/apis/menu/all.ts +0 -68
- package/apis/menu/del.ts +0 -37
- package/apis/menu/ins.ts +0 -20
- package/apis/menu/list.ts +0 -21
- package/apis/menu/upd.ts +0 -29
- package/apis/role/apiDetail.ts +0 -30
- package/apis/role/apiSave.ts +0 -41
- package/apis/role/del.ts +0 -44
- package/apis/role/detail.ts +0 -24
- package/apis/role/ins.ts +0 -39
- package/apis/role/list.ts +0 -14
- package/apis/role/menuDetail.ts +0 -30
- package/apis/role/menuSave.ts +0 -38
- package/apis/role/save.ts +0 -44
- package/apis/role/upd.ts +0 -40
- package/bin/index.ts +0 -34
- package/checks/conflict.ts +0 -351
- package/commands/index.ts +0 -73
- package/commands/sync.ts +0 -88
- package/commands/syncApi.ts +0 -316
- package/commands/syncDb/apply.ts +0 -171
- package/commands/syncDb/constants.ts +0 -77
- package/commands/syncDb/ddl.ts +0 -191
- package/commands/syncDb/helpers.ts +0 -173
- package/commands/syncDb/index.ts +0 -217
- package/commands/syncDb/schema.ts +0 -199
- package/commands/syncDb/sqlite.ts +0 -50
- package/commands/syncDb/state.ts +0 -112
- package/commands/syncDb/table.ts +0 -214
- package/commands/syncDb/tableCreate.ts +0 -149
- package/commands/syncDb/types.ts +0 -92
- package/commands/syncDb/version.ts +0 -73
- package/commands/syncDb.ts +0 -34
- package/commands/syncDev.ts +0 -237
- package/commands/syncMenu.ts +0 -349
- package/commands/util.ts +0 -58
- package/entry.ts +0 -9
- package/tables/admin.json +0 -14
- package/tables/api.json +0 -8
- package/tables/dict.json +0 -8
- package/tables/menu.json +0 -8
- package/tables/role.json +0 -8
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* 表规则检查器 - TypeScript 版本
|
|
3
3
|
* 验证表定义文件的格式和规则
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { basename } from 'pathe';
|
|
7
|
-
import { Logger } from '
|
|
8
|
-
import { parseRule } from '
|
|
9
|
-
import { projectTableDir } from '
|
|
10
|
-
import {
|
|
7
|
+
import { Logger } from './lib/logger.js';
|
|
8
|
+
import { parseRule } from './util.js';
|
|
9
|
+
import { projectTableDir } from './paths.js';
|
|
10
|
+
import { Addon } from './lib/addon.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* 表文件信息接口
|
|
@@ -52,9 +52,9 @@ const MAX_VARCHAR_LENGTH = 65535;
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* 检查表定义文件
|
|
55
|
-
* @
|
|
55
|
+
* @throws 当检查失败时抛出异常
|
|
56
56
|
*/
|
|
57
|
-
export
|
|
57
|
+
export const checkDefault = async function (): Promise<void> {
|
|
58
58
|
try {
|
|
59
59
|
const tablesGlob = new Bun.Glob('*.json');
|
|
60
60
|
|
|
@@ -73,13 +73,13 @@ export default async function (): Promise<boolean> {
|
|
|
73
73
|
absolute: true,
|
|
74
74
|
onlyFiles: true
|
|
75
75
|
})) {
|
|
76
|
-
allTableFiles.push({ file, type: 'project' });
|
|
76
|
+
allTableFiles.push({ file: file, type: 'project' });
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// 收集 addon 表字段定义文件
|
|
80
|
-
const addons =
|
|
80
|
+
const addons = Addon.scan();
|
|
81
81
|
for (const addonName of addons) {
|
|
82
|
-
const addonTablesDir =
|
|
82
|
+
const addonTablesDir = Addon.getDir(addonName, 'tables');
|
|
83
83
|
|
|
84
84
|
try {
|
|
85
85
|
for await (const file of tablesGlob.scan({
|
|
@@ -87,7 +87,7 @@ export default async function (): Promise<boolean> {
|
|
|
87
87
|
absolute: true,
|
|
88
88
|
onlyFiles: true
|
|
89
89
|
})) {
|
|
90
|
-
allTableFiles.push({ file, type: 'addon', addonName });
|
|
90
|
+
allTableFiles.push({ file: file, type: 'addon', addonName: addonName });
|
|
91
91
|
}
|
|
92
92
|
} catch (error) {
|
|
93
93
|
// addon 的 tables 目录可能不存在,跳过
|
|
@@ -238,13 +238,10 @@ export default async function (): Promise<boolean> {
|
|
|
238
238
|
// Logger.info(` 失败文件: ${invalidFiles}`);
|
|
239
239
|
|
|
240
240
|
if (invalidFiles > 0) {
|
|
241
|
-
|
|
242
|
-
return false;
|
|
243
|
-
} else {
|
|
244
|
-
return true;
|
|
241
|
+
throw new Error('表定义检查失败,请修复上述错误后重试');
|
|
245
242
|
}
|
|
246
243
|
} catch (error: any) {
|
|
247
244
|
Logger.error('数据表定义检查过程中出错:', error);
|
|
248
|
-
|
|
245
|
+
throw error;
|
|
249
246
|
}
|
|
250
|
-
}
|
|
247
|
+
};
|
package/lib/addon.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Addon 管理工具类
|
|
3
|
+
* 提供 addon 的扫描、路径获取等功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import { join } from 'pathe';
|
|
8
|
+
import { existsSync, statSync, readdirSync } from 'node:fs';
|
|
9
|
+
import { projectDir } from '../paths.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Addon 管理类
|
|
13
|
+
*/
|
|
14
|
+
export class Addon {
|
|
15
|
+
/**
|
|
16
|
+
* 扫描所有可用的 addon
|
|
17
|
+
* @returns addon 名称数组
|
|
18
|
+
*/
|
|
19
|
+
static scan(): string[] {
|
|
20
|
+
const beflyDir = join(projectDir, 'node_modules', '@befly-addon');
|
|
21
|
+
|
|
22
|
+
if (!existsSync(beflyDir)) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
return fs
|
|
28
|
+
.readdirSync(beflyDir)
|
|
29
|
+
.filter((name) => {
|
|
30
|
+
// addon 名称格式:admin, demo 等(不带 addon- 前缀)
|
|
31
|
+
const fullPath = join(beflyDir, name);
|
|
32
|
+
try {
|
|
33
|
+
const stat = statSync(fullPath);
|
|
34
|
+
return stat.isDirectory();
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
.sort();
|
|
40
|
+
} catch {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 获取 addon 的指定子目录路径
|
|
47
|
+
* @param name - addon 名称
|
|
48
|
+
* @param subDir - 子目录名称
|
|
49
|
+
* @returns 完整路径
|
|
50
|
+
*/
|
|
51
|
+
static getDir(name: string, subDir: string): string {
|
|
52
|
+
return join(projectDir, 'node_modules', '@befly-addon', name, subDir);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 检查 addon 子目录是否存在
|
|
57
|
+
* @param name - addon 名称
|
|
58
|
+
* @param subDir - 子目录名称
|
|
59
|
+
* @returns 是否存在
|
|
60
|
+
*/
|
|
61
|
+
static dirExists(name: string, subDir: string): boolean {
|
|
62
|
+
const dir = this.getDir(name, subDir);
|
|
63
|
+
return existsSync(dir) && statSync(dir).isDirectory();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 获取插件目录列表
|
|
68
|
+
* @param addonsDir - addons 根目录路径
|
|
69
|
+
* @returns 插件名称数组
|
|
70
|
+
*/
|
|
71
|
+
static getDirs(addonsDir: string): string[] {
|
|
72
|
+
return readdirSync(addonsDir).filter((name) => {
|
|
73
|
+
const addonPath = join(addonsDir, name);
|
|
74
|
+
return statSync(addonPath).isDirectory() && !name.startsWith('_');
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
package/lib/logger.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import { join } from 'pathe';
|
|
7
7
|
import { appendFile, stat } from 'node:fs/promises';
|
|
8
|
-
import chalk from 'chalk';
|
|
9
8
|
import { Env } from '../env.js';
|
|
10
9
|
import type { LogLevel } from '../types/common.js';
|
|
11
10
|
|
|
@@ -54,12 +53,6 @@ export class Logger {
|
|
|
54
53
|
|
|
55
54
|
// 格式化消息
|
|
56
55
|
const timestamp = formatDate();
|
|
57
|
-
const colorMap = {
|
|
58
|
-
info: chalk.greenBright,
|
|
59
|
-
debug: chalk.cyanBright,
|
|
60
|
-
warn: chalk.yellowBright,
|
|
61
|
-
error: chalk.redBright
|
|
62
|
-
};
|
|
63
56
|
|
|
64
57
|
// 处理消息内容
|
|
65
58
|
let content = '';
|
|
@@ -69,19 +62,17 @@ export class Logger {
|
|
|
69
62
|
content = String(message);
|
|
70
63
|
}
|
|
71
64
|
|
|
72
|
-
//
|
|
73
|
-
const
|
|
74
|
-
const
|
|
65
|
+
// 格式化日志消息
|
|
66
|
+
const levelStr = level.toUpperCase().padStart(5);
|
|
67
|
+
const logMessage = `[${timestamp}] ${levelStr} - ${content}`;
|
|
75
68
|
|
|
76
69
|
// 控制台输出
|
|
77
70
|
if (this.config.toConsole) {
|
|
78
|
-
console.log(
|
|
71
|
+
console.log(logMessage);
|
|
79
72
|
}
|
|
80
73
|
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
const plainMessage = `[${timestamp}] ${plainLevelStr} - ${content}`;
|
|
84
|
-
await this.writeToFile(plainMessage, level);
|
|
74
|
+
// 文件输出
|
|
75
|
+
await this.writeToFile(logMessage, level);
|
|
85
76
|
}
|
|
86
77
|
|
|
87
78
|
/**
|
package/lifecycle/checker.ts
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { join, basename } from 'pathe';
|
|
7
|
+
import { existsSync, statSync } from 'node:fs';
|
|
7
8
|
import { Logger } from '../lib/logger.js';
|
|
8
9
|
import { calcPerfTime } from '../util.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { projectCheckDir } from '../paths.js';
|
|
11
|
+
import { checkDefault } from '../check.js';
|
|
12
|
+
import { Addon } from '../lib/addon.js';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* 系统检查器类
|
|
@@ -20,6 +22,9 @@ export class Checker {
|
|
|
20
22
|
try {
|
|
21
23
|
const checkStartTime = Bun.nanoseconds();
|
|
22
24
|
|
|
25
|
+
// 先执行默认检查(有异常会自动抛出)
|
|
26
|
+
await checkDefault();
|
|
27
|
+
|
|
23
28
|
const glob = new Bun.Glob('*.{ts}');
|
|
24
29
|
|
|
25
30
|
// 统计信息
|
|
@@ -29,50 +34,21 @@ export class Checker {
|
|
|
29
34
|
failedChecks: 0
|
|
30
35
|
};
|
|
31
36
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
const conflictCheckPath = join(coreCheckDir, 'conflict.ts');
|
|
35
|
-
const conflictCheckFile = Bun.file(conflictCheckPath);
|
|
36
|
-
|
|
37
|
-
if (await conflictCheckFile.exists()) {
|
|
38
|
-
stats.totalChecks++;
|
|
39
|
-
const conflictCheckStart = Bun.nanoseconds();
|
|
40
|
-
|
|
41
|
-
const conflictModule = await import(conflictCheckPath);
|
|
42
|
-
const conflictCheckFn = conflictModule.default;
|
|
37
|
+
// 检查目录列表:先项目,后 addons
|
|
38
|
+
const checkDirs: Array<{ path: string; type: 'app' | 'addon'; addonName?: string }> = [];
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (typeof conflictResult !== 'boolean') {
|
|
49
|
-
Logger.warn(`核心检查 conflict.ts 返回值必须为 true 或 false,当前为 ${typeof conflictResult}`);
|
|
50
|
-
stats.failedChecks++;
|
|
51
|
-
} else if (conflictResult === true) {
|
|
52
|
-
stats.passedChecks++;
|
|
53
|
-
} else {
|
|
54
|
-
Logger.warn(`核心检查未通过: conflict.ts`);
|
|
55
|
-
stats.failedChecks++;
|
|
56
|
-
// 资源冲突检测失败,立即终止
|
|
57
|
-
Logger.warn('资源冲突检测失败,无法继续启动');
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
} catch (error: any) {
|
|
63
|
-
Logger.error('执行资源冲突检测时出错:', error);
|
|
64
|
-
stats.failedChecks++;
|
|
40
|
+
// 添加项目 checks 目录(如果存在)
|
|
41
|
+
if (existsSync(projectCheckDir) && statSync(projectCheckDir).isDirectory()) {
|
|
42
|
+
checkDirs.push({ path: projectCheckDir, type: 'app' });
|
|
65
43
|
}
|
|
66
44
|
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
const checkDirs = [{ path: coreCheckDir, type: 'core' as const }]; // 添加所有 addon 的 checks 目录
|
|
70
|
-
const addons = scanAddons();
|
|
45
|
+
// 添加所有 addon 的 checks 目录
|
|
46
|
+
const addons = Addon.scan();
|
|
71
47
|
for (const addon of addons) {
|
|
72
|
-
if (
|
|
48
|
+
if (Addon.dirExists(addon, 'checks')) {
|
|
73
49
|
checkDirs.push({
|
|
74
|
-
path:
|
|
75
|
-
type: 'addon'
|
|
50
|
+
path: Addon.getDir(addon, 'checks'),
|
|
51
|
+
type: 'addon',
|
|
76
52
|
addonName: addon
|
|
77
53
|
});
|
|
78
54
|
}
|
|
@@ -80,9 +56,10 @@ export class Checker {
|
|
|
80
56
|
|
|
81
57
|
// 按顺序扫描并执行检查函数
|
|
82
58
|
for (const checkConfig of checkDirs) {
|
|
83
|
-
const { path: checkDir, type } = checkConfig;
|
|
59
|
+
const { path: checkDir, type: type } = checkConfig;
|
|
84
60
|
const addonName = 'addonName' in checkConfig ? checkConfig.addonName : undefined;
|
|
85
|
-
const checkTypeLabel = type === '
|
|
61
|
+
const checkTypeLabel = type === 'app' ? '项目' : `组件${addonName}`;
|
|
62
|
+
|
|
86
63
|
for await (const file of glob.scan({
|
|
87
64
|
cwd: checkDir,
|
|
88
65
|
onlyFiles: true,
|
|
@@ -91,9 +68,6 @@ export class Checker {
|
|
|
91
68
|
const fileName = basename(file);
|
|
92
69
|
if (fileName.startsWith('_')) continue; // 跳过以下划线开头的文件
|
|
93
70
|
|
|
94
|
-
// 跳过已经执行过的 conflict.ts
|
|
95
|
-
if (type === 'core' && fileName === 'conflict.ts') continue;
|
|
96
|
-
|
|
97
71
|
try {
|
|
98
72
|
stats.totalChecks++;
|
|
99
73
|
const singleCheckStart = Bun.nanoseconds();
|
|
@@ -135,10 +109,10 @@ export class Checker {
|
|
|
135
109
|
|
|
136
110
|
// 输出检查结果统计
|
|
137
111
|
if (stats.failedChecks > 0) {
|
|
138
|
-
Logger.error(
|
|
112
|
+
Logger.error(`系统检查失败: ${stats.failedChecks}/${stats.totalChecks},耗时: ${totalCheckTime}`);
|
|
139
113
|
process.exit(1);
|
|
140
114
|
} else if (stats.totalChecks > 0) {
|
|
141
|
-
Logger.info(
|
|
115
|
+
Logger.info(`系统检查通过: ${stats.passedChecks}/${stats.totalChecks},耗时: ${totalCheckTime}`);
|
|
142
116
|
}
|
|
143
117
|
} catch (error: any) {
|
|
144
118
|
Logger.error('执行系统检查时发生错误', error);
|
package/lifecycle/lifecycle.ts
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Logger } from '../lib/logger.js';
|
|
7
|
-
import {
|
|
8
|
-
import { scanAddons, addonDirExists } from '../util.js';
|
|
9
|
-
import { Checker } from './checker.js';
|
|
7
|
+
import { Database } from '../lib/database.js';
|
|
10
8
|
import { Loader } from './loader.js';
|
|
9
|
+
import { Checker } from './checker.js';
|
|
10
|
+
import { Env } from '../env.js';
|
|
11
|
+
import { calcPerfTime } from '../util.js';
|
|
12
|
+
import { Addon } from '../lib/addon.js';
|
|
11
13
|
import { Bootstrap } from './bootstrap.js';
|
|
12
14
|
|
|
13
15
|
import type { Server } from 'bun';
|
|
@@ -78,10 +80,10 @@ export class Lifecycle {
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
// 2. 加载 addon APIs
|
|
81
|
-
const addons =
|
|
83
|
+
const addons = Addon.scan();
|
|
82
84
|
|
|
83
85
|
for (const addon of addons) {
|
|
84
|
-
const hasApis =
|
|
86
|
+
const hasApis = Addon.dirExists(addon, 'apis');
|
|
85
87
|
if (hasApis) {
|
|
86
88
|
try {
|
|
87
89
|
await Loader.loadApis(addon, this.apiRoutes, { where: 'addon', addonName: addon });
|
package/lifecycle/loader.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { isPlainObject } from 'es-toolkit/compat';
|
|
|
9
9
|
import { Logger } from '../lib/logger.js';
|
|
10
10
|
import { calcPerfTime } from '../util.js';
|
|
11
11
|
import { corePluginDir, projectPluginDir, coreApiDir, projectApiDir } from '../paths.js';
|
|
12
|
-
import {
|
|
12
|
+
import { Addon } from '../lib/addon.js';
|
|
13
13
|
import type { Plugin } from '../types/plugin.js';
|
|
14
14
|
import type { ApiRoute } from '../types/api.js';
|
|
15
15
|
import type { BeflyContext } from '../types/befly.js';
|
|
@@ -145,16 +145,15 @@ export class Loader {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
const corePluginsInitTime = calcPerfTime(corePluginsInitStart);
|
|
148
|
-
Logger.info(`✓ 核心插件加载完成: ${corePlugins.length} 个,耗时: ${corePluginsScanTime}`);
|
|
149
148
|
|
|
150
149
|
// 扫描 addon 插件目录
|
|
151
|
-
const addons =
|
|
150
|
+
const addons = Addon.scan();
|
|
152
151
|
if (addons.length > 0) {
|
|
153
152
|
const addonPluginsScanStart = Bun.nanoseconds();
|
|
154
153
|
for (const addon of addons) {
|
|
155
|
-
if (!
|
|
154
|
+
if (!Addon.dirExists(addon, 'plugins')) continue;
|
|
156
155
|
|
|
157
|
-
const addonPluginsDir =
|
|
156
|
+
const addonPluginsDir = Addon.getDir(addon, 'plugins');
|
|
158
157
|
for await (const file of glob.scan({
|
|
159
158
|
cwd: addonPluginsDir,
|
|
160
159
|
onlyFiles: true,
|
|
@@ -325,7 +324,7 @@ export class Loader {
|
|
|
325
324
|
if (where === 'core') {
|
|
326
325
|
apiDir = coreApiDir;
|
|
327
326
|
} else if (where === 'addon') {
|
|
328
|
-
apiDir =
|
|
327
|
+
apiDir = Addon.getDir(addonName, 'apis');
|
|
329
328
|
} else {
|
|
330
329
|
apiDir = projectApiDir;
|
|
331
330
|
}
|
package/main.ts
CHANGED
|
@@ -10,6 +10,11 @@ import { Cipher } from './lib/cipher.js';
|
|
|
10
10
|
import { Jwt } from './lib/jwt.js';
|
|
11
11
|
import { Database } from './lib/database.js';
|
|
12
12
|
import { Lifecycle } from './lifecycle/lifecycle.js';
|
|
13
|
+
import { coreDir } from './paths.js';
|
|
14
|
+
import { DbHelper } from './lib/dbHelper.js';
|
|
15
|
+
import { RedisHelper } from './lib/redisHelper.js';
|
|
16
|
+
import { Addon } from './lib/addon.js';
|
|
17
|
+
import { checkDefault } from './check.js';
|
|
13
18
|
|
|
14
19
|
import type { Server } from 'bun';
|
|
15
20
|
import type { BeflyContext, BeflyOptions } from './types/befly.js';
|
|
@@ -71,5 +76,11 @@ export {
|
|
|
71
76
|
Cipher,
|
|
72
77
|
Jwt,
|
|
73
78
|
Yes,
|
|
74
|
-
No
|
|
79
|
+
No,
|
|
80
|
+
Database,
|
|
81
|
+
DbHelper,
|
|
82
|
+
RedisHelper,
|
|
83
|
+
Addon,
|
|
84
|
+
coreDir,
|
|
85
|
+
checkDefault
|
|
75
86
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -10,9 +10,6 @@
|
|
|
10
10
|
},
|
|
11
11
|
"main": "main.ts",
|
|
12
12
|
"types": "./types/index.d.ts",
|
|
13
|
-
"bin": {
|
|
14
|
-
"befly": "./bin/index.ts"
|
|
15
|
-
},
|
|
16
13
|
"exports": {
|
|
17
14
|
".": {
|
|
18
15
|
"default": "./main.ts"
|
|
@@ -30,7 +27,6 @@
|
|
|
30
27
|
"api",
|
|
31
28
|
"framework",
|
|
32
29
|
"core",
|
|
33
|
-
"cli",
|
|
34
30
|
"typescript",
|
|
35
31
|
"javascript",
|
|
36
32
|
"backend",
|
|
@@ -42,16 +38,10 @@
|
|
|
42
38
|
"homepage": "https://chensuiyi.me",
|
|
43
39
|
"license": "Apache-2.0",
|
|
44
40
|
"files": [
|
|
45
|
-
"bin/",
|
|
46
|
-
"apis/",
|
|
47
|
-
"checks/",
|
|
48
|
-
"commands/",
|
|
49
|
-
"config/",
|
|
50
41
|
"lib/",
|
|
51
42
|
"lifecycle/",
|
|
52
43
|
"plugins/",
|
|
53
44
|
"router/",
|
|
54
|
-
"tables/",
|
|
55
45
|
"types/",
|
|
56
46
|
".gitignore",
|
|
57
47
|
".npmignore",
|
|
@@ -64,8 +54,8 @@
|
|
|
64
54
|
"tsconfig.json",
|
|
65
55
|
"LICENSE",
|
|
66
56
|
"main.ts",
|
|
57
|
+
"check.ts",
|
|
67
58
|
"env.ts",
|
|
68
|
-
"entry.ts",
|
|
69
59
|
"menu.json",
|
|
70
60
|
"paths.ts",
|
|
71
61
|
"util.ts",
|
|
@@ -76,9 +66,8 @@
|
|
|
76
66
|
"bun": ">=1.3.0"
|
|
77
67
|
},
|
|
78
68
|
"dependencies": {
|
|
79
|
-
"chalk": "^5.6.2",
|
|
80
69
|
"es-toolkit": "^1.41.0",
|
|
81
70
|
"pathe": "^2.0.3"
|
|
82
71
|
},
|
|
83
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "cdd2d42fdd5e0f887b434fa70dff72028d9e31ed"
|
|
84
73
|
}
|
package/paths.ts
CHANGED
|
@@ -8,24 +8,6 @@
|
|
|
8
8
|
* - root* 系列:Core 框架内部路径(packages/core/*)
|
|
9
9
|
* - project* 系列:用户项目路径(process.cwd()/*)
|
|
10
10
|
*
|
|
11
|
-
* 目录结构:
|
|
12
|
-
* ```
|
|
13
|
-
* packages/core/ (coreDir)
|
|
14
|
-
* ├── scripts/ (coreScriptDir)
|
|
15
|
-
* ├── config/ (coreConfigDir)
|
|
16
|
-
* ├── checks/ (coreCheckDir)
|
|
17
|
-
* ├── plugins/ (corePluginDir)
|
|
18
|
-
* ├── apis/ (coreApiDir)
|
|
19
|
-
* └── tables/ (coreTableDir)
|
|
20
|
-
*
|
|
21
|
-
* project/ (projectDir)
|
|
22
|
-
* ├── scripts/ (projectScriptDir)
|
|
23
|
-
* ├── config/ (projectConfigDir)
|
|
24
|
-
* ├── checks/ (projectCheckDir)
|
|
25
|
-
* ├── plugins/ (projectPluginDir)
|
|
26
|
-
* ├── apis/ (projectApiDir)
|
|
27
|
-
* └── tables/ (projectTableDir)
|
|
28
|
-
* ```
|
|
29
11
|
*/
|
|
30
12
|
|
|
31
13
|
import { fileURLToPath } from 'node:url';
|
|
@@ -35,9 +17,6 @@ import { dirname, join } from 'pathe';
|
|
|
35
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
36
18
|
const __dirname = dirname(__filename);
|
|
37
19
|
|
|
38
|
-
// 项目根目录(befly 框架的使用方项目)
|
|
39
|
-
const projectRoot = process.cwd();
|
|
40
|
-
|
|
41
20
|
// ==================== Core 框架路径 ====================
|
|
42
21
|
|
|
43
22
|
/**
|
|
@@ -46,20 +25,6 @@ const projectRoot = process.cwd();
|
|
|
46
25
|
*/
|
|
47
26
|
export const coreDir = __dirname;
|
|
48
27
|
|
|
49
|
-
/**
|
|
50
|
-
* Core 框架脚本目录
|
|
51
|
-
* @description packages/core/scripts/
|
|
52
|
-
* @usage 存放框架级别的脚本工具
|
|
53
|
-
*/
|
|
54
|
-
export const coreScriptDir = join(__dirname, 'scripts');
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Core 框架配置目录
|
|
58
|
-
* @description packages/core/config/
|
|
59
|
-
* @usage 存放框架默认配置(env.ts, fields.ts 等)
|
|
60
|
-
*/
|
|
61
|
-
export const coreConfigDir = join(__dirname, 'config');
|
|
62
|
-
|
|
63
28
|
/**
|
|
64
29
|
* Core 框架检查目录
|
|
65
30
|
* @description packages/core/checks/
|
|
@@ -95,46 +60,32 @@ export const coreTableDir = join(__dirname, 'tables');
|
|
|
95
60
|
* @description process.cwd()
|
|
96
61
|
* @usage 用户项目的根目录
|
|
97
62
|
*/
|
|
98
|
-
export const projectDir =
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 项目脚本目录
|
|
102
|
-
* @description {projectDir}/scripts/
|
|
103
|
-
* @usage 存放用户自定义脚本工具
|
|
104
|
-
*/
|
|
105
|
-
export const projectScriptDir = join(projectRoot, 'scripts');
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 项目配置目录
|
|
109
|
-
* @description {projectDir}/config/
|
|
110
|
-
* @usage 存放用户项目配置(覆盖框架默认配置)
|
|
111
|
-
*/
|
|
112
|
-
export const projectConfigDir = join(projectRoot, 'config');
|
|
63
|
+
export const projectDir = process.cwd();
|
|
113
64
|
|
|
114
65
|
/**
|
|
115
66
|
* 项目检查目录
|
|
116
67
|
* @description {projectDir}/checks/
|
|
117
68
|
* @usage 存放用户自定义启动检查模块
|
|
118
69
|
*/
|
|
119
|
-
export const projectCheckDir = join(
|
|
70
|
+
export const projectCheckDir = join(projectDir, 'checks');
|
|
120
71
|
|
|
121
72
|
/**
|
|
122
73
|
* 项目插件目录
|
|
123
74
|
* @description {projectDir}/plugins/
|
|
124
75
|
* @usage 存放用户自定义插件
|
|
125
76
|
*/
|
|
126
|
-
export const projectPluginDir = join(
|
|
77
|
+
export const projectPluginDir = join(projectDir, 'plugins');
|
|
127
78
|
|
|
128
79
|
/**
|
|
129
80
|
* 项目 API 目录
|
|
130
81
|
* @description {projectDir}/apis/
|
|
131
82
|
* @usage 存放用户业务 API 接口
|
|
132
83
|
*/
|
|
133
|
-
export const projectApiDir = join(
|
|
84
|
+
export const projectApiDir = join(projectDir, 'apis');
|
|
134
85
|
|
|
135
86
|
/**
|
|
136
87
|
* 项目表定义目录
|
|
137
88
|
* @description {projectDir}/tables/
|
|
138
89
|
* @usage 存放用户业务表定义(JSON 格式)
|
|
139
90
|
*/
|
|
140
|
-
export const projectTableDir = join(
|
|
91
|
+
export const projectTableDir = join(projectDir, 'tables');
|
package/plugins/cache.ts
CHANGED
package/plugins/db.ts
CHANGED
package/plugins/logger.ts
CHANGED
package/plugins/redis.ts
CHANGED
|
@@ -23,12 +23,6 @@ const redisPlugin: Plugin = {
|
|
|
23
23
|
// 初始化 Redis 客户端(统一使用 database.ts 的连接管理)
|
|
24
24
|
await Database.connectRedis();
|
|
25
25
|
|
|
26
|
-
Logger.info('Redis 插件初始化成功', {
|
|
27
|
-
host: Env.REDIS_HOST,
|
|
28
|
-
port: Env.REDIS_PORT,
|
|
29
|
-
db: Env.REDIS_DB
|
|
30
|
-
});
|
|
31
|
-
|
|
32
26
|
// 返回工具对象,向下游以相同 API 暴露
|
|
33
27
|
return RedisHelper;
|
|
34
28
|
} else {
|