@choi2021/next-route-visualizer
Version:
๐บ๏ธ Visualize Next.js routes as an interactive diagram with advanced function analysis. Supports dynamic route detection, function-based navigation patterns, and comprehensive Next.js route mapping. Generate JSON data and beautiful HTML reports to explore
134 lines (133 loc) โข 6.22 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCli = createCli;
const commander_1 = require("commander");
const htmlReport_js_1 = require("./htmlReport.js");
const readline = __importStar(require("readline"));
function askForRoutesFile() {
return __awaiter(this, void 0, void 0, function* () {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise((resolve) => {
console.log("\n" + "=".repeat(60));
console.log("๐บ๏ธ Routes ์์ ํ์ผ ์ค์ ");
console.log("=".repeat(60));
console.log("");
console.log("ํ๋ก์ ํธ์์ ROUTES, PATHS ๋ฑ์ ์์๋ฅผ ์ ์ํ ํ์ผ์ด ์๋์?");
console.log("์ด ํ์ผ์ ์ง์ ํ๋ฉด ๋ณ์ ์ฐธ์กฐ๋ฅผ ์ ํํ๊ฒ ๊ฐ์งํ ์ ์์ต๋๋ค.");
console.log("");
console.log("๐ ์์:");
console.log(" โข src/routes.ts");
console.log(" โข constants/paths.js");
console.log(" โข lib/routes.tsx");
console.log(" โข config/urls.ts");
console.log(" โข src/routes.ts,src/api-routes.ts (์ฌ๋ฌ ํ์ผ)");
console.log("");
rl.question("๐ Routes ํ์ผ ๊ฒฝ๋ก๋ฅผ ์
๋ ฅํ์ธ์ (์ฌ๋ฌ ํ์ผ์ ์ผํ๋ก ๊ตฌ๋ถ, ์์ผ๋ฉด Enter๋ก ๊ฑด๋๋ฐ๊ธฐ): ", (answer) => {
rl.close();
const trimmed = answer.trim();
if (trimmed === "") {
console.log("โญ๏ธ ๊ฑด๋๋ฐ๊ธฐ - ์๋ ๊ฐ์ง๋ฅผ ์๋ํฉ๋๋ค...\n");
resolve(undefined);
}
else {
// ์ผํ๋ก ๊ตฌ๋ถ๋ ํ์ผ๋ค์ ๋ฐฐ์ด๋ก ๋ณํ
const files = trimmed
.split(",")
.map((file) => file.trim())
.filter((file) => file.length > 0);
console.log(`โ
Routes ํ์ผ: ${files.join(", ")}\n`);
resolve(files);
}
});
});
});
}
function createCli() {
const program = new commander_1.Command();
program
.name("next-route-map")
.description("๐บ๏ธ Visualize Next.js routes as an interactive diagram")
.version("1.0.10");
// ๊ธฐ๋ณธ ๋์ - ๊ฒฝ๋ก์ ์ต์
์ ๋ฐ์์ ๋ฆฌํฌํธ ์์ฑ
program
.argument("[path]", "Path to Next.js project", ".")
.option("-o, --output <filename>", "Output HTML filename", "route-report.html")
.option("-r, --routes-file <filepath>", "Path to routes constants file (e.g., src/routes.ts)")
.action((path, options) => __awaiter(this, void 0, void 0, function* () {
console.log(`\n๐ Next.js Route HTML Report Generator v1.0.6`);
let routesFile = undefined;
// ๋ช
๋ นํ ์ต์
์ด ์์ผ๋ฉด ๋ฐฐ์ด๋ก ๋ณํ
if (options.routesFile) {
// ์ผํ๋ก ๊ตฌ๋ถ๋ ํ์ผ๋ค์ ๋ฐฐ์ด๋ก ๋ณํ
const files = options.routesFile
.split(",")
.map((file) => file.trim())
.filter((file) => file.length > 0);
routesFile = files;
console.log(`๐บ๏ธ Using routes file from command line: ${files.join(", ")}`);
}
else {
// ๋ช
๋ นํ ์ต์
์ด ์์ผ๋ฉด ๋ํํ์ผ๋ก ์
๋ ฅ๋ฐ๊ธฐ
routesFile = yield askForRoutesFile();
}
if (routesFile && routesFile.length > 0) {
console.log(`๐บ๏ธ Using routes file: ${routesFile.join(", ")}`);
}
else {
console.log("๐ ์๋์ผ๋ก routes ํ์ผ์ ๊ฒ์ํฉ๋๋ค...");
}
// generateHTMLReport์๋ ์ฒซ ๋ฒ์งธ ํ์ผ๋ง ์ ๋ฌ (๊ธฐ์กด ํธํ์ฑ ์ ์ง)
const firstRoutesFile = routesFile && routesFile.length > 0 ? routesFile[0] : undefined;
(0, htmlReport_js_1.generateHTMLReport)(path, options.output, firstRoutesFile);
}));
return program;
}
if (require.main === module) {
createCli().parse(process.argv);
}