@punkestu/react-html 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +215 -2
  2. package/bin/react-html.js +8 -0
  3. package/dist/cli/docs-content.d.ts +8 -0
  4. package/dist/cli/docs-content.d.ts.map +1 -0
  5. package/dist/cli/docs-content.js +261 -0
  6. package/dist/cli/docs-content.js.map +1 -0
  7. package/dist/cli/index.d.ts +2 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +113 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/tui-docs.d.ts +5 -0
  12. package/dist/cli/tui-docs.d.ts.map +1 -0
  13. package/dist/cli/tui-docs.js +191 -0
  14. package/dist/cli/tui-docs.js.map +1 -0
  15. package/dist/client/hydrate.d.ts +4 -0
  16. package/dist/client/hydrate.d.ts.map +1 -0
  17. package/dist/client/hydrate.js +80 -0
  18. package/dist/client/hydrate.js.map +1 -0
  19. package/dist/core/bundler.d.ts +7 -0
  20. package/dist/core/bundler.d.ts.map +1 -0
  21. package/dist/core/bundler.js +103 -0
  22. package/dist/core/bundler.js.map +1 -0
  23. package/dist/core/formatter.d.ts +6 -0
  24. package/dist/core/formatter.d.ts.map +1 -0
  25. package/dist/core/formatter.js +74 -0
  26. package/dist/core/formatter.js.map +1 -0
  27. package/dist/core/island-client.d.ts +9 -0
  28. package/dist/core/island-client.d.ts.map +1 -0
  29. package/dist/core/island-client.js +8 -0
  30. package/dist/core/island-client.js.map +1 -0
  31. package/dist/core/island-registry.d.ts +15 -0
  32. package/dist/core/island-registry.d.ts.map +1 -0
  33. package/dist/core/island-registry.js +17 -0
  34. package/dist/core/island-registry.js.map +1 -0
  35. package/dist/core/island.d.ts +32 -0
  36. package/dist/core/island.d.ts.map +1 -0
  37. package/dist/core/island.js +47 -0
  38. package/dist/core/island.js.map +1 -0
  39. package/dist/core/loader.d.ts +11 -0
  40. package/dist/core/loader.d.ts.map +1 -0
  41. package/dist/core/loader.js +73 -0
  42. package/dist/core/loader.js.map +1 -0
  43. package/dist/core/renderer.d.ts +20 -0
  44. package/dist/core/renderer.d.ts.map +1 -0
  45. package/dist/core/renderer.js +53 -0
  46. package/dist/core/renderer.js.map +1 -0
  47. package/dist/index.d.ts +23 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +104 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/server/dev-server.d.ts +8 -0
  52. package/dist/server/dev-server.d.ts.map +1 -0
  53. package/dist/server/dev-server.js +112 -0
  54. package/dist/server/dev-server.js.map +1 -0
  55. package/dist/server/engine.d.ts +46 -0
  56. package/dist/server/engine.d.ts.map +1 -0
  57. package/dist/server/engine.js +222 -0
  58. package/dist/server/engine.js.map +1 -0
  59. package/dist/server/index.d.ts +5 -0
  60. package/dist/server/index.d.ts.map +1 -0
  61. package/dist/server/index.js +3 -0
  62. package/dist/server/index.js.map +1 -0
  63. package/package.json +47 -3
