@blitzjs/cli
Version:
Blitz.js CLI
80 lines (79 loc) • 3.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Routes = void 0;
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const logging_1 = require("next/dist/server/lib/logging");
const logging_2 = require("next/dist/server/lib/logging");
class Routes extends command_1.Command {
getColor(type) {
switch (type) {
case "rpc":
return "magenta";
case "api":
return "blue";
default:
return "green";
}
}
run() {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
const config = {
rootFolder: process.cwd(),
env: "dev",
};
this.parse(Routes);
process.env.BLITZ_APP_DIR = config.rootFolder;
try {
const { loadConfigProduction } = yield Promise.resolve().then(() => (0, tslib_1.__importStar)(require("next/dist/server/config-shared")));
const { collectAllRoutes } = yield Promise.resolve().then(() => (0, tslib_1.__importStar)(require("next/dist/build/routes")));
const config = loadConfigProduction(process.cwd());
const routes = yield collectAllRoutes(process.cwd(), config);
(0, logging_2.newline)();
const table = new logging_1.table({
columns: [
{ name: "HTTP", alignment: "center" },
{ name: "Source File", alignment: "left" },
{ name: "Route Path", alignment: "left" },
{ name: "Type", alignment: "center" },
],
sort: (q, r) => {
// Sort pages to the top
if (q.Type === "PAGE" && r.Type !== "PAGE") {
return -1;
}
if (q.Type !== "PAGE" && r.Type === "PAGE") {
return 1;
}
if (q.Type > r.Type) {
return 1;
}
if (q.Type < r.Type) {
return -1;
}
return 0;
},
});
routes.forEach(({ filePath, route, verb, type }) => {
table.addRow({
[table.table.columns[0].name]: verb.toUpperCase(),
[table.table.columns[1].name]: filePath,
[table.table.columns[2].name]: route,
[table.table.columns[3].name]: type.toUpperCase(),
}, { color: this.getColor(type) });
});
console.log(table.render());
}
catch (err) {
console.error(err);
process.exit(1);
}
});
}
}
exports.Routes = Routes;
Routes.description = "Display all Blitz URL Routes";
Routes.aliases = ["r"];
Routes.flags = {
help: command_1.flags.help({ char: "h" }),
};