UNPKG

file-routing-expressjs

Version:

A dependency-free, flexible, system-based file routing for Express.

88 lines 3.69 kB
"use strict"; 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); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; var collect_exports = {}; __export(collect_exports, { default: () => configCollectCommand }); module.exports = __toCommonJS(collect_exports); var import_validators = require("../helpers/validators"); var import_file_based_routing = __toESM(require("../models/file-based-routing")); var import_fs = __toESM(require("fs")); var import_path = __toESM(require("path")); var import_cli = require("../helpers/cli"); var import_logging = require("../helpers/logging"); var import_program = require("./program"); function configCollectCommand() { import_program.program.command("collect").option("--target <path>", "base folder for endpoints", "./src/routes").option("--output <type>", "tree | json | table", "tree").action((options) => __async(this, null, function* () { try { const config = (0, import_validators.normalizeCLIOptions)(options); const endpoints = yield import_file_based_routing.default.collectRoutes(config.target); switch (config.output) { case "json": const dir = import_path.default.join(process.cwd(), ".fre", "routes"); import_fs.default.mkdirSync(dir, { recursive: true }); const file = import_path.default.join(dir, `${Date.now()}.json`); import_fs.default.writeFileSync(file, JSON.stringify(endpoints, null, 2), "utf-8"); import_logging.logger.info(`Saved to ${file}`); break; case "table": (0, import_cli.printTable)(endpoints); break; default: (0, import_cli.printTree)(endpoints); break; } } catch (err) { import_logging.logger.error(err.message); process.exit(1); } })); return import_program.program; } //# sourceMappingURL=collect.js.map