next build Route Summary
Hard · Build
After next build, Next.js prints a table of routes with a symbol that shows how each route is served: ○ Static (prerendered at build time), ● SSG (prerendered HTML from generateStaticParams), ƒ Dynamic (server-rendered on demand). Write formatBuildSummary(routes) that prints a simplified version of that table. The exact format below is defined by this exercise.
Each route is { path, kind, paths?, revalidate? } where kind is "static", "ssg" or "dynamic", paths are the prerendered URLs of an SSG route, and revalidate is in seconds. Return an array of lines:
- Sort routes by path (plain string comparison with <).
- First line: "Route (app)".
- One line per route: <branch> <symbol> <path>. The branch is ─ when there is only one route, otherwise ┌ for the first, └ for the last and ├ for the others.
- An SSG route with paths gets child lines under it: <cont> <inner> <text>, where <cont> is │ (or a space when the route is the last one) followed by three spaces. Show the first 3 paths in the given order. If there are more than 3, add a last child [+N more paths] with N = remaining count. The last child uses └, the others ├.
- Revalidate column: if at least one route has revalidate, let W = (length of the longest line among the header and the route lines) + 2. The header becomes "Route (app)".padEnd(W) + "Revalidate", and each route line with a revalidate becomes line.padEnd(W) + <time>. Lines without revalidate (and child lines) are not padded. <time> is Nd if the seconds divide by 86400, else Nh if they divide by 3600, else Nm if they divide by 60, else Ns.
- If there is at least one route: an empty line, then one legend line per symbol that appears, in the order ○ ● ƒ:
- "○ (Static) prerendered as static content"
- "● (SSG) prerendered as static HTML (uses generateStaticParams)"
- "ƒ (Dynamic) server-rendered on demand"