@cloudwerk/vite-plugin 0.1.1 → 0.1.3
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.
- package/README.md +66 -0
- package/dist/index.js +13 -6
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @cloudwerk/vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite plugin for Cloudwerk file-based routing with virtual entry generation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @cloudwerk/vite-plugin vite
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// vite.config.ts
|
|
15
|
+
import { defineConfig } from 'vite'
|
|
16
|
+
import cloudwerk from '@cloudwerk/vite-plugin'
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
plugins: [
|
|
20
|
+
cloudwerk({
|
|
21
|
+
// Options (all optional)
|
|
22
|
+
appDir: 'app', // Directory containing app files
|
|
23
|
+
routesDir: 'routes', // Subdirectory for routes
|
|
24
|
+
renderer: 'hono-jsx', // 'hono-jsx' or 'react'
|
|
25
|
+
verbose: false, // Enable debug logging
|
|
26
|
+
})
|
|
27
|
+
]
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Virtual Modules
|
|
32
|
+
|
|
33
|
+
The plugin generates virtual modules for your application:
|
|
34
|
+
|
|
35
|
+
| Module | Description |
|
|
36
|
+
|--------|-------------|
|
|
37
|
+
| `virtual:cloudwerk/server-entry` | Server entry with route registration |
|
|
38
|
+
| `virtual:cloudwerk/client-entry` | Client entry for hydration |
|
|
39
|
+
| `virtual:cloudwerk/manifest` | Compiled route manifest |
|
|
40
|
+
|
|
41
|
+
Import in your code:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import app from 'virtual:cloudwerk/server-entry'
|
|
45
|
+
import manifest from 'virtual:cloudwerk/manifest'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
| Option | Type | Default | Description |
|
|
51
|
+
|--------|------|---------|-------------|
|
|
52
|
+
| `appDir` | `string` | `'app'` | Directory containing route files |
|
|
53
|
+
| `routesDir` | `string` | `'routes'` | Subdirectory within appDir for routes |
|
|
54
|
+
| `config` | `object` | - | Override Cloudwerk configuration |
|
|
55
|
+
| `serverEntry` | `string` | - | Custom server entry file path |
|
|
56
|
+
| `clientEntry` | `string` | - | Custom client entry file path |
|
|
57
|
+
| `renderer` | `string` | `'hono-jsx'` | UI renderer (`'hono-jsx'` or `'react'`) |
|
|
58
|
+
| `verbose` | `boolean` | `false` | Enable verbose logging |
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
For full documentation, visit: https://github.com/squirrelsoft-dev/cloudwerk
|
|
63
|
+
|
|
64
|
+
## Part of Cloudwerk
|
|
65
|
+
|
|
66
|
+
This package is part of the [Cloudwerk](https://github.com/squirrelsoft-dev/cloudwerk) monorepo.
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function generateServerEntry(manifest, scanResult, options) {
|
|
|
43
43
|
for (const middlewarePath of route.middleware) {
|
|
44
44
|
if (!importedModules.has(middlewarePath)) {
|
|
45
45
|
const varName = `middleware_${middlewareIndex++}`;
|
|
46
|
-
middlewareImports.push(`import ${varName} from '${middlewarePath}'`);
|
|
46
|
+
middlewareImports.push(`import { middleware as ${varName} } from '${middlewarePath}'`);
|
|
47
47
|
middlewareModules.set(middlewarePath, varName);
|
|
48
48
|
importedModules.add(middlewarePath);
|
|
49
49
|
}
|
|
@@ -63,6 +63,13 @@ function generateServerEntry(manifest, scanResult, options) {
|
|
|
63
63
|
imports.push(`import * as ${varName} from '${route.absolutePath}'`);
|
|
64
64
|
const layoutChain = route.layouts.map((p) => layoutModules.get(p)).join(", ");
|
|
65
65
|
const middlewareChain = route.middleware.map((p) => middlewareModules.get(p)).join(", ");
|
|
66
|
+
const hasOptionalCatchAll = route.segments.some((s) => s.type === "optionalCatchAll");
|
|
67
|
+
if (hasOptionalCatchAll) {
|
|
68
|
+
const basePath = route.urlPattern.replace(/\/:[^/]+\{\.\*\}$/, "") || "/";
|
|
69
|
+
pageRegistrations.push(
|
|
70
|
+
` registerPage(app, '${basePath}', ${varName}, [${layoutChain}], [${middlewareChain}])`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
66
73
|
pageRegistrations.push(
|
|
67
74
|
` registerPage(app, '${route.urlPattern}', ${varName}, [${layoutChain}], [${middlewareChain}])`
|
|
68
75
|
);
|
|
@@ -82,7 +89,7 @@ function generateServerEntry(manifest, scanResult, options) {
|
|
|
82
89
|
*/
|
|
83
90
|
|
|
84
91
|
import { Hono } from 'hono'
|
|
85
|
-
import { contextMiddleware, createHandlerAdapter, setRouteConfig } from '@cloudwerk/core/runtime'
|
|
92
|
+
import { contextMiddleware, createHandlerAdapter, createMiddlewareAdapter, setRouteConfig } from '@cloudwerk/core/runtime'
|
|
86
93
|
import { setActiveRenderer } from '@cloudwerk/ui'
|
|
87
94
|
|
|
88
95
|
// Page and Route Imports
|
|
@@ -101,9 +108,9 @@ ${middlewareImports.join("\n")}
|
|
|
101
108
|
const HTTP_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD']
|
|
102
109
|
|
|
103
110
|
function registerPage(app, pattern, pageModule, layoutModules, middlewareModules) {
|
|
104
|
-
// Apply middleware
|
|
111
|
+
// Apply middleware (wrap with adapter to convert Cloudwerk middleware to Hono middleware)
|
|
105
112
|
for (const mw of middlewareModules) {
|
|
106
|
-
app.use(pattern, mw)
|
|
113
|
+
app.use(pattern, createMiddlewareAdapter(mw))
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
// Apply config middleware if present
|
|
@@ -184,9 +191,9 @@ function renderWithHydration(element) {
|
|
|
184
191
|
}
|
|
185
192
|
|
|
186
193
|
function registerRoute(app, pattern, routeModule, middlewareModules) {
|
|
187
|
-
// Apply middleware
|
|
194
|
+
// Apply middleware (wrap with adapter to convert Cloudwerk middleware to Hono middleware)
|
|
188
195
|
for (const mw of middlewareModules) {
|
|
189
|
-
app.use(pattern, mw)
|
|
196
|
+
app.use(pattern, createMiddlewareAdapter(mw))
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
// Apply config middleware if present
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudwerk/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Vite plugin for Cloudwerk file-based routing with virtual entry generation",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@swc/core": "^1.3.100",
|
|
22
|
-
"@cloudwerk/core": "^0.7.
|
|
23
|
-
"@cloudwerk/ui": "^0.7.
|
|
22
|
+
"@cloudwerk/core": "^0.7.2",
|
|
23
|
+
"@cloudwerk/ui": "^0.7.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vite": "^5.0.0 || ^6.0.0",
|