befly 3.3.0 → 3.3.1
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/commands/script.ts +3 -8
- package/commands/syncApi.ts +8 -9
- package/commands/syncDb/index.ts +4 -4
- package/package.json +2 -2
- package/util.ts +3 -5
package/commands/script.ts
CHANGED
|
@@ -105,27 +105,22 @@ function scanCliScripts(): Array<{ scriptName: string; scriptPath: string }> {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
* 扫描 node_modules/@befly
|
|
108
|
+
* 扫描 node_modules/@befly-addon/* 下的 scripts
|
|
109
109
|
*/
|
|
110
110
|
function scanAddonScripts(projectRoot: string): Array<{ addonName: string; scriptName: string; scriptPath: string }> {
|
|
111
111
|
const results: Array<{ addonName: string; scriptName: string; scriptPath: string }> = [];
|
|
112
112
|
|
|
113
113
|
try {
|
|
114
|
-
const beflyAddonsDir = join(projectRoot, 'node_modules', '@befly');
|
|
114
|
+
const beflyAddonsDir = join(projectRoot, 'node_modules', '@befly-addon');
|
|
115
115
|
|
|
116
116
|
if (!existsSync(beflyAddonsDir)) {
|
|
117
117
|
return results;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
// 读取 @befly 目录下的所有 addon
|
|
120
|
+
// 读取 @befly-addon 目录下的所有 addon
|
|
121
121
|
const addonDirs = readdirSync(beflyAddonsDir);
|
|
122
122
|
|
|
123
123
|
for (const addonDir of addonDirs) {
|
|
124
|
-
// 只处理 addon-* 开头的目录
|
|
125
|
-
if (!addonDir.startsWith('addon-')) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
124
|
const scriptsDir = join(beflyAddonsDir, addonDir, 'scripts');
|
|
130
125
|
|
|
131
126
|
if (!existsSync(scriptsDir)) {
|
package/commands/syncApi.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 流程:
|
|
6
6
|
* 1. 扫描 core/apis 目录下所有 Core API 文件
|
|
7
7
|
* 2. 扫描项目 apis 目录下所有项目 API 文件
|
|
8
|
-
* 3. 扫描 node_modules/@befly
|
|
8
|
+
* 3. 扫描 node_modules/@befly-addon/* 目录下所有组件 API 文件
|
|
9
9
|
* 4. 提取每个 API 的 name、method、auth 等信息
|
|
10
10
|
* 5. 根据接口路径检查是否存在
|
|
11
11
|
* 6. 存在则更新,不存在则新增
|
|
@@ -138,24 +138,23 @@ async function scanAllApis(projectRoot: string): Promise<ApiInfo[]> {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
// 3. 扫描组件 API (node_modules/@befly
|
|
142
|
-
Logger.info('\n=== 扫描组件 API (node_modules/@befly
|
|
141
|
+
// 3. 扫描组件 API (node_modules/@befly-addon/*)
|
|
142
|
+
Logger.info('\n=== 扫描组件 API (node_modules/@befly-addon/*) ===');
|
|
143
143
|
const addonNames = scanAddons();
|
|
144
144
|
|
|
145
|
-
for (const
|
|
146
|
-
//
|
|
147
|
-
const addonName = fullAddonName.replace('addon-', ''); // 移除 addon- 前缀
|
|
145
|
+
for (const addonName of addonNames) {
|
|
146
|
+
// addonName 格式: admin, demo 等
|
|
148
147
|
|
|
149
148
|
// 检查 apis 子目录是否存在
|
|
150
|
-
if (!addonDirExists(
|
|
149
|
+
if (!addonDirExists(addonName, 'apis')) {
|
|
151
150
|
Logger.info(` [${addonName}] 无 apis 目录,跳过`);
|
|
152
151
|
continue;
|
|
153
152
|
}
|
|
154
153
|
|
|
155
|
-
const addonApisDir = getAddonDir(
|
|
154
|
+
const addonApisDir = getAddonDir(addonName, 'apis');
|
|
156
155
|
|
|
157
156
|
// 读取 addon 配置
|
|
158
|
-
const addonConfigPath = getAddonDir(
|
|
157
|
+
const addonConfigPath = getAddonDir(addonName, 'addon.config.json');
|
|
159
158
|
let addonTitle = addonName;
|
|
160
159
|
try {
|
|
161
160
|
const configFile = Bun.file(addonConfigPath);
|
package/commands/syncDb/index.ts
CHANGED
|
@@ -139,8 +139,8 @@ export const SyncDb = async (): Promise<void> => {
|
|
|
139
139
|
// 确定表名:
|
|
140
140
|
// - core 表:core_{表名}
|
|
141
141
|
// 例如:user.json → core_user
|
|
142
|
-
// - addon 表:
|
|
143
|
-
// 例如:
|
|
142
|
+
// - addon 表:{addonName}_{表名}
|
|
143
|
+
// 例如:admin addon 的 user.json → admin_user
|
|
144
144
|
// - 项目表:{表名}
|
|
145
145
|
// 例如:user.json → user
|
|
146
146
|
let tableName = snakeCase(fileName);
|
|
@@ -148,8 +148,8 @@ export const SyncDb = async (): Promise<void> => {
|
|
|
148
148
|
// core 框架表,添加 core_ 前缀
|
|
149
149
|
tableName = `core_${tableName}`;
|
|
150
150
|
} else if (type === 'addon') {
|
|
151
|
-
// addon 表,添加
|
|
152
|
-
// 使用 snakeCase 统一转换(
|
|
151
|
+
// addon 表,添加 {addonName}_ 前缀
|
|
152
|
+
// 使用 snakeCase 统一转换(admin → admin)
|
|
153
153
|
const addonNameSnake = snakeCase(addonName!);
|
|
154
154
|
tableName = `${addonNameSnake}_${tableName}`;
|
|
155
155
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"ora": "^9.0.0",
|
|
79
79
|
"pathe": "^2.0.3"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "66e103e5effbb89dd6de894972766fa1a03d564e"
|
|
82
82
|
}
|
package/util.ts
CHANGED
|
@@ -241,7 +241,7 @@ export const parseRule = (rule: string): ParsedFieldRule => {
|
|
|
241
241
|
* 扫描所有可用的 addon
|
|
242
242
|
*/
|
|
243
243
|
export const scanAddons = (): string[] => {
|
|
244
|
-
const beflyDir = join(paths.projectDir, 'node_modules', '@befly');
|
|
244
|
+
const beflyDir = join(paths.projectDir, 'node_modules', '@befly-addon');
|
|
245
245
|
|
|
246
246
|
if (!existsSync(beflyDir)) {
|
|
247
247
|
return [];
|
|
@@ -251,9 +251,7 @@ export const scanAddons = (): string[] => {
|
|
|
251
251
|
return fs
|
|
252
252
|
.readdirSync(beflyDir)
|
|
253
253
|
.filter((name) => {
|
|
254
|
-
//
|
|
255
|
-
const kebabName = kebabCase(name);
|
|
256
|
-
if (!kebabName.startsWith('addon-')) return false;
|
|
254
|
+
// addon 名称格式:admin, demo 等(不带 addon- 前缀)
|
|
257
255
|
const fullPath = join(beflyDir, name);
|
|
258
256
|
try {
|
|
259
257
|
const stat = statSync(fullPath);
|
|
@@ -272,7 +270,7 @@ export const scanAddons = (): string[] => {
|
|
|
272
270
|
* 获取 addon 的指定子目录路径
|
|
273
271
|
*/
|
|
274
272
|
export const getAddonDir = (addonName: string, subDir: string): string => {
|
|
275
|
-
return join(paths.projectDir, 'node_modules', '@befly', addonName, subDir);
|
|
273
|
+
return join(paths.projectDir, 'node_modules', '@befly-addon', addonName, subDir);
|
|
276
274
|
};
|
|
277
275
|
|
|
278
276
|
/**
|