78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var utils_exports = {};
|
|
__export(utils_exports, {
|
|
dirname: () => dirname,
|
|
filterStaticGenerateRoutes: () => filterStaticGenerateRoutes,
|
|
joinPaths: () => joinPaths
|
|
});
|
|
module.exports = __toCommonJS(utils_exports);
|
|
var import_router = require("../../router");
|
|
var import_handler = require("../../utils/handler");
|
|
const dirname = (path) => {
|
|
const splittedPath = path.split(/[\/\\]/);
|
|
return splittedPath.slice(0, -1).join("/");
|
|
};
|
|
const normalizePath = (path) => {
|
|
return path.replace(/(\\)/g, "/").replace(/\/$/g, "");
|
|
};
|
|
const handleDotDot = (resultPaths) => {
|
|
if (resultPaths.length === 0) {
|
|
resultPaths.push("..");
|
|
} else {
|
|
resultPaths.pop();
|
|
}
|
|
};
|
|
const handleNonDot = (path, resultPaths) => {
|
|
path = path.replace(/^\.(?!.)/, "");
|
|
if (path !== "") {
|
|
resultPaths.push(path);
|
|
}
|
|
};
|
|
const handleSegments = (paths, resultPaths) => {
|
|
for (const path of paths) {
|
|
if (path === "..") {
|
|
handleDotDot(resultPaths);
|
|
} else {
|
|
handleNonDot(path, resultPaths);
|
|
}
|
|
}
|
|
};
|
|
const joinPaths = (...paths) => {
|
|
paths = paths.map(normalizePath);
|
|
const resultPaths = [];
|
|
handleSegments(paths.join("/").split("/"), resultPaths);
|
|
return (paths[0][0] === "/" ? "/" : "") + resultPaths.join("/");
|
|
};
|
|
const filterStaticGenerateRoutes = (hono) => {
|
|
return hono.routes.reduce((acc, { method, handler, path }) => {
|
|
const targetHandler = (0, import_handler.findTargetHandler)(handler);
|
|
if (["GET", import_router.METHOD_NAME_ALL].includes(method) && !(0, import_handler.isMiddleware)(targetHandler)) {
|
|
acc.push({ path });
|
|
}
|
|
return acc;
|
|
}, []);
|
|
};
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
dirname,
|
|
filterStaticGenerateRoutes,
|
|
joinPaths
|
|
});
|