Files
SnowLuma/.pnpm-store/v11/files/89/c5ecdb8b1b6fd9047eb638b5d99c68c98786c7c79b6a40065ea0db0bd4c0bd1640f8f15208080a5c451671095270282d8a6efa39a572223600778bcbaae394
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Skipped
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

54 lines
1.9 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_utils_color = require("../../utils/color.js");
const require_utils_handler = require("../../utils/handler.js");
//#region src/helper/dev/index.ts
const handlerName = (handler) => {
return handler.name || (require_utils_handler.isMiddleware(handler) ? "[middleware]" : "[handler]");
};
const inspectRoutes = (hono) => {
return hono.routes.map(({ path, method, handler }) => {
const targetHandler = require_utils_handler.findTargetHandler(handler);
return {
path,
method,
name: handlerName(targetHandler),
isMiddleware: require_utils_handler.isMiddleware(targetHandler)
};
});
};
const showRoutes = (hono, opts) => {
const colorEnabled = opts?.colorize ?? require_utils_color.getColorEnabled();
const routeData = {};
let maxMethodLength = 0;
let maxPathLength = 0;
inspectRoutes(hono).filter(({ isMiddleware }) => opts?.verbose || !isMiddleware).map((route) => {
const key = `${route.method}-${route.path}`;
(routeData[key] ||= []).push(route);
if (routeData[key].length > 1) return;
maxMethodLength = Math.max(maxMethodLength, route.method.length);
maxPathLength = Math.max(maxPathLength, route.path.length);
return {
method: route.method,
path: route.path,
routes: routeData[key]
};
}).forEach((data) => {
if (!data) return;
const { method, path, routes } = data;
const methodStr = colorEnabled ? `\x1b[32m${method}\x1b[0m` : method;
console.log(`${methodStr} ${" ".repeat(maxMethodLength - method.length)} ${path}`);
if (!opts?.verbose) return;
routes.forEach(({ name }) => {
console.log(`${" ".repeat(maxMethodLength + 3)} ${name}`);
});
});
};
const getRouterName = (app) => {
app.router.match("GET", "/");
return app.router.name;
};
//#endregion
exports.getRouterName = getRouterName;
exports.inspectRoutes = inspectRoutes;
exports.showRoutes = showRoutes;