reroute-js 0.2.2 → 0.3.0

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 (196) hide show
  1. package/README.md +14 -0
  2. package/_/README.md +59 -0
  3. package/_/basic/package.json +24 -0
  4. package/_/basic/src/client/App.tsx +10 -0
  5. package/_/basic/src/client/components/Counter.tsx +15 -0
  6. package/_/basic/src/client/index.html +12 -0
  7. package/_/basic/src/client/index.tsx +5 -0
  8. package/_/basic/src/client/routes/[404].tsx +18 -0
  9. package/_/basic/src/client/routes/about.tsx +25 -0
  10. package/_/basic/src/client/routes/index.tsx +57 -0
  11. package/_/basic/src/index.ts +20 -0
  12. package/_/basic/tsconfig.json +26 -0
  13. package/_/blog/package.json +24 -0
  14. package/_/blog/src/client/App.tsx +10 -0
  15. package/_/blog/src/client/components/Counter.tsx +14 -0
  16. package/_/blog/src/client/components/RecentPosts.tsx +90 -0
  17. package/_/blog/src/client/index.html +13 -0
  18. package/_/blog/src/client/index.tsx +5 -0
  19. package/_/blog/src/client/routes/[404].tsx +21 -0
  20. package/_/blog/src/client/routes/about.tsx +31 -0
  21. package/_/blog/src/client/routes/blog/[404].tsx +21 -0
  22. package/_/blog/src/client/routes/blog/[layout].tsx +84 -0
  23. package/_/blog/src/client/routes/blog/[slug].tsx +11 -0
  24. package/_/blog/src/client/routes/blog/content/1-hello-world.tsx +27 -0
  25. package/_/blog/src/client/routes/blog/content/2-what-is-reroute.tsx +31 -0
  26. package/_/blog/src/client/routes/blog/index.tsx +70 -0
  27. package/_/blog/src/client/routes/index.tsx +63 -0
  28. package/_/blog/src/index.ts +20 -0
  29. package/_/blog/tsconfig.json +26 -0
  30. package/_/store/package.json +26 -0
  31. package/_/store/src/client/App.tsx +17 -0
  32. package/_/store/src/client/components/Header.tsx +40 -0
  33. package/_/store/src/client/components/ProductCard.tsx +54 -0
  34. package/_/store/src/client/index.html +17 -0
  35. package/_/store/src/client/index.tsx +7 -0
  36. package/_/store/src/client/lib/api.ts +153 -0
  37. package/_/store/src/client/routes/[404].tsx +63 -0
  38. package/_/store/src/client/routes/categories/[category].tsx +223 -0
  39. package/_/store/src/client/routes/categories/index.tsx +187 -0
  40. package/_/store/src/client/routes/index.tsx +126 -0
  41. package/_/store/src/client/routes/products/[id].tsx +238 -0
  42. package/_/store/src/client/routes/products/index.tsx +261 -0
  43. package/_/store/src/client/theme.css +306 -0
  44. package/_/store/src/index.ts +19 -0
  45. package/_/store/tsconfig.json +26 -0
  46. package/cli/bin.d.ts +11 -0
  47. package/cli/bin.d.ts.map +1 -0
  48. package/cli/bin.js +883 -0
  49. package/cli/bin.js.map +15 -0
  50. package/cli/index.d.ts +11 -0
  51. package/cli/index.d.ts.map +1 -0
  52. package/cli/index.js +113 -0
  53. package/cli/index.js.map +10 -0
  54. package/cli/src/cli.d.ts +16 -0
  55. package/cli/src/cli.d.ts.map +1 -0
  56. package/cli/src/commands/build.d.ts +16 -0
  57. package/cli/src/commands/build.d.ts.map +1 -0
  58. package/cli/src/commands/dev.d.ts +16 -0
  59. package/cli/src/commands/dev.d.ts.map +1 -0
  60. package/cli/src/commands/gen.d.ts +11 -0
  61. package/cli/src/commands/gen.d.ts.map +1 -0
  62. package/cli/src/commands/init.d.ts +16 -0
  63. package/cli/src/commands/init.d.ts.map +1 -0
  64. package/cli/src/libs/index.d.ts +11 -0
  65. package/cli/src/libs/index.d.ts.map +1 -0
  66. package/cli/src/libs/tailwind.d.ts +20 -0
  67. package/cli/src/libs/tailwind.d.ts.map +1 -0
  68. package/core/index.d.ts +11 -0
  69. package/core/index.d.ts.map +1 -0
  70. package/core/index.js +1138 -0
  71. package/core/index.js.map +25 -0
  72. package/core/src/bundler/hash.d.ts +11 -0
  73. package/core/src/bundler/hash.d.ts.map +1 -0
  74. package/core/src/bundler/index.d.ts +12 -0
  75. package/core/src/bundler/index.d.ts.map +1 -0
  76. package/core/src/bundler/transpile.d.ts +13 -0
  77. package/core/src/bundler/transpile.d.ts.map +1 -0
  78. package/core/src/content/discovery.d.ts +14 -0
  79. package/core/src/content/discovery.d.ts.map +1 -0
  80. package/core/src/content/index.d.ts +13 -0
  81. package/core/src/content/index.d.ts.map +1 -0
  82. package/core/src/content/metadata.d.ts +18 -0
  83. package/core/src/content/metadata.d.ts.map +1 -0
  84. package/core/src/content/registry.d.ts +11 -0
  85. package/core/src/content/registry.d.ts.map +1 -0
  86. package/core/src/index.d.ts +16 -0
  87. package/core/src/index.d.ts.map +1 -0
  88. package/core/src/ssr/data.d.ts +18 -0
  89. package/core/src/ssr/data.d.ts.map +1 -0
  90. package/core/src/ssr/index.d.ts +13 -0
  91. package/core/src/ssr/index.d.ts.map +1 -0
  92. package/core/src/ssr/modules.d.ts +17 -0
  93. package/core/src/ssr/modules.d.ts.map +1 -0
  94. package/core/src/ssr/render.d.ts +29 -0
  95. package/core/src/ssr/render.d.ts.map +1 -0
  96. package/core/src/ssr/seed.d.ts +11 -0
  97. package/core/src/ssr/seed.d.ts.map +1 -0
  98. package/core/src/template/html.d.ts +13 -0
  99. package/core/src/template/html.d.ts.map +1 -0
  100. package/core/src/template/index.d.ts +11 -0
  101. package/core/src/template/index.d.ts.map +1 -0
  102. package/core/src/types.d.ts +59 -0
  103. package/core/src/types.d.ts.map +1 -0
  104. package/core/src/utils/cache.d.ts +21 -0
  105. package/core/src/utils/cache.d.ts.map +1 -0
  106. package/core/src/utils/compression.d.ts +14 -0
  107. package/core/src/utils/compression.d.ts.map +1 -0
  108. package/core/src/utils/index.d.ts +14 -0
  109. package/core/src/utils/index.d.ts.map +1 -0
  110. package/core/src/utils/mime.d.ts +12 -0
  111. package/core/src/utils/mime.d.ts.map +1 -0
  112. package/core/src/utils/path.d.ts +15 -0
  113. package/core/src/utils/path.d.ts.map +1 -0
  114. package/elysia/index.d.ts +11 -0
  115. package/elysia/index.d.ts.map +1 -0
  116. package/elysia/index.js +2101 -0
  117. package/elysia/index.js.map +34 -0
  118. package/elysia/src/index.d.ts +12 -0
  119. package/elysia/src/index.d.ts.map +1 -0
  120. package/elysia/src/libs/http.d.ts +14 -0
  121. package/elysia/src/libs/http.d.ts.map +1 -0
  122. package/elysia/src/libs/image.d.ts +38 -0
  123. package/elysia/src/libs/image.d.ts.map +1 -0
  124. package/elysia/src/plugin.d.ts +41 -0
  125. package/elysia/src/plugin.d.ts.map +1 -0
  126. package/elysia/src/routes/artifacts.d.ts +12 -0
  127. package/elysia/src/routes/artifacts.d.ts.map +1 -0
  128. package/elysia/src/routes/content.d.ts +12 -0
  129. package/elysia/src/routes/content.d.ts.map +1 -0
  130. package/elysia/src/routes/dev.d.ts +18 -0
  131. package/elysia/src/routes/dev.d.ts.map +1 -0
  132. package/elysia/src/routes/image.d.ts +23 -0
  133. package/elysia/src/routes/image.d.ts.map +1 -0
  134. package/elysia/src/routes/ssr.d.ts +32 -0
  135. package/elysia/src/routes/ssr.d.ts.map +1 -0
  136. package/elysia/src/routes/static.d.ts +28 -0
  137. package/elysia/src/routes/static.d.ts.map +1 -0
  138. package/elysia/src/types.d.ts +44 -0
  139. package/elysia/src/types.d.ts.map +1 -0
  140. package/package.json +6 -5
  141. package/react/index.d.ts +11 -0
  142. package/react/index.d.ts.map +1 -0
  143. package/react/index.js +1370 -0
  144. package/react/index.js.map +24 -0
  145. package/react/src/components/ContentRoute.d.ts +22 -0
  146. package/react/src/components/ContentRoute.d.ts.map +1 -0
  147. package/react/src/components/Image.d.ts +53 -0
  148. package/react/src/components/Image.d.ts.map +1 -0
  149. package/react/src/components/Link.d.ts +17 -0
  150. package/react/src/components/Link.d.ts.map +1 -0
  151. package/react/src/components/Outlet.d.ts +16 -0
  152. package/react/src/components/Outlet.d.ts.map +1 -0
  153. package/react/src/components/index.d.ts +14 -0
  154. package/react/src/components/index.d.ts.map +1 -0
  155. package/react/src/hooks/index.d.ts +16 -0
  156. package/react/src/hooks/index.d.ts.map +1 -0
  157. package/react/src/hooks/useContent.d.ts +35 -0
  158. package/react/src/hooks/useContent.d.ts.map +1 -0
  159. package/react/src/hooks/useData.d.ts +19 -0
  160. package/react/src/hooks/useData.d.ts.map +1 -0
  161. package/react/src/hooks/useNavigate.d.ts +15 -0
  162. package/react/src/hooks/useNavigate.d.ts.map +1 -0
  163. package/react/src/hooks/useParams.d.ts +15 -0
  164. package/react/src/hooks/useParams.d.ts.map +1 -0
  165. package/react/src/hooks/useRouter.d.ts +16 -0
  166. package/react/src/hooks/useRouter.d.ts.map +1 -0
  167. package/react/src/hooks/useSearchParams.d.ts +15 -0
  168. package/react/src/hooks/useSearchParams.d.ts.map +1 -0
  169. package/react/src/index.d.ts +15 -0
  170. package/react/src/index.d.ts.map +1 -0
  171. package/react/src/providers/ContentProvider.d.ts +44 -0
  172. package/react/src/providers/ContentProvider.d.ts.map +1 -0
  173. package/react/src/providers/RerouteProvider.d.ts +34 -0
  174. package/react/src/providers/RerouteProvider.d.ts.map +1 -0
  175. package/react/src/providers/RouterProvider.d.ts +32 -0
  176. package/react/src/providers/RouterProvider.d.ts.map +1 -0
  177. package/react/src/providers/index.d.ts +13 -0
  178. package/react/src/providers/index.d.ts.map +1 -0
  179. package/react/src/types/any.d.ts +12 -0
  180. package/react/src/types/any.d.ts.map +1 -0
  181. package/react/src/types/index.d.ts +12 -0
  182. package/react/src/types/index.d.ts.map +1 -0
  183. package/react/src/types/router.d.ts +41 -0
  184. package/react/src/types/router.d.ts.map +1 -0
  185. package/react/src/utils/content.d.ts +17 -0
  186. package/react/src/utils/content.d.ts.map +1 -0
  187. package/react/src/utils/head.d.ts +15 -0
  188. package/react/src/utils/head.d.ts.map +1 -0
  189. package/react/src/utils/index.d.ts +12 -0
  190. package/react/src/utils/index.d.ts.map +1 -0
  191. package/CHANGELOG.md +0 -29
  192. package/packages/cli/README.md +0 -264
  193. package/packages/cli/bin.ts +0 -3
  194. package/packages/core/README.md +0 -90
  195. package/packages/elysia/README.md +0 -250
  196. package/packages/react/README.md +0 -3
