befly 3.13.8 → 3.13.9
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/dist/befly.js +81 -89
- package/dist/befly.min.js +12 -12
- package/dist/sync/syncApi.js +19 -9
- package/dist/types/sync.d.ts +2 -0
- package/dist/utils/loadMenuConfigs.d.ts +1 -19
- package/dist/utils/loadMenuConfigs.js +23 -63
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -978,6 +978,43 @@ var init_logger = __esm(() => {
|
|
|
978
978
|
Logger = new LoggerFacade;
|
|
979
979
|
});
|
|
980
980
|
|
|
981
|
+
// utils/importDefault.ts
|
|
982
|
+
import { isAbsolute } from "path";
|
|
983
|
+
import { pathToFileURL } from "url";
|
|
984
|
+
function isWindowsAbsPath(file) {
|
|
985
|
+
return /^[a-zA-Z]:[\\/]/.test(file);
|
|
986
|
+
}
|
|
987
|
+
function toFileImportUrl(file) {
|
|
988
|
+
if (isAbsolute(file) || isWindowsAbsPath(file)) {
|
|
989
|
+
return pathToFileURL(file).href;
|
|
990
|
+
}
|
|
991
|
+
return file;
|
|
992
|
+
}
|
|
993
|
+
async function importDefault(file, defaultValue) {
|
|
994
|
+
try {
|
|
995
|
+
const isJson = file.endsWith(".json");
|
|
996
|
+
const mod = isJson ? await import(toFileImportUrl(file), { with: { type: "json" } }) : await import(file);
|
|
997
|
+
const value = mod?.default;
|
|
998
|
+
if (value === null || value === undefined) {
|
|
999
|
+
return defaultValue;
|
|
1000
|
+
}
|
|
1001
|
+
const expectedType = getTypeTag(defaultValue);
|
|
1002
|
+
const actualType = getTypeTag(value);
|
|
1003
|
+
if (expectedType !== actualType) {
|
|
1004
|
+
Logger.warn({ file, msg: "importDefault \u5BFC\u5165\u7C7B\u578B\u4E0E\u9ED8\u8BA4\u503C\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u503C", expectedType, actualType });
|
|
1005
|
+
return defaultValue;
|
|
1006
|
+
}
|
|
1007
|
+
return value;
|
|
1008
|
+
} catch (err) {
|
|
1009
|
+
Logger.warn({ err, file, msg: "importDefault \u5BFC\u5165\u5931\u8D25\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u503C" });
|
|
1010
|
+
return defaultValue;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
var init_importDefault = __esm(() => {
|
|
1014
|
+
init_logger();
|
|
1015
|
+
init_util();
|
|
1016
|
+
});
|
|
1017
|
+
|
|
981
1018
|
// ../../node_modules/.bun/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
982
1019
|
function normalizeWindowsPath(input = "") {
|
|
983
1020
|
if (!input) {
|
|
@@ -1205,31 +1242,18 @@ var init_isDirentDirectory = __esm(() => {
|
|
|
1205
1242
|
|
|
1206
1243
|
// utils/loadMenuConfigs.ts
|
|
1207
1244
|
import { existsSync as existsSync2 } from "fs";
|
|
1208
|
-
import { readdir
|
|
1209
|
-
function
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
function extractScriptSetupBlock(vueContent) {
|
|
1213
|
-
const openTag = /<script\b[^>]*\bsetup\b[^>]*>/i.exec(vueContent);
|
|
1214
|
-
if (!openTag) {
|
|
1215
|
-
return null;
|
|
1216
|
-
}
|
|
1217
|
-
const start = openTag.index + openTag[0].length;
|
|
1218
|
-
const closeIndex = vueContent.indexOf("</script>", start);
|
|
1219
|
-
if (closeIndex < 0) {
|
|
1245
|
+
import { readdir } from "fs/promises";
|
|
1246
|
+
function normalizeViewDirMeta(input) {
|
|
1247
|
+
if (!input || typeof input !== "object") {
|
|
1220
1248
|
return null;
|
|
1221
1249
|
}
|
|
1222
|
-
|
|
1223
|
-
}
|
|
1224
|
-
function extractDefinePageMetaFromScriptSetup(scriptSetup) {
|
|
1225
|
-
const titleMatch = scriptSetup.match(/definePage\s*\([\s\S]*?meta\s*:\s*\{[\s\S]*?title\s*:\s*(["'`])([^"'`]+)\1/);
|
|
1226
|
-
if (!titleMatch) {
|
|
1250
|
+
if (typeof input.title !== "string" || !input.title) {
|
|
1227
1251
|
return null;
|
|
1228
1252
|
}
|
|
1229
|
-
const
|
|
1253
|
+
const order = typeof input.order === "number" && Number.isFinite(input.order) && Number.isInteger(input.order) && input.order >= 0 ? input.order : undefined;
|
|
1230
1254
|
return {
|
|
1231
|
-
title:
|
|
1232
|
-
order
|
|
1255
|
+
title: input.title,
|
|
1256
|
+
order
|
|
1233
1257
|
};
|
|
1234
1258
|
}
|
|
1235
1259
|
async function scanViewsDirToMenuConfigs(viewsDir, prefix, parentPath = "") {
|
|
@@ -1243,31 +1267,26 @@ async function scanViewsDirToMenuConfigs(viewsDir, prefix, parentPath = "") {
|
|
|
1243
1267
|
continue;
|
|
1244
1268
|
}
|
|
1245
1269
|
const dirPath = join2(viewsDir, entry.name);
|
|
1270
|
+
const metaJsonPath = join2(dirPath, "meta.json");
|
|
1246
1271
|
const indexVuePath = join2(dirPath, "index.vue");
|
|
1272
|
+
let meta = null;
|
|
1273
|
+
if (!existsSync2(metaJsonPath)) {
|
|
1274
|
+
continue;
|
|
1275
|
+
}
|
|
1247
1276
|
if (!existsSync2(indexVuePath)) {
|
|
1277
|
+
Logger.warn({ path: dirPath, msg: "\u76EE\u5F55\u5B58\u5728 meta.json \u4F46\u7F3A\u5C11 index.vue\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u5F55\u83DC\u5355\u540C\u6B65" });
|
|
1248
1278
|
continue;
|
|
1249
1279
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
if (!scriptSetup) {
|
|
1255
|
-
Logger.warn({ path: indexVuePath, msg: "index.vue \u7F3A\u5C11 <script setup>\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u5F55\u83DC\u5355\u540C\u6B65" });
|
|
1256
|
-
continue;
|
|
1257
|
-
}
|
|
1258
|
-
meta = extractDefinePageMetaFromScriptSetup(scriptSetup);
|
|
1259
|
-
if (!meta?.title) {
|
|
1260
|
-
Logger.warn({ path: indexVuePath, msg: "index.vue \u672A\u58F0\u660E definePage({ meta: { title, order? } })\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u5F55\u83DC\u5355\u540C\u6B65" });
|
|
1261
|
-
continue;
|
|
1262
|
-
}
|
|
1263
|
-
} catch (error) {
|
|
1264
|
-
Logger.warn({ err: error, path: indexVuePath, msg: "\u8BFB\u53D6 index.vue \u5931\u8D25" });
|
|
1280
|
+
const metaRaw = await importDefault(metaJsonPath, {});
|
|
1281
|
+
meta = normalizeViewDirMeta(metaRaw);
|
|
1282
|
+
if (!meta?.title) {
|
|
1283
|
+
Logger.warn({ path: metaJsonPath, msg: "meta.json \u7F3A\u5C11\u6709\u6548\u7684 title\uFF08\u4EE5\u53CA\u53EF\u9009 order:number\uFF09\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u5F55\u83DC\u5355\u540C\u6B65" });
|
|
1265
1284
|
continue;
|
|
1266
1285
|
}
|
|
1267
1286
|
if (!meta?.title) {
|
|
1268
1287
|
continue;
|
|
1269
1288
|
}
|
|
1270
|
-
const cleanName =
|
|
1289
|
+
const cleanName = String(entry.name).replace(/_\d+$/, "");
|
|
1271
1290
|
let menuPath;
|
|
1272
1291
|
if (cleanName === "index") {
|
|
1273
1292
|
menuPath = parentPath;
|
|
@@ -1325,16 +1344,11 @@ async function loadMenuConfigs(addons) {
|
|
|
1325
1344
|
}
|
|
1326
1345
|
const menusJsonPath = join2(process.cwd(), "menus.json");
|
|
1327
1346
|
if (existsSync2(menusJsonPath)) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
const
|
|
1331
|
-
|
|
1332
|
-
for (const menu of appMenus) {
|
|
1333
|
-
allMenus.push(menu);
|
|
1334
|
-
}
|
|
1347
|
+
const appMenus = await importDefault(menusJsonPath, []);
|
|
1348
|
+
if (Array.isArray(appMenus) && appMenus.length > 0) {
|
|
1349
|
+
for (const menu of appMenus) {
|
|
1350
|
+
allMenus.push(menu);
|
|
1335
1351
|
}
|
|
1336
|
-
} catch (error) {
|
|
1337
|
-
Logger.warn({ err: error, msg: "\u8BFB\u53D6\u9879\u76EE menus.json \u5931\u8D25" });
|
|
1338
1352
|
}
|
|
1339
1353
|
}
|
|
1340
1354
|
return allMenus;
|
|
@@ -1342,6 +1356,7 @@ async function loadMenuConfigs(addons) {
|
|
|
1342
1356
|
var init_loadMenuConfigs = __esm(() => {
|
|
1343
1357
|
init_dist();
|
|
1344
1358
|
init_logger();
|
|
1359
|
+
init_importDefault();
|
|
1345
1360
|
init_isDirentDirectory();
|
|
1346
1361
|
});
|
|
1347
1362
|
|
|
@@ -7408,43 +7423,9 @@ var require_src = __commonJS((exports, module) => {
|
|
|
7408
7423
|
});
|
|
7409
7424
|
|
|
7410
7425
|
// befly.config.ts
|
|
7426
|
+
init_importDefault();
|
|
7411
7427
|
import { join } from "path";
|
|
7412
7428
|
|
|
7413
|
-
// utils/importDefault.ts
|
|
7414
|
-
init_logger();
|
|
7415
|
-
init_util();
|
|
7416
|
-
import { isAbsolute } from "path";
|
|
7417
|
-
import { pathToFileURL } from "url";
|
|
7418
|
-
function isWindowsAbsPath(file) {
|
|
7419
|
-
return /^[a-zA-Z]:[\\/]/.test(file);
|
|
7420
|
-
}
|
|
7421
|
-
function toFileImportUrl(file) {
|
|
7422
|
-
if (isAbsolute(file) || isWindowsAbsPath(file)) {
|
|
7423
|
-
return pathToFileURL(file).href;
|
|
7424
|
-
}
|
|
7425
|
-
return file;
|
|
7426
|
-
}
|
|
7427
|
-
async function importDefault(file, defaultValue) {
|
|
7428
|
-
try {
|
|
7429
|
-
const isJson = file.endsWith(".json");
|
|
7430
|
-
const mod = isJson ? await import(toFileImportUrl(file), { with: { type: "json" } }) : await import(file);
|
|
7431
|
-
const value = mod?.default;
|
|
7432
|
-
if (value === null || value === undefined) {
|
|
7433
|
-
return defaultValue;
|
|
7434
|
-
}
|
|
7435
|
-
const expectedType = getTypeTag(defaultValue);
|
|
7436
|
-
const actualType = getTypeTag(value);
|
|
7437
|
-
if (expectedType !== actualType) {
|
|
7438
|
-
Logger.warn({ file, msg: "importDefault \u5BFC\u5165\u7C7B\u578B\u4E0E\u9ED8\u8BA4\u503C\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u503C", expectedType, actualType });
|
|
7439
|
-
return defaultValue;
|
|
7440
|
-
}
|
|
7441
|
-
return value;
|
|
7442
|
-
} catch (err) {
|
|
7443
|
-
Logger.warn({ err, file, msg: "importDefault \u5BFC\u5165\u5931\u8D25\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u503C" });
|
|
7444
|
-
return defaultValue;
|
|
7445
|
-
}
|
|
7446
|
-
}
|
|
7447
|
-
|
|
7448
7429
|
// utils/mergeAndConcat.ts
|
|
7449
7430
|
init_util();
|
|
7450
7431
|
function cloneDeepLoose(value) {
|
|
@@ -8816,7 +8797,7 @@ async function syncApi(ctx, apis) {
|
|
|
8816
8797
|
}
|
|
8817
8798
|
const allDbApis = await ctx.db.getAll({
|
|
8818
8799
|
table: tableName,
|
|
8819
|
-
fields: ["id", "routePath", "name", "addonName", "state"],
|
|
8800
|
+
fields: ["id", "routePath", "name", "addonName", "auth", "state"],
|
|
8820
8801
|
where: { state$gte: 0 }
|
|
8821
8802
|
});
|
|
8822
8803
|
const dbLists = allDbApis.data.lists || [];
|
|
@@ -8830,16 +8811,24 @@ async function syncApi(ctx, apis) {
|
|
|
8830
8811
|
if (apiType && apiType !== "api") {
|
|
8831
8812
|
continue;
|
|
8832
8813
|
}
|
|
8833
|
-
const
|
|
8834
|
-
|
|
8814
|
+
const normalizedAuth = api.auth === 0 || api.auth === false ? 0 : 1;
|
|
8815
|
+
const normalizedApi = {
|
|
8816
|
+
name: api.name,
|
|
8817
|
+
routePath: api.routePath,
|
|
8818
|
+
addonName: api.addonName,
|
|
8819
|
+
auth: normalizedAuth
|
|
8820
|
+
};
|
|
8821
|
+
const routePath = normalizedApi.routePath;
|
|
8822
|
+
apiRouteKeys.add(routePath);
|
|
8835
8823
|
const item = allDbApiMap[routePath];
|
|
8836
8824
|
if (item) {
|
|
8837
|
-
const
|
|
8825
|
+
const dbAuth = item.auth === 0 || item.auth === false ? 0 : 1;
|
|
8826
|
+
const shouldUpdate = normalizedApi.name !== item.name || normalizedApi.routePath !== item.routePath || normalizedApi.addonName !== item.addonName || normalizedAuth !== dbAuth;
|
|
8838
8827
|
if (shouldUpdate) {
|
|
8839
|
-
updData.push({ id: item.id, api });
|
|
8828
|
+
updData.push({ id: item.id, api: normalizedApi });
|
|
8840
8829
|
}
|
|
8841
8830
|
} else {
|
|
8842
|
-
insData.push(
|
|
8831
|
+
insData.push(normalizedApi);
|
|
8843
8832
|
}
|
|
8844
8833
|
}
|
|
8845
8834
|
for (const record of dbLists) {
|
|
@@ -8855,7 +8844,8 @@ async function syncApi(ctx, apis) {
|
|
|
8855
8844
|
data: {
|
|
8856
8845
|
name: item.api.name,
|
|
8857
8846
|
routePath: item.api.routePath,
|
|
8858
|
-
addonName: item.api.addonName
|
|
8847
|
+
addonName: item.api.addonName,
|
|
8848
|
+
auth: item.api.auth === 0 || item.api.auth === false ? 0 : 1
|
|
8859
8849
|
}
|
|
8860
8850
|
};
|
|
8861
8851
|
}));
|
|
@@ -8869,7 +8859,8 @@ async function syncApi(ctx, apis) {
|
|
|
8869
8859
|
return {
|
|
8870
8860
|
name: api.name,
|
|
8871
8861
|
routePath: api.routePath,
|
|
8872
|
-
addonName: api.addonName
|
|
8862
|
+
addonName: api.addonName,
|
|
8863
|
+
auth: api.auth === 0 || api.auth === false ? 0 : 1
|
|
8873
8864
|
};
|
|
8874
8865
|
}));
|
|
8875
8866
|
} catch (error) {
|
|
@@ -15088,8 +15079,9 @@ function scanCoreBuiltinHooks() {
|
|
|
15088
15079
|
|
|
15089
15080
|
// utils/scanFiles.ts
|
|
15090
15081
|
init_dist();
|
|
15091
|
-
|
|
15082
|
+
init_importDefault();
|
|
15092
15083
|
init_util();
|
|
15084
|
+
import { existsSync as existsSync4 } from "fs";
|
|
15093
15085
|
function parseAddonNameFromPath(normalizedPath) {
|
|
15094
15086
|
const parts = normalizedPath.split("/").filter(Boolean);
|
|
15095
15087
|
const idx = parts.indexOf("@befly-addon");
|