package/README.md CHANGED
@@ -1,3 +1,216 @@
1
- # Temporary Holding Version
1
+ # react-html ⚛️ ➡️ 📄
2
+
3
+ A blazing-fast engine to convert React/JSX components into **pure, semantic HTML** with selective compilation of interactive components into **micro JavaScript islands**.
4
+
5
+ Write DRY, modular HTML using React components without shipping any React runtime or JavaScript to the client by default.
6
+
7
+ ---
8
+
9
+ ## 🌟 Why react-html?
10
+
11
+ - **Zero-JS by Default**: Static pages are rendered to 100% pure HTML. No client-side React runtime, no `<script>` tags, and 0 KB JavaScript overhead.
12
+ - **Modular & DRY**: Stop duplicating headers, footers, meta tags, and layouts. Build reusable components (`<Layout>`, `<Header>`, `<Card>`, `<Footer>`) using familiar React JSX syntax.
13
+ - **Selective Reactivity (Islands Architecture)**: When a component needs client-side interactivity (counters, modals, tabs, forms), the engine bundles only that component into a standalone, micro ESM script using `esbuild`.
14
+ - **Fast Build Pipeline**: Powered by `esbuild` for instantaneous static site generation and sub-100ms builds.
15
+ - **Node.js Native**: Runs strictly on standard Node.js (v20+) with npm.
16
+
17
+ ---
18
+
19
+ ## 🚀 Quick Start
20
+
21
+ ### Installation
22
+
23
+ ```bash
24
+ npm install react-html
25
+ ```
26
+
27
+ Or install globally / link locally:
28
+
29
+ ```bash
30
+ npm link
31
+ ```
32
+
33
+ ### CLI Usage
34
+
35
+ ```bash
36
+ # Build static site to dist/
37
+ react-html build
38
+
39
+ # Build with custom pages or output directory
40
+ react-html build --pages src/pages --out dist
41
+
42
+ # Start dev server with watch & live recompile
43
+ react-html dev --port 3000
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 📖 How It Works
49
+
50
+ ### 1. Pure Modular HTML (Zero JavaScript)
51
+
52
+ Create your reusable layout and page components using standard JSX:
53
+
54
+ ```tsx
55
+ // src/components/Layout.tsx
56
+ import React, { ReactNode } from 'react';
57
+
58
+ export function Layout({ title, children }: { title: string; children: ReactNode }) {
59
+ return (
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>{title}</title>
65
+ <link rel="stylesheet" href="/styles.css" />
66
+ </head>
67
+ <body>
68
+ <header>
69
+ <h1>My Modular Site</h1>
70
+ </header>
71
+ <main>{children}</main>
72
+ </body>
73
+ </html>
74
+ );
75
+ }
76
+ ```
77
+
78
+ ```tsx
79
+ // src/pages/about.tsx
80
+ import React from 'react';
81
+ import { Layout } from '../components/Layout.js';
82
+
83
+ export default function AboutPage() {
84
+ return (
85
+ <Layout title="About Us">
86
+ <h2>About Our Project</h2>
87
+ <p>This entire page compiles into pure static HTML with 0 KB JavaScript!</p>
88
+ </Layout>
89
+ );
90
+ }
91
+ ```
92
+
93
+ **Output in `dist/about.html`:**
94
+ ```html
95
+ <!DOCTYPE html>
96
+ <html lang="en">
97
+ <head>
98
+ <meta charSet="UTF-8"/>
99
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
100
+ <title>About Us</title>
101
+ <link rel="stylesheet" href="/styles.css"/>
102
+ </head>
103
+ <body>
104
+ <header>
105
+ <h1>My Modular Site</h1>
106
+ </header>
107
+ <main>
108
+ <h2>About Our Project</h2>
109
+ <p>This entire page compiles into pure static HTML with 0 KB JavaScript!</p>
110
+ </main>
111
+ </body>
112
+ </html>
113
+ ```
114
+
115
+ ---
116
+
117
+ ### 2. Reactive Components (Islands Architecture)
118
+
119
+ When a component needs client-side state and interactivity, wrap it with `island()`:
120
+
121
+ ```tsx
122
+ // src/components/Counter.island.tsx
123
+ import React, { useState } from 'react';
124
+ import { island } from 'react-html';
125
+
126
+ export interface CounterProps {
127
+ initial?: number;
128
+ }
129
+
130
+ function CounterComponent({ initial = 0 }: CounterProps) {
131
+ const [count, setCount] = useState(initial);
132
+
133
+ return (
134
+ <div className="counter">
135
+ <button onClick={() => setCount(c => c - 1)}>-</button>
136
+ <span>Count: {count}</span>
137
+ <button onClick={() => setCount(c => c + 1)}>+</button>
138
+ </div>
139
+ );
140
+ }
141
+
142
+ // Export the island with its unique name and source path
143
+ export const Counter = island(CounterComponent, import.meta.url, 'Counter');
144
+ export default Counter;
145
+ ```
146
+
147
+ Now import and use it in any page just like a normal React component:
148
+
149
+ ```tsx
150
+ // src/pages/index.tsx
151
+ import React from 'react';
152
+ import { Layout } from '../components/Layout.js';
153
+ import { Counter } from '../components/Counter.island.js';
154
+
155
+ export default function HomePage() {
156
+ return (
157
+ <Layout title="Home">
158
+ <h2>Welcome!</h2>
159
+ {/* Pre-rendered to HTML for instant paint, then hydrated with tiny JS */}
160
+ <Counter initial={10} />
161
+ </Layout>
162
+ );
163
+ }
164
+ ```
165
+
166
+ **What the engine does:**
167
+ 1. Renders the initial static markup during SSR for instant paint.
168
+ 2. Compiles a dedicated micro-bundle `dist/assets/islands/Counter.js`.
169
+ 3. Injects `<script type="module" src="/assets/islands/Counter.js"></script>` into `index.html`.
170
+ 4. Hydrates only the island element in-place using React 19's `hydrateRoot`.
171
+
172
+ ---
173
+
174
+ ## 🛠️ Hydration Directives
175
+
176
+ `react-html` supports client loading directives to maximize performance:
177
+
178
+ | Directive | Syntax | Behavior |
179
+ | :--- | :--- | :--- |
180
+ | `load` (default) | `<Counter client="load" />` | Hydrates immediately on DOM ready |
181
+ | `idle` | `<Counter client="idle" />` | Hydrates during browser idle time (`requestIdleCallback`) |
182
+ | `visible` | `<Counter client="visible" />` | Hydrates when scrolled into view (`IntersectionObserver`) |
183
+
184
+ ---
185
+
186
+ ## 💻 Programmatic API
187
+
188
+ You can also run `react-html` programmatically from your Node.js scripts:
189
+
190
+ ```ts
191
+ import { build } from 'react-html';
192
+
193
+ const result = await build({
194
+ root: process.cwd(),
195
+ pagesDir: 'src/pages',
196
+ outDir: 'dist',
197
+ minify: true
198
+ });
199
+
200
+ console.log(`Compiled ${result.pages.length} pages and ${result.islands.length} reactive islands.`);
201
+ ```
202
+
203
+ ---
204
+
205
+ ## 🧪 Testing
206
+
207
+ Run the automated test suite powered by Node.js test runner:
208
+
209
+ ```bash
210
+ npm test
211
+ ```
212
+
213
+ ## 📄 License
214
+
215
+ MIT
2
216
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from '../dist/cli/index.js';
3
+
4
+ runCli().catch((err) => {
5
+ console.error('[react-html] Fatal error:', err);
6
+ process.exit(1);
7
+ });
8
+
@@ -0,0 +1,8 @@
1
+ export interface DocSection {
2
+ id: string;
3
+ title: string;
4
+ summary: string;
5
+ content: string[];
6
+ }
7
+ export declare const DOC_SECTIONS: DocSection[];
8
+ //# sourceMappingURL=docs-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-content.d.ts","sourceRoot":"","sources":["../../src/cli/docs-content.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,eAAO,MAAM,YAAY,EAAE,UAAU,EAmQpC,CAAC"}
@@ -0,0 +1,261 @@
1
+ export const DOC_SECTIONS = [
2
+ {
3
+ id: 'intro',
4
+ title: '1. Overview & Philosophy',
5
+ summary: 'Core concepts: pure HTML output, zero-JS by default, and modular JSX.',
6
+ content: [
7
+ '# 1. Overview & Philosophy',
8
+ '',
9
+ 'react-html bridges the gap between modern component-based developer experience',
10
+ 'and lightweight, blazing-fast static websites.',
11
+ '',
12
+ '* ZERO JAVASCRIPT BY DEFAULT:',
13
+ ' Standard components (layouts, navigation, typography, cards, footers) render into',
14
+ ' 100% clean, semantic HTML5. No React runtime, no data-reactroot attributes,',
15
+ ' and 0 KB JavaScript sent to the browser.',
16
+ '',
17
+ '* MODULAR & DRY (DON\'T REPEAT YOURSELF):',
18
+ ' Eliminate copy-pasting HTML boilerplate. Compose pages with reusable React',
19
+ ' components (<Layout>, <Header>, <Card>, <Footer>) with typed props.',
20
+ '',
21
+ '* SELECTIVE REACTIVITY (ISLANDS ARCHITECTURE):',
22
+ ' Only components that explicitly require client-side interactivity are bundled',
23
+ ' into isolated, tiny JavaScript files. Everything around them remains pure HTML.'
24
+ ]
25
+ },
26
+ {
27
+ id: 'quickstart',
28
+ title: '2. Getting Started & Setup',
29
+ summary: 'Installation, Node.js environment, and initial directory structure.',
30
+ content: [
31
+ '# 2. Getting Started & Setup',
32
+ '',
33
+ '* PREREQUISITES:',
34
+ ' - Node.js v20.0.0 or higher (runs natively on standard Node.js & npm)',
35
+ '',
36
+ '* INSTALLATION:',
37
+ ' $ npm install react-html',
38
+ '',
39
+ '* RECOMMENDED PROJECT STRUCTURE:',
40
+ ' my-project/',
41
+ ' ├── package.json',
42
+ ' ├── public/ # Static assets (CSS, images, icons)',
43
+ ' │ └── styles.css',
44
+ ' └── src/',
45
+ ' ├── components/ # Reusable UI components',
46
+ ' │ ├── Layout.tsx # Master HTML shell',
47
+ ' │ ├── Header.tsx # Navigation bar',
48
+ ' │ └── Counter.island.tsx # Interactive island component',
49
+ ' └── pages/ # Multi-page entries',
50
+ ' ├── index.tsx # -> dist/index.html',
51
+ ' ├── about.tsx # -> dist/about.html',
52
+ ' └── blog/',
53
+ ' └── first.tsx # -> dist/blog/first.html'
54
+ ]
55
+ },
56
+ {
57
+ id: 'modular-html',
58
+ title: '3. Modular HTML with React',
59
+ summary: 'Creating reusable layouts, header partials, and nested components.',
60
+ content: [
61
+ '# 3. Modular HTML with React',
62
+ '',
63
+ 'Stop repeating HTML boilerplate. Create a single Layout component:',
64
+ '',
65
+ '// src/components/Layout.tsx',
66
+ 'import React, { ReactNode } from "react";',
67
+ 'import { Header } from "./Header.js";',
68
+ 'import { Footer } from "./Footer.js";',
69
+ '',
70
+ 'export function Layout({ title, children }: { title: string; children: ReactNode }) {',
71
+ ' return (',
72
+ ' <html lang="en">',
73
+ ' <head>',
74
+ ' <meta charSet="UTF-8" />',
75
+ ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />',
76
+ ' <title>{title}</title>',
77
+ ' <link rel="stylesheet" href="/styles.css" />',
78
+ ' </head>',
79
+ ' <body>',
80
+ ' <Header />',
81
+ ' <main>{children}</main>',
82
+ ' <Footer />',
83
+ ' </body>',
84
+ ' </html>',
85
+ ' );',
86
+ '}',
87
+ '',
88
+ 'Every page simply wraps its content in <Layout>: no copy-pasting required!'
89
+ ]
90
+ },
91
+ {
92
+ id: 'islands',
93
+ title: '4. Reactive Islands Architecture',
94
+ summary: 'Compiling interactive React components to tiny client-side JavaScript.',
95
+ content: [
96
+ '# 4. Reactive Islands Architecture',
97
+ '',
98
+ 'When you need client-side state (useState, useEffect, event listeners):',
99
+ '',
100
+ '1. Create the component and wrap it using island():',
101
+ '// src/components/Counter.island.tsx',
102
+ 'import React, { useState } from "react";',
103
+ 'import { island } from "react-html";',
104
+ '',
105
+ 'function CounterComponent({ initial = 0 }) {',
106
+ ' const [count, setCount] = useState(initial);',
107
+ ' return (',
108
+ ' <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>',
109
+ ' );',
110
+ '}',
111
+ '',
112
+ 'export const Counter = island(CounterComponent, import.meta.url, "Counter");',
113
+ 'export default Counter;',
114
+ '',
115
+ '2. Use it in any page just like a normal React component:',
116
+ '// src/pages/index.tsx',
117
+ '<Counter initial={10} />',
118
+ '',
119
+ '* HOW THE ENGINE COMPILES IT:',
120
+ ' - Initial HTML is pre-rendered for instant paint and SEO.',
121
+ ' - esbuild bundles ONLY CounterComponent into dist/assets/islands/Counter.js.',
122
+ ' - Only pages containing <Counter> will have the <script> tag injected.'
123
+ ]
124
+ },
125
+ {
126
+ id: 'directives',
127
+ title: '5. Hydration Directives (Performance)',
128
+ summary: 'Controlling client hydration timing with load, idle, and visible.',
129
+ content: [
130
+ '# 5. Hydration Directives (Performance)',
131
+ '',
132
+ 'Control when JavaScript executes on the user\'s device with the `client` prop:',
133
+ '',
134
+ '* client="load" (Default):',
135
+ ' <Counter client="load" />',
136
+ ' Hydrates as soon as DOMContentLoaded fires. Use for critical UI above the fold.',
137
+ '',
138
+ '* client="idle":',
139
+ ' <Counter client="idle" />',
140
+ ' Hydrates during browser idle time via requestIdleCallback. Perfect for widgets',
141
+ ' or floating elements that do not block immediate interaction.',
142
+ '',
143
+ '* client="visible":',
144
+ ' <Counter client="visible" />',
145
+ ' Hydrates only when scrolled into the viewport using IntersectionObserver.',
146
+ ' Ideal for carousels, comment sections, or widgets further down the page.'
147
+ ]
148
+ },
149
+ {
150
+ id: 'cli',
151
+ title: '6. CLI Commands & Options',
152
+ summary: 'Full guide for build, dev, and docs commands.',
153
+ content: [
154
+ '# 6. CLI Commands & Options',
155
+ '',
156
+ '* BUILD PRODUCTION STATIC SITE:',
157
+ ' $ react-html build [options]',
158
+ ' Flags:',
159
+ ' --pages <dir> Directory containing pages (default: src/pages or pages)',
160
+ ' --out <dir> Output directory (default: dist)',
161
+ ' --root <dir> Root directory of the project (default: cwd)',
162
+ ' --no-minify Disable JS minification for debugging',
163
+ '',
164
+ '* START DEV SERVER (LIVE PREVIEW & WATCH):',
165
+ ' $ react-html dev [options]',
166
+ ' Flags:',
167
+ ' --port <number> Port to listen on (default: 3000)',
168
+ ' --host <string> Host to bind to (default: localhost)',
169
+ '',
170
+ '* TERMINAL UI DOCUMENTATION (TUI):',
171
+ ' $ react-html docs # Interactive TUI navigator',
172
+ ' $ react-html docs --all # Print entire manual to stdout',
173
+ ' $ react-html docs <section-id> # Print specific section'
174
+ ]
175
+ },
176
+ {
177
+ id: 'api',
178
+ title: '7. Programmatic API Reference',
179
+ summary: 'Using build(), renderPageToHtml(), and createDevServer() in Node.js.',
180
+ content: [
181
+ '# 7. Programmatic API Reference',
182
+ '',
183
+ 'import { build, renderPageToHtml, island, Island } from "react-html";',
184
+ '',
185
+ '* build(config):',
186
+ ' const result = await build({',
187
+ ' root: process.cwd(),',
188
+ ' pagesDir: "src/pages",',
189
+ ' outDir: "dist",',
190
+ ' minify: true',
191
+ ' });',
192
+ ' // Returns: { pages: [...], islands: [...], outDir: string }',
193
+ '',
194
+ '* renderPageToHtml({ pagePath, Component, props, metadata }):',
195
+ ' const { html, islands } = renderPageToHtml({',
196
+ ' pagePath: "/path/to/page.tsx",',
197
+ ' Component: MyPage,',
198
+ ' metadata: { title: "Custom Title" }',
199
+ ' });',
200
+ ' // Returns pure HTML string and list of detected islands.'
201
+ ]
202
+ },
203
+ {
204
+ id: 'server',
205
+ title: '8. Server App Integration (Express, Fastify, Node HTTP)',
206
+ summary: 'Using createEngine() for production static hosting and development live rebuilds.',
207
+ content: [
208
+ '# 8. Server App Integration (Express, Fastify, Node HTTP)',
209
+ '',
210
+ 'You can import and use react-html directly inside your backend server application:',
211
+ '',
212
+ 'import express from "express";',
213
+ 'import { createEngine } from "react-html";',
214
+ '// or: import { createEngine } from "react-html/server";',
215
+ '',
216
+ 'const app = express();',
217
+ 'const engine = createEngine({',
218
+ ' pagesDir: "src/pages",',
219
+ ' distDir: "dist",',
220
+ ' // Automatically checks process.env.NODE_ENV === "production"',
221
+ '});',
222
+ '',
223
+ '* 1. CONNECT / EXPRESS MIDDLEWARE:',
224
+ ' app.use(engine.middleware);',
225
+ ' // In production: finds and streams pre-built static HTML from dist/.',
226
+ ' // In development: dynamically rebuilds TSX on the fly and returns fresh HTML.',
227
+ '',
228
+ '* 2. PROGRAMMATIC ROUTE RENDERING:',
229
+ ' app.get("/custom", async (req, res) => {',
230
+ ' const html = await engine.render("index", { user: req.user });',
231
+ ' res.setHeader("Content-Type", "text/html; charset=utf-8");',
232
+ ' res.send(html);',
233
+ ' });',
234
+ '',
235
+ '* 3. NATIVE NODE HTTP SERVER:',
236
+ ' import http from "node:http";',
237
+ ' const server = http.createServer(engine.handle);',
238
+ ' server.listen(3000);'
239
+ ]
240
+ },
241
+ {
242
+ id: 'troubleshooting',
243
+ title: '9. Best Practices & Troubleshooting',
244
+ summary: 'Avoiding hydration mismatch, React error #418, and styling rules.',
245
+ content: [
246
+ '# 8. Best Practices & Troubleshooting',
247
+ '',
248
+ '* PREVENTING HYDRATION MISMATCH (React Error #418):',
249
+ ' - Ensure server and initial client props match.',
250
+ ' - Do not use client-only objects (window.innerWidth, localStorage) in initial render.',
251
+ ' Instead, read them inside useEffect() or an event handler.',
252
+ ' - react-html automatically protects island markup during formatting and uses',
253
+ ' renderToString for interactive inner trees to guarantee matching text nodes.',
254
+ '',
255
+ '* ISOLATE STATEFUL LOGIC:',
256
+ ' Keep non-interactive parts (headers, card shells, footers) pure React components.',
257
+ ' Only place state hooks (useState, useReducer) inside *.island.tsx files.'
258
+ ]
259
+ }
260
+ ];
261
+ //# sourceMappingURL=docs-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-content.js","sourceRoot":"","sources":["../../src/cli/docs-content.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC;QACE,EAAE,EAAE,OAAO;QACX,KAAK,EAAE,0BAA0B;QACjC,OAAO,EAAE,uEA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;QAC/E,OAAO,EAAE;YACP,iCAAiC;YACjC,EAAE;YACF,uEAAuE;YACvE,EAAE;YACF,kBAAkB;YAClB,gCAAgC;YAChC,0BAA0B;YAC1B,4BAA4B;YAC5B,qBAAqB;YACrB,kBAAkB;YAClB,OAAO;YACP,gEAAgE;YAChE,EAAE;YACF,+DAA+D;YAC/D,gDAAgD;YAChD,oCAAoC;YACpC,wBAAwB;YACxB,yCAAyC;YACzC,OAAO;YACP,6DAA6D;SAC9D;KACF;IACD;QACE,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,yDAAyD;QAChE,OAAO,EAAE,mFAAmF;QAC5F,OAAO,EAAE;YACP,2DAA2D;YAC3D,EAAE;YACF,oFAAoF;YACpF,EAAE;YACF,gCAAgC;YAChC,4CAA4C;YAC5C,0DAA0D;YAC1D,EAAE;YACF,wBAAwB;YACxB,+BAA+B;YAC/B,0BAA0B;YAC1B,oBAAoB;YACpB,iEAAiE;YACjE,KAAK;YACL,EAAE;YACF,oCAAoC;YACpC,+BAA+B;YAC/B,yEAAyE;YACzE,kFAAkF;YAClF,EAAE;YACF,oCAAoC;YACpC,4CAA4C;YAC5C,oEAAoE;YACpE,gEAAgE;YAChE,qBAAqB;YACrB,OAAO;YACP,EAAE;YACF,+BAA+B;YAC/B,iCAAiC;YACjC,oDAAoD;YACpD,wBAAwB;SACzB;KACF;IACD;QACE,EAAE,EAAE,iBAAiB;QACrB,KAAK,EAAE,qCAAqC;QAC5C,OAAO,EAAE,mEAAmE;QAC5E,OAAO,EAAE;YACP,uCAAuC;YACvC,EAAE;YACF,qDAAqD;YACrD,mDAAmD;YACnD,yFAAyF;YACzF,gEAAgE;YAChE,gFAAgF;YAChF,kFAAkF;YAClF,EAAE;YACF,2BAA2B;YAC3B,qFAAqF;YACrF,4EAA4E;SAC7E;KACF;CACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function runCli(args?: string[]): Promise<void>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAKA,wBAAsB,MAAM,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAsGlF"}
@@ -0,0 +1,113 @@
1
+ import path from 'node:path';
2
+ import { build } from '../index.js';
3
+ import { createDevServer } from '../server/dev-server.js';
4
+ import { launchDocsTui } from './tui-docs.js';
5
+ export async function runCli(args = process.argv.slice(2)) {
6
+ const command = args[0] || 'help';
7
+ function getArgValue(flag) {
8
+ const idx = args.indexOf(flag);
9
+ return idx !== -1 && args[idx + 1] ? args[idx + 1] : undefined;
10
+ }
11
+ const hasFlag = (flag) => args.includes(flag);
12
+ if (hasFlag('--help') || hasFlag('-h') || command === 'help') {
13
+ console.log(`
14
+ react-html - Engine to convert React to pure HTML with reactive islands
15
+
16
+ Usage:
17
+ react-html <command> [options]
18
+
19
+ Commands:
20
+ build Compile pages into pure HTML & bundle reactive islands
21
+ dev Start live preview development server with auto-rebuild
22
+ docs Browse interactive documentation in Terminal UI (TUI)
23
+ help Show this help message
24
+
25
+ Options:
26
+ --pages <dir> Pages directory (default: src/pages or pages)
27
+ --out <dir> Output directory (default: dist)
28
+ --port <number> Dev server port (default: 3000)
29
+ --host <string> Dev server host (default: localhost)
30
+ --no-minify Disable minification for island bundles
31
+ --root <path> Project root directory (default: cwd)
32
+
33
+ Docs Options:
34
+ react-html docs Launch interactive Terminal UI
35
+ react-html docs --all Print complete manual to terminal
36
+ react-html docs <section> Print a specific section (e.g. islands, api, cli)
37
+ `);
38
+ return;
39
+ }
40
+ if (hasFlag('--version') || hasFlag('-v')) {
41
+ console.log(`react-html v0.1.0`);
42
+ return;
43
+ }
44
+ const root = getArgValue('--root') || process.cwd();
45
+ const pagesDir = getArgValue('--pages');
46
+ const outDir = getArgValue('--out') || 'dist';
47
+ const minify = !hasFlag('--no-minify');
48
+ if (command === 'build') {
49
+ console.log(`\n🚀 [react-html] Building static site...`);
50
+ const startTime = Date.now();
51
+ try {
52
+ const result = await build({
53
+ root,
54
+ pagesDir,
55
+ outDir,
56
+ minify
57
+ });
58
+ console.log(`✅ [react-html] Build successful in ${Date.now() - startTime}ms`);
59
+ console.log(`📄 Pages compiled (${result.pages.length}):`);
60
+ result.pages.forEach(p => {
61
+ console.log(` - ${path.relative(root, p.output)}`);
62
+ });
63
+ if (result.islands.length > 0) {
64
+ console.log(`🏝️ Reactive islands bundled (${result.islands.length}):`);
65
+ result.islands.forEach(isl => {
66
+ console.log(` - ${path.relative(root, isl)}`);
67
+ });
68
+ }
69
+ else {
70
+ console.log(`✨ Pure 100% HTML generated (0 KB JavaScript overhead)`);
71
+ }
72
+ }
73
+ catch (err) {
74
+ console.error(`❌ [react-html] Build failed:`, err?.message || err);
75
+ process.exit(1);
76
+ }
77
+ }
78
+ else if (command === 'dev') {
79
+ const port = parseInt(getArgValue('--port') || '3000', 10);
80
+ const host = getArgValue('--host') || 'localhost';
81
+ try {
82
+ await createDevServer({
83
+ root,
84
+ pagesDir,
85
+ outDir,
86
+ port,
87
+ host
88
+ });
89
+ }
90
+ catch (err) {
91
+ console.error(`❌ [react-html] Dev server failed:`, err?.message || err);
92
+ process.exit(1);
93
+ }
94
+ }
95
+ else if (command === 'docs') {
96
+ try {
97
+ await launchDocsTui(args[1]);
98
+ }
99
+ catch (err) {
100
+ console.error(`❌ [react-html] Docs error:`, err?.message || err);
101
+ process.exit(1);
102
+ }
103
+ }
104
+ else {
105
+ console.error(`Unknown command "${command}". Run "react-html --help" for available commands.`);
106
+ process.exit(1);
107
+ }
108
+ }
109
+ // Direct invocation check
110
+ if (import.meta.url === `file://${process.argv[1]}`) {
111
+ runCli();
112
+ }
113
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE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EAAE,CAAC;IACpD,MAAM,EAAE,CAAC;AACX,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { DocSection } from './docs-content.js';
2
+ export declare function printSectionDirect(section: DocSection): void;
3
+ export declare function printAllDocs(): void;
4
+ export declare function launchDocsTui(initialArg?: string): Promise<void>;
5
+ //# sourceMappingURL=tui-docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tui-docs.d.ts","sourceRoot":"","sources":["../../src/cli/tui-docs.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAgC7D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAM5D;AAED,wBAAgB,YAAY,IAAI,IAAI,CAQnC;AAED,wBAAsB,aAAa,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiKtE"}