@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
213 lines (156 loc) β’ 6.02 kB
Markdown
# πΊοΈ Next.js Route Visualizer
**Next.js νλ‘μ νΈμ λΌμ°νΈ ꡬ쑰μ λ€λΉκ²μ΄μ
μ ν λμ μκ°νν΄λ³΄μΈμ!**
ν λ²μ λͺ
λ Ήμ΄λ‘ λΌμ°νΈ κ·Έλν JSONκ³Ό μΈν°λν°λΈ HTML 리ν¬νΈλ₯Ό μμ±ν©λλ€.
## β¨ νΉμ§
- π **μν΄λ¦ μ€ν**: `npx` λͺ
λ Ήμ΄ νλλ‘ μ¦μ μκ°ν
- π **λΌμ°νΈ λΆμ**: νμ΄μ§μ λ€μ΄λ΄λ―Ή λΌμ°νΈ κ΄κ³ μΆμ
- π― **λμ ν¨μ λΆμ**: `Router.push(getRoute())`μ κ°μ λμ ν¨μ νΈμΆ λ΄λΆ λΆμ
- π **κ³ κΈ λ€λΉκ²μ΄μ
κ°μ§**: Routes μμ, νμ΄ν ν¨μ, μ‘°κ±΄λΆ λ€λΉκ²μ΄μ
μ§μ
- π¨ **λ κ°μ§ μκ°ν λͺ¨λ**:
- π **κ·Έλν λ€μ΄μ΄κ·Έλ¨**: λλκ·Έ, μ€, νν°λ§ κ°λ₯ν λ
Έλ-λ§ν¬ μκ°ν
- π **μΈν°λν°λΈ 리ν¬νΈ**: νμ΄μ§ μ νν μ°κ²° νμ μΈν°νμ΄μ€
- πΎ **JSON μΆλ ₯**: λ€λ₯Έ λꡬμμλ νμ© κ°λ₯ν λ°μ΄ν°
- π **μλ λΈλΌμ°μ **: μμ± μ¦μ λΈλΌμ°μ μμ μ΄λ¦Ό
## π λΉ λ₯Έ μμ
### Next.js νλ‘μ νΈμμ λ°λ‘ μ€ν
```bash
# νμ¬ λλ ν°λ¦¬ λΆμ (κΈ°λ³Έ: κ·Έλν λ€μ΄μ΄κ·Έλ¨)
npx @choi2021/next-route-visualizer
# μΈν°λν°λΈ HTML 리ν¬νΈ μμ±
npx @choi2021/next-route-visualizer report
# νΉμ νλ‘μ νΈ λΆμ
npx @choi2021/next-route-visualizer ./my-next-app
npx @choi2021/next-route-visualizer report ./my-next-app
```
### λͺ
λ Ήμ΄ μ΅μ
```bash
# κΈ°λ³Έ κ·Έλν μκ°ν
npx @choi2021/next-route-visualizer map [project-path]
# μΈν°λν°λΈ HTML 리ν¬νΈ
npx @choi2021/next-route-visualizer report [project-path] [-o output.html]
```
### κ²°κ³Ό
**κ·Έλν μκ°ν (`map` λͺ
λ Ήμ΄):**
- `route-graph.json` - λΌμ°νΈ λ°μ΄ν°
- `route-visualizer.html` - λ
Έλ-λ§ν¬ κ·Έλν μκ°ν
**HTML 리ν¬νΈ (`report` λͺ
λ Ήμ΄):**
- `route-graph.json` - λΌμ°νΈ λ°μ΄ν°
- `route-report.html` - νμ΄μ§ μ νν μΈν°λν°λΈ 리ν¬νΈ
## π μμ€ν
μꡬμ¬ν
- Node.js 14.0.0 μ΄μ
- Next.js νλ‘μ νΈ (pages/ λλ src/pages/ ꡬ쑰)
## π‘ μ¬μ© μμ
```bash
$ npx @choi2021/next-route-visualizer report
π Next.js Route HTML Report Generator v1.0.0
π λΌμ°νΈ λΆμ μ€...
π HTML 리ν¬νΈ μμ± μ€...
β
HTML 리ν¬νΈκ° μμ±λμμ΅λλ€: route-report.html
π μ΄ 9κ° νμ΄μ§, 139κ° μ°κ²° λΆμ μλ£
π λΈλΌμ°μ μμ 리ν¬νΈλ₯Ό μ΄μμ΅λλ€!
```
## π¨ μκ°ν λͺ¨λ
### 1. π κ·Έλν λ€μ΄μ΄κ·Έλ¨ (`map`)
- **μ»¬λ¬ μ½λ©**: νμ΄μ§(νλμ), λ€μ΄λ΄λ―Ή λΌμ°νΈ(μ£Όν©μ)
- **μΈν°λν°λΈ κ·Έλν**: λ
Έλ λλκ·Έ, μ€ μΈ/μμ, ν¬
- **μΈλΆ μ 보**: νΈλ²μ νμΌ κ²½λ‘, μ½λ μ€λν«, λΌμΈ λ²νΈ νμ
- **μ°κ²° μΆμ **: νμ΄μ§κ° λ€λΉκ²μ΄μ
κ΄κ³ μκ°ν
### 2. π μΈν°λν°λΈ 리ν¬νΈ (`report`)
- **μ¬μ΄λλ°**: μ°κ²° μ κΈ°μ€ μ λ ¬λ νμ΄μ§ λͺ©λ‘
- **νμ΄μ§ μμΈ**: μ νλ νμ΄μ§μ incoming/outgoing μ°κ²° νμ
- **νλ‘μ νΈ ν΅κ³**: μ 체 νμ΄μ§, μ°κ²° μ, νκ· μ°κ²° μ
- **κ²μ κΈ°λ₯**: νμ΄μ§ κ²½λ‘ μ€μκ° κ²μ
- **ν΄λ¦ λ€λΉκ²μ΄μ
**: μ°κ²°λ νμ΄μ§ κ° μ¬μ΄ μ΄λ
## π μΆλ ₯ λ°μ΄ν° ꡬ쑰
`route-graph.json`μ ꡬ쑰:
```json
{
"nodes": [
{
"id": "/",
"path": "/",
"type": "page",
"filePath": "pages/index.tsx",
"fileSize": 2203,
"metadata": { "depth": 0, "segments": [""] }
}
],
"edges": [
{
"source": "/",
"target": "/about",
"method": "link",
"lineNumber": 25,
"codeSnippet": "<Link href='/about'>",
"fileName": "pages/index.tsx"
}
],
"summary": {
"totalPages": 9,
"totalConnections": 139,
"avgConnections": 15.4
}
}
```
## π μ°κ²° λΆμ νμ
- **link**: Next.js Link μ»΄ν¬λνΈ
- **router**: router.push(), router.replace() λ±
- **component**: μ»΄ν¬λνΈλ₯Ό ν΅ν κ°μ λ€λΉκ²μ΄μ
## π οΈ κ°λ° λ° λλ²κΉ
### λ‘컬 κ°λ°
```bash
git clone https://github.com/your-username/next-route-map.git
cd next-route-map
npm install
npm run build
# μμ νλ‘μ νΈ ν
μ€νΈ
npm run test:example
# HTML 리ν¬νΈ ν
μ€νΈ
npm run test:report
```
## π€ κΈ°μ¬νκΈ°
λ²κ·Έ 리ν¬νΈμ κΈ°λ₯ μ μμ [GitHub Issues](https://github.com/your-username/next-route-map/issues)μμ νμν©λλ€.
## π λΌμ΄μ μ€
MIT License
---
**β νλ‘μ νΈκ° μ μ©νλ€λ©΄ GitHubμμ λ³νλ₯Ό λλ¬μ£ΌμΈμ!**
## π― κ³ κΈ λΆμ κΈ°λ₯ (v1.1.0)
### λμ ν¨μ λΆμ
μ΄μ λ€μκ³Ό κ°μ 볡μ‘ν λ€λΉκ²μ΄μ
ν¨ν΄λ μ νν λΆμν©λλ€:
```typescript
// 1. μ‘°κ±΄λΆ λμ ν¨μ (β
λͺ¨λ κ°λ₯ν κ²½λ‘ κ°μ§)
const getRoute = () => {
if (condition) {
return V2_Routes.ADMIN_PANEL(); // β /v2/admin/panel
} else {
return Routes.PROFILE(); // β /profile
}
};
const handleClick = () => {
Router.push(getRoute()); // λ κ²½λ‘ λͺ¨λ μκ°νλ¨!
};
// 2. νμ΄ν ν¨μ Routes μμ (β
μ§μ)
export const V2_Routes = {
ADMIN_PANEL: () => "/v2/admin/panel",
USER_PROFILE: (id) => `/v2/user/${id}`,
};
// 3. getServerSideProps 리λλ μ
(β
μ§μ)
export async function getServerSideProps() {
if (!authenticated) {
return { redirect: { destination: "/login" } };
}
}
// 4. λμλ¬Έμ κ΅¬λΆ (β
λͺ¨λ κ°μ§)
Router.push(Routes.HOME()); // λλ¬Έμ Router
router.push(Routes.PROFILE()); // μλ¬Έμ router
```
### μ§μνλ λ€λΉκ²μ΄μ
ν¨ν΄
- β
**μ μ κ²½λ‘**: `"/dashboard"`, `'/profile'`
- β
**Routes μμ**: `Routes.HOME`, `ROUTES.DASHBOARD`
- β
**ν¨μν Routes**: `Routes.PROFILE()`, `V2_Routes.ADMIN()`
- β
**λμ ν¨μ νΈμΆ**: `Router.push(getRoute())`
- β
**μ‘°κ±΄λΆ λ¦¬ν΄**: `if/else` λΈλ‘ λ΄ λ€λΉκ²μ΄μ
- β
**ν
νλ¦Ώ 리ν°λ΄**: `` `/dashboard?tab=${tab}` ``
- β
**getServerSideProps 리λλ μ
**
- β
**useEffect λ΄ λ€λΉκ²μ΄μ
**
- β
**ν
κΈ°λ° λ€λΉκ²μ΄μ
**