var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { attachDirToRouter: () => attachDirToRouter }); module.exports = __toCommonJS(src_exports); var import_fast_glob = __toESM(require("fast-glob"), 1); var path = __toESM(require("path"), 1); async function attachDirToRouter(router, source) { const files = await (0, import_fast_glob.default)(`${source}/**/*.(ts|js)`, { onlyFiles: true }); for (const file of files.filter((file2) => path.basename(file2) === "index.js").sort()) { const f = path.relative(source, file); const tempm = await import(file); const mpath = `/${f.slice(0, f.lastIndexOf(path.sep) + 1)}`.replace( /\/_/g, "/:" ); const basename2 = path.basename(f, path.extname(f)); ["get", "post", "put", "delete"].map((method) => { for (const tempmethod in tempm) { if (tempmethod.toUpperCase() === method.toUpperCase()) { return { method, functionname: tempmethod }; } } return { method, functionname: null }; }).filter(({ functionname }) => functionname != null).forEach(({ method, functionname }) => { router[method]( `${mpath}${basename2 === "index" ? "" : basename2}`.replace(/\\/g, "/"), // @ts-expect-error functionname exists tempm[functionname] ); }); } return router; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { attachDirToRouter }); //# sourceMappingURL=index.cjs.map