@@ -1,250 +0,0 @@
1
- # Reroute Elysia
2
-
3
- Elysia adapter for the Reroute framework. This package provides an Elysia plugin that enables server-side rendering, static file serving, content management, and live reload for React applications.
4
-
5
- ## Overview
6
-
7
- This package is a thin adapter layer that integrates Reroute's core functionality with the Elysia web framework. It handles:
8
-
9
- - **Server-Side Rendering (SSR)**: Automatic SSR for React components
10
- - **Static File Serving**: Optimized static asset delivery with compression
11
- - **Content Management**: File-based content collections with automatic discovery
12
- - **Live Reload**: Development mode with hot reload via SSE
13
- - **TypeScript/JSX Transpilation**: On-the-fly bundling with Bun
14
- - **Asset Optimization**: Content hashing, compression, and caching
15
-
16
- ## Installation
17
-
18
- ```bash
19
- bun add reroute-js elysia react react-dom
20
- ```
21
-
22
- ## Usage
23
-
24
- ### Basic Setup
25
-
26
- ```typescript
27
- import { Elysia } from 'elysia';
28
- import { reroute } from 'reroute-js/elysia';
29
- import { createElement } from 'react';
30
- import App from './App';
31
-
32
- const app = new Elysia()
33
- .use(
34
- reroute({
35
- app: createElement(App),
36
- assets: 'src/client',
37
- prefix: '/',
38
- })
39
- )
40
- .listen(3000);
41
-
42
- console.log(`Server running at http://localhost:3000`);
43
- ```
44
-
45
- ### With Collections
46
-
47
- Content collections are automatically discovered from your `routes` directory:
48
-
49
- ```
50
- src/client/
51
- ├── routes/
52
- │ ├── blog/
53
- │ │ └── content/
54
- │ │ ├── post-1.tsx
55
- │ │ └── post-2.tsx
56
- │ └── docs/
57
- │ └── content/
58
- │ └── guide.tsx
59
- ├── index.html
60
- └── index.tsx
61
- ```
62
-
63
- Collections are accessible at:
64
- - `/blog/post-1` - SSR rendered
65
- - `/blog/post-2` - SSR rendered
66
- - `/__content/blog` - JSON manifest with all blog posts
67
-
68
- ## API
69
-
70
- ### `reroute(options: RerouteOptions)`
71
-
72
- Creates an Elysia plugin with the provided configuration.
73
-
74
- #### Options
75
-
76
- ##### SSR Options
77
-
78
- - **`app?: ReactElement`** - Root React component for SSR. When provided, enables automatic SSR for all routes.
79
- - **`head?: string`** - Additional HTML to inject into `<head>` (default: `''`)
80
- - **`lang?: string`** - HTML document language (default: `'en'`)
81
- - **`appId?: string`** - ID of the root element (default: `'root'`)
82
- - **`entrypoint?: string`** - Client-side entry file (default: `'index.tsx'`)
83
-
84
- ##### Static Serving Options
85
-
86
- - **`assets?: string`** - Assets directory path (default: `'src/client'`)
87
- - **`prefix?: string`** - URL prefix for static files (default: `'/'`)
88
- - **`ignorePatterns?: (string | RegExp)[]`** - Files to ignore (default: `['.DS_Store', '.git', '.env', 'index.html', /favicon\.ico/, /\.well-known/]`)
89
- - **`staticHeaders?: Record<string, string>`** - Additional headers for static files
90
- - **`maxAge?: number`** - Cache max-age in seconds (default: `3600`)
91
- - **`directive?: string`** - Cache-Control directive (default: `'public'`)
92
- - **`indexHTML?: boolean`** - Serve index.html for directories (default: `true`)
93
-
94
- ##### Build Options
95
-
96
- - **`minify?: boolean`** - Minify JavaScript bundles (default: `process.env.NODE_ENV === 'production'`)
97
- - **`sourcemap?: boolean`** - Generate sourcemaps (default: `true`)
98
-
99
- ## Features
100
-
101
- ### Automatic SSR
102
-
103
- When you provide a root component via the `app` option, Reroute automatically:
104
-
105
- 1. Discovers content collections in your routes directory
106
- 2. Registers SSR routes for each collection (e.g., `/blog/*`, `/docs/*`)
107
- 3. Renders components on the server with React
108
- 4. Sends fully hydrated HTML to the client
109
- 5. Hydrates the client-side React app seamlessly
110
-
111
- ### Content Collections
112
-
113
- Content files are TypeScript/TSX modules that export a React component and optional metadata:
114
-
115
- ```tsx
116
- // src/client/routes/blog/content/my-post.tsx
117
- export const meta = {
118
- title: 'My Blog Post',
119
- excerpt: 'This is a great post',
120
- date: '2024-01-15',
121
- };
122
-
123
- // Optional SSR extras per page
124
- export const ssr = {
125
- // Extra tags appended verbatim into <head>
126
- head: [
127
- '<meta property="og:type" content="article" />',
128
- ],
129
- // Override document language for this page
130
- lang: 'en',
131
- };
132
-
133
- export default function MyPost() {
134
- return (
135
- <article>
136
- <h1>My Blog Post</h1>
137
- <p>Content goes here...</p>
138
- </article>
139
- );
140
- }
141
- ```
142
-
143
- Access via:
144
- - **Route**: `/blog/my-post` (SSR rendered)
145
- - **API**: `/__content/blog` (JSON manifest)
146
-
147
- During SSR, `meta.title` and `meta.description` (or `meta.excerpt`) are converted into `<title>` and `<meta name="description">`. Any `ssr.head` content is appended to `<head>`, and `ssr.lang` overrides the HTML `lang` attribute for that response.
148
-
149
- ### Development Mode
150
-
151
- Run with `--watch` flag to enable live reload:
152
-
153
- ```bash
154
- bun --watch src/server.ts
155
- ```
156
-
157
- Features:
158
- - File watching with automatic rebuild
159
- - SSE-based live reload (no browser extension needed)
160
- - Fast hot module replacement
161
- - Source map support
162
-
163
- ### Production Optimization
164
-
165
- In production:
166
- - JavaScript bundles are minified
167
- - Content is hashed for cache busting (e.g., `index.abc12345.js`)
168
- - Responses are gzip compressed
169
- - Aggressive caching headers for hashed assets
170
- - Preloading hints for content chunks
171
-
172
- ## Routes
173
-
174
- The Elysia plugin registers these routes automatically:
175
-
176
- ### Content Routes
177
- - `/__content/:collection` - JSON manifest of collection items
178
-
179
- ### Development Routes (watch mode only)
180
- - `/__reroute_watch` - SSE endpoint for live reload
181
- - `/__reroute_watch.js` - Live reload client script
182
- - `/__reroute_preload` - Content chunk preloader
183
-
184
- ### Artifact Routes
185
- - `/.reroute/*` - Generated content chunks and bundles
186
-
187
- ### SSR Routes
188
- - `/:collection/:slug` - Server-rendered collection items
189
- - `/*` (fallback) - Catch-all SSR for unmatched routes
190
-
191
- ### Static Routes
192
- - `${prefix}/*` - Static file serving with transpilation
193
-
194
- ## Architecture
195
-
196
- This package is built on top of `reroute-js/core`, which provides framework-agnostic utilities. The Elysia adapter:
197
-
198
- 1. Translates Elysia request/response objects
199
- 2. Registers appropriate route handlers
200
- 3. Handles errors with Elysia's `NotFoundError`
201
- 4. Manages caches and live reload state
202
-
203
- This separation allows Reroute to support multiple frameworks (Hono, Fastify, etc.) by creating similar adapter packages.
204
-
205
- ## Examples
206
-
207
- ### Custom Ignore Patterns
208
-
209
- ```typescript
210
- reroute({
211
- ignorePatterns: [
212
- '.DS_Store',
213
- /\.test\.(ts|tsx|js|jsx)$/,
214
- /^_/, // Ignore files starting with underscore
215
- ],
216
- })
217
- ```
218
-
219
- ### Custom Headers
220
-
221
- ```typescript
222
- reroute({
223
- staticHeaders: {
224
- 'X-Custom-Header': 'value',
225
- 'Access-Control-Allow-Origin': '*',
226
- },
227
- })
228
- ```
229
-
230
- ### Multiple Asset Directories
231
-
232
- You can mount multiple reroute instances with different prefixes:
233
-
234
- ```typescript
235
- new Elysia()
236
- .use(reroute({ assets: 'src/client', prefix: '/app' }))
237
- .use(reroute({ assets: 'src/admin', prefix: '/admin' }))
238
- ```
239
-
240
- ## TypeScript
241
-
242
- All types are exported from the package:
243
-
244
- ```typescript
245
- import type { RerouteOptions } from 'reroute-js/elysia';
246
- ```
247
-
248
- ## License
249
-
250
- MIT
@@ -1,3 +0,0 @@
1
- # Reroute React
2
-
3
- React specific building blocks to enable the Reroute features.