|
| 1 | +import fs from "fs"; |
| 2 | +import path from "path"; |
| 3 | + |
| 4 | +const DIST_DIR = path.join(__dirname, "..", "dist"); |
| 5 | + |
| 6 | +// Clean and recreate dist |
| 7 | +if (fs.existsSync(DIST_DIR)) { |
| 8 | + fs.rmSync(DIST_DIR, { recursive: true, force: true }); |
| 9 | +} |
| 10 | +fs.mkdirSync(DIST_DIR, { recursive: true }); |
| 11 | + |
| 12 | +const GETTING_STARTED = ["introduction", "installation", "rosetta-stone", "common-ai-hallucinations", "directives-guide"]; |
| 13 | +const COMPONENTS = [ |
| 14 | + "accordion","alert","alert-dialog","aspect-ratio","avatar","avatar-group","badge","banner", |
| 15 | + "breadcrumb","button","button-group","calendar","card","carousel","checkbox","checkbox-group", |
| 16 | + "chip","collapsible","color-picker","combobox","command","container","context-menu","data-table", |
| 17 | + "date-picker","dialog","divider","drawer","dropdown-menu","empty-state","error-message", |
| 18 | + "file-upload","flash-search","form","hover-card","icon","image","indicator","input","input-otp","kbd","label", |
| 19 | + "layout-block","layout-canvas","layout-grid","layout-page","layout-print","layout-scaffold","layout-web","layout-mweb","layout-mapp", |
| 20 | + "link","list","list-item","loading-spinner","masonry-grid","menubar","message-bubble", |
| 21 | + "navigation-menu","notification","number-input","page-header","pagination","panel", |
| 22 | + "password-input","pin-input","popover","profile-badge","progress","progress-bar","pulse", |
| 23 | + "radio-button","radio-group","rating","resizable","ribbon","scroll-area","search-input", |
| 24 | + "select","separator","sheet","sidebar","skeleton","slider","slider-range","snackbar","splitter", |
| 25 | + "stat-card","stepper","submenu","switch","table","tabs","tag","text","textarea","timeline", |
| 26 | + "time-picker","toast","toggle","toggle-group","toggle-switch","toolbar","tooltip","tree-view","user-card", |
| 27 | + "video-player","watermark","wizard","hx-wizard","date-range-picker","hx-grid","hx-virtual","hx-offline","hollywood-webfx" |
| 28 | +]; |
| 29 | + |
| 30 | +function formatName(slug: string): string { |
| 31 | + return slug.split("-").map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(" "); |
| 32 | +} |
| 33 | + |
| 34 | +function buildSidebar(active: string): string { |
| 35 | + let html = `<div class="mb-6"><h4 class="mb-2 px-3 text-sm font-semibold tracking-tight">Getting Started</h4><div class="space-y-1">`; |
| 36 | + html += GETTING_STARTED.map(c => { |
| 37 | + const isActive = c === active; |
| 38 | + return `<a href="/docs/components/${c}/" class="block rounded-md px-3 py-1.5 text-sm ${isActive ? 'bg-accent font-medium text-accent-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-accent/50'} transition-colors">${formatName(c)}</a>`; |
| 39 | + }).join("\n"); |
| 40 | + html += `</div></div><div><h4 class="mb-2 px-3 text-sm font-semibold tracking-tight">Components</h4><div class="space-y-1">`; |
| 41 | + html += COMPONENTS.map(c => { |
| 42 | + const isActive = c === active; |
| 43 | + return `<a href="/docs/components/${c}/" class="block rounded-md px-3 py-1.5 text-sm ${isActive ? 'bg-accent font-medium text-accent-foreground' : 'text-muted-foreground hover:text-foreground hover:bg-accent/50'} transition-colors">${formatName(c)}</a>`; |
| 44 | + }).join("\n"); |
| 45 | + html += `</div></div>`; |
| 46 | + return html; |
| 47 | +} |
| 48 | + |
| 49 | +function escapeHtml(str: string): string { |
| 50 | + return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """); |
| 51 | +} |
| 52 | + |
| 53 | +function buildComponentPage(slug: string): string { |
| 54 | + const name = formatName(slug); |
| 55 | + const sidebar = buildSidebar(slug); |
| 56 | + const filePath = path.join(__dirname, "..", "views", "components", `${slug}.html`); |
| 57 | + const sourceHtml = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "<!-- Component source not found -->"; |
| 58 | + |
| 59 | + return `<!DOCTYPE html> |
| 60 | +<html lang="en"> |
| 61 | +<head> |
| 62 | + <meta charset="UTF-8"> |
| 63 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 64 | + <title>${name} — HTMXUI</title> |
| 65 | + <script src="https://unpkg.com/htmx.org@2.0.4" crossorigin="anonymous"></script> |
| 66 | + <script src="/htmx-bolt.js"></script> |
| 67 | + <script src="/htmx-flash.js"></script> |
| 68 | + <script src="/htmx-form.js"></script> |
| 69 | + <script src="/htmx-vibe.js"></script> |
| 70 | + <script src="/htmx-a11y.js"></script> |
| 71 | + <script src="/htmx-virtual.js"></script> |
| 72 | + <script src="/htmx-grid.js"></script> |
| 73 | + <script src="/htmx-offline.js"></script> |
| 74 | + <script src="/htmx-devtools.js"></script> |
| 75 | + <script src="/htmx-canvas.js"></script> |
| 76 | + <link rel="stylesheet" href="/styles.css"> |
| 77 | + <style> |
| 78 | + .code-block { background: #1e293b; color: #e2e8f0; border-radius: 0.5rem; padding: 1rem; overflow-x: auto; font-size: 0.8rem; line-height: 1.6; } |
| 79 | + .code-block code { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace; } |
| 80 | + </style> |
| 81 | +</head> |
| 82 | +<body class="bg-background text-foreground antialiased min-h-screen"> |
| 83 | + <div class="flex min-h-screen"> |
| 84 | + <aside id="doc-sidebar" class="hidden lg:flex w-60 flex-col border-r border-border bg-card overflow-y-auto sticky top-0 h-screen"> |
| 85 | + <div class="flex h-14 items-center border-b border-border px-4"> |
| 86 | + <a href="/" class="flex items-center gap-2"> |
| 87 | + <svg class="h-5 w-5 text-primary" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="10"/></svg> |
| 88 | + <span class="font-bold text-lg tracking-tight">HTMXUI</span> |
| 89 | + </a> |
| 90 | + </div> |
| 91 | + <div class="flex-1 p-3 overflow-y-auto">${sidebar}</div> |
| 92 | + </aside> |
| 93 | + <main class="flex-1 flex flex-col min-w-0"> |
| 94 | + <header class="h-14 border-b border-border flex items-center justify-between px-6 bg-card sticky top-0 z-30"> |
| 95 | + <div class="flex items-center gap-4"> |
| 96 | + <h1 class="font-semibold text-base">${name}</h1> |
| 97 | + <a href="/demo/" class="text-xs bg-primary/10 text-primary font-medium px-2.5 py-1 rounded-full hover:bg-primary/20 transition-colors">Live Demos Hub</a> |
| 98 | + </div> |
| 99 | + <a href="https://github.com/hyperlibs/htmxUI" target="_blank" class="text-xs text-muted-foreground hover:text-foreground">GitHub ↗</a> |
| 100 | + </header> |
| 101 | + <div class="flex-1 p-8 max-w-5xl mx-auto w-full space-y-8"> |
| 102 | + <div class="space-y-2"> |
| 103 | + <h1 class="text-3xl font-extrabold tracking-tight">${name}</h1> |
| 104 | + <p class="text-muted-foreground text-sm">Interactive Shadcn-quality hypermedia component for HTMXUI.</p> |
| 105 | + </div> |
| 106 | + <div class="space-y-4"> |
| 107 | + <h2 class="text-xl font-bold tracking-tight">Interactive Preview</h2> |
| 108 | + <div class="rounded-xl border border-border p-8 bg-card shadow-sm flex items-center justify-center min-h-[160px]"> |
| 109 | + <div class="w-full max-w-xl flex flex-col items-center gap-4">${sourceHtml}</div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + <div class="space-y-4"> |
| 113 | + <h2 class="text-xl font-bold tracking-tight">HTML Source</h2> |
| 114 | + <div class="code-block"><pre><code>${escapeHtml(sourceHtml)}</code></pre></div> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + </main> |
| 118 | + </div> |
| 119 | +</body> |
| 120 | +</html>`; |
| 121 | +} |
| 122 | + |
| 123 | +function writePage(relPath: string, content: string) { |
| 124 | + const fullPath = path.join(DIST_DIR, relPath); |
| 125 | + fs.mkdirSync(path.dirname(fullPath), { recursive: true }); |
| 126 | + fs.writeFileSync(fullPath, content, "utf8"); |
| 127 | +} |
| 128 | + |
| 129 | +console.log("Building static HTMXUI site for Cloudflare Pages..."); |
| 130 | + |
| 131 | +// 1. Root redirect / landing |
| 132 | +writePage("index.html", `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/demo/"></head><body><script>location.href='/demo/';</script></body></html>`); |
| 133 | + |
| 134 | +// 2. Demos Hub |
| 135 | +const demoHubHtml = fs.readFileSync(path.join(__dirname, "..", "views", "demos-hub.html"), "utf8"); |
| 136 | +writePage("demo/index.html", demoHubHtml); |
| 137 | +writePage("demos/index.html", demoHubHtml); |
| 138 | + |
| 139 | +// 3. Flagship Demos |
| 140 | +const tailadminHtml = fs.readFileSync(path.join(__dirname, "..", "views", "app-tailadmin.html"), "utf8"); |
| 141 | +writePage("demo/tailadmin/index.html", tailadminHtml); |
| 142 | +writePage("app/tailadmin/index.html", tailadminHtml); |
| 143 | + |
| 144 | +const erpHtml = fs.readFileSync(path.join(__dirname, "..", "views", "app-erp.html"), "utf8"); |
| 145 | +writePage("demo/erp/index.html", erpHtml); |
| 146 | +writePage("app/erp/index.html", erpHtml); |
| 147 | + |
| 148 | +const hypersheetHtml = fs.readFileSync(path.join(__dirname, "..", "views", "app-hypersheet.html"), "utf8"); |
| 149 | +writePage("demo/hypersheet/index.html", hypersheetHtml); |
| 150 | +writePage("app/hypersheet/index.html", hypersheetHtml); |
| 151 | + |
| 152 | +const universeHtml = fs.readFileSync(path.join(__dirname, "..", "views", "app-universe.html"), "utf8"); |
| 153 | +writePage("demo/universe/index.html", universeHtml); |
| 154 | +writePage("app/universe/index.html", universeHtml); |
| 155 | +writePage("cosmos/index.html", universeHtml); |
| 156 | + |
| 157 | +// 4. Docs Component Pages |
| 158 | +[...GETTING_STARTED, ...COMPONENTS].forEach(slug => { |
| 159 | + const pageHtml = buildComponentPage(slug); |
| 160 | + writePage(`docs/components/${slug}/index.html`, pageHtml); |
| 161 | +}); |
| 162 | +writePage("docs/index.html", `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/docs/components/introduction/"></head><body><script>location.href='/docs/components/introduction/';</script></body></html>`); |
| 163 | + |
| 164 | +// 5. Mock Invoices API for ERP |
| 165 | +const invoices = Array.from({ length: 500 }, (_, i) => ({ |
| 166 | + id: `INV-${100000 + i}`, |
| 167 | + customer: ["Acme Corp", "Globex LLC", "Initech", "Umbrella Co", "Stark Industries", "Wayne Enterprises", "Cyberdyne", "Soylent Corp"][i % 8], |
| 168 | + amount: (Math.random() * 5000 + 100).toFixed(2), |
| 169 | + status: ["Paid", "Pending", "Overdue", "Draft", "Processing"][i % 5], |
| 170 | + date: new Date(Date.now() - (i * 86400000)).toISOString().split("T")[0] |
| 171 | +})); |
| 172 | +writePage("api/erp-invoices.json", JSON.stringify(invoices)); |
| 173 | + |
| 174 | +// 6. Copy Public Assets |
| 175 | +function copyDir(src: string, dest: string) { |
| 176 | + if (!fs.existsSync(src)) return; |
| 177 | + fs.mkdirSync(dest, { recursive: true }); |
| 178 | + const entries = fs.readdirSync(src, { withFileTypes: true }); |
| 179 | + for (const entry of entries) { |
| 180 | + const srcPath = path.join(src, entry.name); |
| 181 | + const destPath = path.join(dest, entry.name); |
| 182 | + if (entry.isDirectory()) { |
| 183 | + copyDir(srcPath, destPath); |
| 184 | + } else { |
| 185 | + fs.copyFileSync(srcPath, destPath); |
| 186 | + } |
| 187 | + } |
| 188 | +} |
| 189 | + |
| 190 | +copyDir(path.join(__dirname, "..", "public"), DIST_DIR); |
| 191 | + |
| 192 | +// Copy styles.css to root of dist |
| 193 | +if (fs.existsSync(path.join(__dirname, "..", "public", "styles", "output.css"))) { |
| 194 | + fs.copyFileSync(path.join(__dirname, "..", "public", "styles", "output.css"), path.join(DIST_DIR, "styles.css")); |
| 195 | +} |
| 196 | + |
| 197 | +// 7. Schema files |
| 198 | +if (fs.existsSync(path.join(__dirname, "..", "schema", "htmxui.json"))) { |
| 199 | + writePage("schema/htmxui.json", fs.readFileSync(path.join(__dirname, "..", "schema", "htmxui.json"), "utf8")); |
| 200 | +} |
| 201 | + |
| 202 | +console.log("✅ Static build complete! Output generated in dist/"); |
0 commit comments