Orchestrator Entry (generate-static.js)
Examine the main orchestrator script that cleans the build cache, crawls static paths, and triggers the RSC and HTML rendering pipelines.
Key File Location: ./dinou/core/generate-static.js💡 Overview
When building a website, there must be a single entry point that manages the lifecycle of the static compilation phase. In Dinou, generate-static.js handles this role. It clears previous builds, runs the route crawler, and triggers the RSC and HTML rendering streams.
📊 Build Cycle Sequence
The flowchart below traces the steps executed when running the compiler:
🏗️ Pipeline Orchestration
The compilation pipeline follows a strict dependency order:
- Clean (Pruning): Deletes the cache folder (
dist2/) usingrmSync()to ensure deleted source pages are pruned from output builds. - Crawl & Map: Runs
buildStaticPages()to find routes and evaluate parameters. - RSC Phase: Executes
generateStaticRSCs()to serialize react elements. This must run first, as the subsequent HTML compilation relies on loading these output payloads. - HTML Phase: Executes
generateStaticPages()to parse RSC outputs and output static HTML files.
⚙️ Complete Code Walkthrough
Below is the full, complete code of generate-static.js:
const path = require("path");
const { existsSync, rmSync } = require("fs");
const generateStaticRSCs = require("./generate-static-rscs");
const generateStaticPages = require("./generate-static-pages");
const { buildStaticPages, getStaticPaths } = require("./build-static-pages");
async function generateStatic() {
const distFolder2 = path.resolve(process.cwd(), "dist2");
// 1. Clean build directory to prune outdated/deleted routes
if (existsSync(distFolder2)) {
rmSync(distFolder2, { recursive: true, force: true });
console.log("Deleted existing dist2 folder");
}
// 2. Crawl filesystem and resolve static configurations
await buildStaticPages();
const routes = getStaticPaths();
console.log("Static paths:", routes);
// 3. Serialize RSC flight stream files in parallel
await generateStaticRSCs(routes);
// 4. Render HTML static pages
await generateStaticPages(routes);
}
module.exports = generateStatic;