file-routing-expressjs
Version:
A dependency-free, flexible, system-based file routing for Express.
58 lines • 1.94 kB
JavaScript
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());
});
};
import { normalizeCLIOptions } from "../helpers/validators";
import FileBasedRouting from "../models/file-based-routing";
import fs from "fs";
import path from "path";
import { printTable, printTree } from "../helpers/cli";
import { logger } from "../helpers/logging";
import { program } from "./program";
function configCollectCommand() {
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 = normalizeCLIOptions(options);
const endpoints = yield FileBasedRouting.collectRoutes(config.target);
switch (config.output) {
case "json":
const dir = path.join(process.cwd(), ".fre", "routes");
fs.mkdirSync(dir, { recursive: true });
const file = path.join(dir, `${Date.now()}.json`);
fs.writeFileSync(file, JSON.stringify(endpoints, null, 2), "utf-8");
logger.info(`Saved to ${file}`);
break;
case "table":
printTable(endpoints);
break;
default:
printTree(endpoints);
break;
}
} catch (err) {
logger.error(err.message);
process.exit(1);
}
}));
return program;
}
export {
configCollectCommand as default
};
//# sourceMappingURL=collect.mjs.map