@mauroandre/velojs 0.0.31 → 0.0.33
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/dist/client.d.ts +3 -0
- package/dist/client.js +32 -25
- package/dist/init.js +18 -5
- package/dist/server.js +66 -66
- package/dist/static.js +45 -33
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -2,4 +2,7 @@ import type { AppRoutes } from "./types.js";
|
|
|
2
2
|
export interface StartClientOptions {
|
|
3
3
|
routes: AppRoutes;
|
|
4
4
|
}
|
|
5
|
+
export declare const ClientRoutes: ({ routes }: {
|
|
6
|
+
routes: AppRoutes;
|
|
7
|
+
}) => import("preact").JSX.Element;
|
|
5
8
|
export declare const startClient: (options: StartClientOptions) => void;
|
package/dist/client.js
CHANGED
|
@@ -1,46 +1,53 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { hydrate as
|
|
1
|
+
import { jsx as n } from "preact/jsx-runtime";
|
|
2
|
+
import { hydrate as m } from "preact";
|
|
3
3
|
import { Router as f, Route as l, Switch as s } from "wouter-preact";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
for (let
|
|
7
|
-
const t =
|
|
4
|
+
const p = (o, e) => o.reduceRight((r, i) => /* @__PURE__ */ n(i, { children: r }), e), h = (o, e = [], r = "") => {
|
|
5
|
+
const i = [];
|
|
6
|
+
for (let u = 0; u < o.length; u++) {
|
|
7
|
+
const t = o[u], c = `${r}${u}`;
|
|
8
8
|
if (!t.module) {
|
|
9
|
-
|
|
10
|
-
for (const d of u(t.children, i))
|
|
11
|
-
o.push(d);
|
|
9
|
+
t.children && i.push(...h(t.children, e, `${c}-`));
|
|
12
10
|
continue;
|
|
13
11
|
}
|
|
14
|
-
const
|
|
12
|
+
const d = t.module.Component;
|
|
15
13
|
if (!t.children) {
|
|
16
|
-
|
|
17
|
-
/* @__PURE__ */
|
|
14
|
+
i.push(
|
|
15
|
+
/* @__PURE__ */ n(l, { path: t.path || "", children: p(e, /* @__PURE__ */ n(d, {})) }, c)
|
|
18
16
|
);
|
|
19
17
|
continue;
|
|
20
18
|
}
|
|
21
|
-
const h = u(t.children, !!t.path);
|
|
22
19
|
if (t.isRoot) {
|
|
23
|
-
|
|
20
|
+
i.push(
|
|
21
|
+
/* @__PURE__ */ n(s, { children: h(t.children, [], `${c}-`) }, c)
|
|
22
|
+
);
|
|
24
23
|
continue;
|
|
25
24
|
}
|
|
26
25
|
if (!t.path) {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
i.push(
|
|
27
|
+
...h(
|
|
28
|
+
t.children,
|
|
29
|
+
[...e, d],
|
|
30
|
+
`${c}-`
|
|
31
|
+
)
|
|
29
32
|
);
|
|
30
33
|
continue;
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
/* @__PURE__ */
|
|
35
|
+
i.push(
|
|
36
|
+
/* @__PURE__ */ n(l, { path: t.path, nest: !0, children: p(
|
|
37
|
+
e,
|
|
38
|
+
/* @__PURE__ */ n(d, { children: /* @__PURE__ */ n(s, { children: h(t.children, [], `${c}-`) }) })
|
|
39
|
+
) }, c)
|
|
34
40
|
);
|
|
35
41
|
}
|
|
36
|
-
return
|
|
37
|
-
},
|
|
38
|
-
const
|
|
39
|
-
return /* @__PURE__ */
|
|
40
|
-
}, C = (
|
|
41
|
-
const { routes:
|
|
42
|
-
|
|
42
|
+
return i;
|
|
43
|
+
}, a = ({ routes: o }) => {
|
|
44
|
+
const e = h(o);
|
|
45
|
+
return /* @__PURE__ */ n(f, { children: e });
|
|
46
|
+
}, C = (o) => {
|
|
47
|
+
const { routes: e } = o, r = document.querySelector("body");
|
|
48
|
+
r && m(/* @__PURE__ */ n(a, { routes: e }), r);
|
|
43
49
|
};
|
|
44
50
|
export {
|
|
51
|
+
a as ClientRoutes,
|
|
45
52
|
C as startClient
|
|
46
53
|
};
|
package/dist/init.js
CHANGED
|
@@ -54,6 +54,7 @@ export default { plugins: [veloPlugin()] };
|
|
|
54
54
|
|
|
55
55
|
import * as Root from "./client-root.js";
|
|
56
56
|
import * as Home from "./pages/Home.js";
|
|
57
|
+
import * as NotFound from "./pages/NotFound.js";
|
|
57
58
|
|
|
58
59
|
export default [
|
|
59
60
|
{
|
|
@@ -61,6 +62,8 @@ export default [
|
|
|
61
62
|
isRoot: true,
|
|
62
63
|
children: [
|
|
63
64
|
{ path: "/", module: Home },
|
|
65
|
+
// Catch-all 404 — keep last. Served via notFound (SSR) / 404.html (SSG).
|
|
66
|
+
{ path: "*", module: NotFound, statusCode: 404 },
|
|
64
67
|
],
|
|
65
68
|
},
|
|
66
69
|
] satisfies AppRoutes;
|
|
@@ -123,9 +126,19 @@ a:hover {
|
|
|
123
126
|
</main>
|
|
124
127
|
);
|
|
125
128
|
};
|
|
129
|
+
`,
|
|
130
|
+
"app/pages/NotFound.tsx": `export const Component = () => {
|
|
131
|
+
return (
|
|
132
|
+
<main style={{ maxWidth: 640, margin: "80px auto", padding: "0 20px" }}>
|
|
133
|
+
<h1>404</h1>
|
|
134
|
+
<p>Page not found.</p>
|
|
135
|
+
<a href="/">Go home</a>
|
|
136
|
+
</main>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
126
139
|
`
|
|
127
140
|
};
|
|
128
|
-
async function
|
|
141
|
+
async function x(o) {
|
|
129
142
|
const e = o ? s.resolve(process.cwd(), o) : process.cwd(), r = s.basename(e);
|
|
130
143
|
t.existsSync(e) ? t.readdirSync(e).filter(
|
|
131
144
|
(n) => !n.startsWith(".") && n !== "node_modules"
|
|
@@ -133,10 +146,10 @@ async function v(o) {
|
|
|
133
146
|
`Error: Directory "${r}" is not empty. Use an empty directory.`
|
|
134
147
|
), process.exit(1)) : t.mkdirSync(e, { recursive: !0 });
|
|
135
148
|
for (const [a, n] of Object.entries(u)) {
|
|
136
|
-
const
|
|
149
|
+
const p = s.join(e, a), l = s.dirname(p);
|
|
137
150
|
t.existsSync(l) || t.mkdirSync(l, { recursive: !0 });
|
|
138
|
-
const
|
|
139
|
-
t.writeFileSync(
|
|
151
|
+
const c = a === "package.json" ? n.replace("my-velojs-app", r) : n;
|
|
152
|
+
t.writeFileSync(p, c);
|
|
140
153
|
}
|
|
141
154
|
console.log(`
|
|
142
155
|
Project created in ${o ? r : "current directory"}!
|
|
@@ -145,5 +158,5 @@ Project created in ${o ? r : "current directory"}!
|
|
|
145
158
|
`);
|
|
146
159
|
}
|
|
147
160
|
export {
|
|
148
|
-
|
|
161
|
+
x as runInit
|
|
149
162
|
};
|
package/dist/server.js
CHANGED
|
@@ -2,13 +2,13 @@ import { jsx as g } from "preact/jsx-runtime";
|
|
|
2
2
|
import { Hono as R } from "hono";
|
|
3
3
|
import { logger as T } from "hono/logger";
|
|
4
4
|
import { trimTrailingSlash as j } from "hono/trailing-slash";
|
|
5
|
-
import { render as
|
|
6
|
-
import { Router as
|
|
7
|
-
import { AsyncLocalStorage as
|
|
5
|
+
import { render as A } from "preact-render-to-string";
|
|
6
|
+
import { Router as C } from "wouter-preact";
|
|
7
|
+
import { AsyncLocalStorage as k } from "node:async_hooks";
|
|
8
8
|
import { getAppContext as v } from "./app-context.js";
|
|
9
9
|
import { flushPendingStreamRoutes as $, registerStreamHandler as D } from "./events.js";
|
|
10
10
|
import { registerSocketRoutes as I, injectWebSocketServer as y } from "./sockets.js";
|
|
11
|
-
const S = new
|
|
11
|
+
const S = new k();
|
|
12
12
|
globalThis.__veloServerData = S;
|
|
13
13
|
let w = null;
|
|
14
14
|
function Y(e) {
|
|
@@ -27,38 +27,38 @@ function P(e) {
|
|
|
27
27
|
function Z(e) {
|
|
28
28
|
v().pendingRoutes.push(e);
|
|
29
29
|
}
|
|
30
|
-
const N = (e, t, s) => {
|
|
31
|
-
if (e.req.query("_data") === "1") {
|
|
32
|
-
const
|
|
33
|
-
return e.json(
|
|
30
|
+
const N = (e, t, s, r) => {
|
|
31
|
+
if (r && r !== 200 && e.status(r), e.req.query("_data") === "1") {
|
|
32
|
+
const i = globalThis.__veloBuildHash || void 0, l = s ? { ...s, __buildHash: i } : { __buildHash: i };
|
|
33
|
+
return e.json(l);
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const o = e.req.path, n = S.run(
|
|
36
36
|
s ?? {},
|
|
37
|
-
() =>
|
|
37
|
+
() => A(/* @__PURE__ */ g(C, { ssrPath: o, children: t }))
|
|
38
38
|
);
|
|
39
39
|
if (e.header("Cache-Control", "no-cache"), !s)
|
|
40
|
-
return e.html(
|
|
41
|
-
const
|
|
40
|
+
return e.html(n);
|
|
41
|
+
const a = `<script>window.__PAGE_DATA__=${JSON.stringify(
|
|
42
42
|
s
|
|
43
43
|
)}<\/script>`;
|
|
44
|
-
return e.html(
|
|
44
|
+
return e.html(n.replace("</head>", `${a}</head>`));
|
|
45
45
|
}, O = async (e, t) => {
|
|
46
|
-
const s = t.req.param(),
|
|
46
|
+
const s = t.req.param(), r = t.req.query(), o = { params: s, query: r, c: t }, n = await Promise.all(
|
|
47
47
|
e.map(async (i) => {
|
|
48
48
|
if (!i.loader) return null;
|
|
49
49
|
const l = await i.loader(o), c = i.metadata?.moduleId;
|
|
50
50
|
return c ? { moduleId: c, loaderData: l } : null;
|
|
51
51
|
})
|
|
52
|
-
),
|
|
52
|
+
), a = {
|
|
53
53
|
__params: s,
|
|
54
|
-
__query:
|
|
54
|
+
__query: r,
|
|
55
55
|
__pathname: t.req.path
|
|
56
56
|
};
|
|
57
57
|
for (const i of n)
|
|
58
|
-
i && (
|
|
58
|
+
i && (a[i.moduleId] = i.loaderData);
|
|
59
59
|
return {
|
|
60
60
|
components: e.map((i) => i.Component),
|
|
61
|
-
data:
|
|
61
|
+
data: a
|
|
62
62
|
};
|
|
63
63
|
}, G = (e) => {
|
|
64
64
|
if (e.length === 0) return null;
|
|
@@ -70,19 +70,19 @@ const N = (e, t, s) => {
|
|
|
70
70
|
}
|
|
71
71
|
const s = t[t.length - 1];
|
|
72
72
|
return t.slice(0, -1).reduceRight((o, n) => /* @__PURE__ */ g(n, { children: o }), /* @__PURE__ */ g(s, {}));
|
|
73
|
-
}, _ = (e, t, s = [],
|
|
73
|
+
}, _ = (e, t, s = [], r = []) => {
|
|
74
74
|
for (const o of t) {
|
|
75
75
|
if (o.handler && !o.module) {
|
|
76
76
|
o.children && _(
|
|
77
77
|
e,
|
|
78
78
|
o.children,
|
|
79
79
|
s,
|
|
80
|
-
[...
|
|
80
|
+
[...r, ...o.middlewares || []]
|
|
81
81
|
);
|
|
82
82
|
continue;
|
|
83
83
|
}
|
|
84
|
-
const n = o.module ? [...s, o.module] : s,
|
|
85
|
-
...
|
|
84
|
+
const n = o.module ? [...s, o.module] : s, a = [
|
|
85
|
+
...r,
|
|
86
86
|
...o.middlewares || []
|
|
87
87
|
];
|
|
88
88
|
if (o.children)
|
|
@@ -90,36 +90,36 @@ const N = (e, t, s) => {
|
|
|
90
90
|
e,
|
|
91
91
|
o.children,
|
|
92
92
|
n,
|
|
93
|
-
|
|
93
|
+
a
|
|
94
94
|
);
|
|
95
95
|
else if (o.module) {
|
|
96
|
-
const i = o.module.metadata?.fullPath;
|
|
97
|
-
if (!i) {
|
|
96
|
+
const i = o.path === "*", l = o.statusCode ?? (i ? 404 : void 0), c = o.module.metadata?.fullPath;
|
|
97
|
+
if (!c && !i) {
|
|
98
98
|
console.warn(
|
|
99
99
|
`Module ${o.module.metadata?.moduleId} has no fullPath`
|
|
100
100
|
);
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
const { components:
|
|
105
|
-
return N(
|
|
103
|
+
const u = async (h) => {
|
|
104
|
+
const { components: d, data: m } = await O(n, h), f = G(d);
|
|
105
|
+
return N(h, f, m, l);
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
i ? e.notFound(u) : a.length > 0 ? e.on(["GET"], [c], ...a, u) : e.on(["GET"], [c], u);
|
|
108
108
|
} else
|
|
109
109
|
continue;
|
|
110
110
|
}
|
|
111
111
|
}, b = (e, t, s = []) => {
|
|
112
|
-
for (const
|
|
113
|
-
const o =
|
|
112
|
+
for (const r of t) {
|
|
113
|
+
const o = r.module?.metadata?.moduleId, n = [
|
|
114
114
|
...s,
|
|
115
|
-
...
|
|
115
|
+
...r.middlewares || []
|
|
116
116
|
];
|
|
117
|
-
if (
|
|
118
|
-
const
|
|
117
|
+
if (r.module && o) {
|
|
118
|
+
const a = Object.keys(r.module).filter(
|
|
119
119
|
(i) => i.startsWith("action_")
|
|
120
120
|
);
|
|
121
|
-
for (const i of
|
|
122
|
-
const l = i.replace("action_", ""), c =
|
|
121
|
+
for (const i of a) {
|
|
122
|
+
const l = i.replace("action_", ""), c = r.module[i];
|
|
123
123
|
if (typeof c == "function") {
|
|
124
124
|
const u = `/_action/${o}/${l}`, h = async (d) => {
|
|
125
125
|
let m = {};
|
|
@@ -150,21 +150,21 @@ const N = (e, t, s) => {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
|
|
153
|
+
r.children && b(e, r.children, n);
|
|
154
154
|
}
|
|
155
155
|
}, H = async (e, t, s = []) => {
|
|
156
|
-
const
|
|
157
|
-
for (const
|
|
158
|
-
const i =
|
|
156
|
+
const r = (o, n) => {
|
|
157
|
+
for (const a of o) {
|
|
158
|
+
const i = a.module?.metadata?.moduleId, l = [
|
|
159
159
|
...n,
|
|
160
|
-
...
|
|
160
|
+
...a.middlewares || []
|
|
161
161
|
];
|
|
162
|
-
if (
|
|
163
|
-
const c = Object.keys(
|
|
162
|
+
if (a.module && i) {
|
|
163
|
+
const c = Object.keys(a.module).filter(
|
|
164
164
|
(u) => u.startsWith("stream_")
|
|
165
165
|
);
|
|
166
166
|
for (const u of c) {
|
|
167
|
-
const h = u.replace("stream_", ""), d =
|
|
167
|
+
const h = u.replace("stream_", ""), d = a.module[u];
|
|
168
168
|
if (d?.__isVeloEventStream) {
|
|
169
169
|
const m = `/_event/${i}/${h}`;
|
|
170
170
|
d.__path = m, D(
|
|
@@ -176,13 +176,13 @@ const N = (e, t, s) => {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
a.children && r(a.children, l);
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
-
|
|
182
|
+
r(t, s);
|
|
183
183
|
}, x = (e, t) => t ? t.startsWith("/") ? e + t : e ? e + "/" + t : "/" + t : e || "", V = (e) => {
|
|
184
|
-
const t = /* @__PURE__ */ new Set(), s = (
|
|
185
|
-
for (const o of
|
|
184
|
+
const t = /* @__PURE__ */ new Set(), s = (r) => {
|
|
185
|
+
for (const o of r) {
|
|
186
186
|
if (o.module && !o.children) {
|
|
187
187
|
const n = o.module.metadata?.fullPath;
|
|
188
188
|
n && t.add(n);
|
|
@@ -191,45 +191,45 @@ const N = (e, t, s) => {
|
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
193
|
return s(e), t;
|
|
194
|
-
}, q = (e, t, s,
|
|
194
|
+
}, q = (e, t, s, r = "", o = []) => {
|
|
195
195
|
for (const n of t) {
|
|
196
|
-
const
|
|
196
|
+
const a = x(r, n.path), i = [
|
|
197
197
|
...o,
|
|
198
198
|
...n.middlewares || []
|
|
199
199
|
], l = !!n.handler, c = !!n.method;
|
|
200
200
|
if (l && !c ? console.warn(
|
|
201
|
-
`[velojs] invalid route at "${
|
|
201
|
+
`[velojs] invalid route at "${a || "/"}" — "handler" set without "method"; endpoint skipped`
|
|
202
202
|
) : c && !l ? console.warn(
|
|
203
|
-
`[velojs] invalid route at "${
|
|
203
|
+
`[velojs] invalid route at "${a || "/"}" — "method" set without "handler"; endpoint skipped`
|
|
204
204
|
) : l && n.module ? console.warn(
|
|
205
|
-
`[velojs] ambiguous route at "${
|
|
205
|
+
`[velojs] ambiguous route at "${a || "/"}" — both "module" and "handler" set; endpoint ignored, page kept`
|
|
206
206
|
) : l && n.isRoot && console.warn(
|
|
207
|
-
`[velojs] "isRoot" has no effect on endpoint at "${
|
|
207
|
+
`[velojs] "isRoot" has no effect on endpoint at "${a || "/"}"; ignored`
|
|
208
208
|
), l && c && !n.module) {
|
|
209
209
|
const h = n.method;
|
|
210
|
-
h === "GET" && s.has(
|
|
211
|
-
`[velojs] path "${
|
|
210
|
+
h === "GET" && s.has(a) && console.warn(
|
|
211
|
+
`[velojs] path "${a}" has both a page GET and an endpoint GET; endpoint will win. Consider renaming one.`
|
|
212
212
|
);
|
|
213
213
|
const d = n.handler, m = async (f) => await d({
|
|
214
214
|
c: f,
|
|
215
215
|
params: f.req.param(),
|
|
216
216
|
query: f.req.query()
|
|
217
217
|
});
|
|
218
|
-
i.length > 0 ? e.on([h], [
|
|
218
|
+
i.length > 0 ? e.on([h], [a], ...i, m) : e.on([h], [a], m);
|
|
219
219
|
}
|
|
220
220
|
n.children && q(
|
|
221
221
|
e,
|
|
222
222
|
n.children,
|
|
223
223
|
s,
|
|
224
|
-
|
|
224
|
+
a,
|
|
225
225
|
i
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
}, W = async (e) => {
|
|
229
229
|
const t = new R();
|
|
230
230
|
t.use(j()), process.env.NODE_ENV !== "production" && t.use("*", T());
|
|
231
|
-
const
|
|
232
|
-
for (const n of
|
|
231
|
+
const r = v().pendingRoutes.splice(0);
|
|
232
|
+
for (const n of r)
|
|
233
233
|
await n(t);
|
|
234
234
|
_(t, e), b(t, e), await H(t, e);
|
|
235
235
|
const o = V(e);
|
|
@@ -239,14 +239,14 @@ const N = (e, t, s) => {
|
|
|
239
239
|
}
|
|
240
240
|
return t;
|
|
241
241
|
}, ee = async (e) => {
|
|
242
|
-
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3,
|
|
242
|
+
const { routes: t } = e, s = Number(process.env.PORT) || e.port || 3e3, r = await W(t);
|
|
243
243
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
244
|
-
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join:
|
|
245
|
-
(process.env.STATIC_BASE_URL || "").startsWith("http") ||
|
|
246
|
-
const c = o({ fetch:
|
|
247
|
-
await y(
|
|
244
|
+
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: a } = await import("node:path"), i = a(process.cwd(), "dist/client");
|
|
245
|
+
(process.env.STATIC_BASE_URL || "").startsWith("http") || r.use("/*", n({ root: i })), console.log(`Server running on http://localhost:${s}`);
|
|
246
|
+
const c = o({ fetch: r.fetch, port: s });
|
|
247
|
+
await y(r, c), P(c);
|
|
248
248
|
}
|
|
249
|
-
return
|
|
249
|
+
return r;
|
|
250
250
|
};
|
|
251
251
|
export {
|
|
252
252
|
Z as addRoutes,
|
package/dist/static.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import i from "node:fs";
|
|
2
2
|
import a from "node:path";
|
|
3
|
-
async function
|
|
4
|
-
const
|
|
3
|
+
async function h(c, e = "") {
|
|
4
|
+
const o = [];
|
|
5
5
|
for (const t of c) {
|
|
6
|
-
|
|
6
|
+
if (t.path === "*") continue;
|
|
7
|
+
const n = t.module?.metadata?.fullPath ?? "";
|
|
7
8
|
if (t.children) {
|
|
8
|
-
const s = await
|
|
9
|
-
|
|
9
|
+
const s = await h(t.children, n);
|
|
10
|
+
o.push(...s);
|
|
10
11
|
} else if (t.module) {
|
|
11
12
|
const s = t.module.metadata?.fullPath;
|
|
12
13
|
if (!s) continue;
|
|
@@ -17,60 +18,71 @@ async function d(c, n = "") {
|
|
|
17
18
|
const l = t.module.staticPaths;
|
|
18
19
|
if (typeof l == "function") {
|
|
19
20
|
const u = await l();
|
|
20
|
-
for (const
|
|
21
|
+
for (const p of u) {
|
|
21
22
|
let f = s;
|
|
22
|
-
for (const [
|
|
23
|
-
f = f.replace(`:${
|
|
24
|
-
|
|
23
|
+
for (const [m, w] of Object.entries(p))
|
|
24
|
+
f = f.replace(`:${m}`, w);
|
|
25
|
+
o.push({ fullPath: f, module: t.module });
|
|
25
26
|
}
|
|
26
27
|
} else
|
|
27
28
|
console.warn(
|
|
28
29
|
`Skipping ${s} — dynamic route without staticPaths export`
|
|
29
30
|
);
|
|
30
31
|
} else
|
|
31
|
-
|
|
32
|
+
o.push({ fullPath: s, module: t.module });
|
|
32
33
|
} else
|
|
33
34
|
continue;
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return o;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
function d(c) {
|
|
39
|
+
for (const e of c)
|
|
40
|
+
if (e.path === "*" && e.module || e.children && d(e.children)) return !0;
|
|
41
|
+
return !1;
|
|
42
|
+
}
|
|
43
|
+
async function y(c, e, o) {
|
|
44
|
+
const t = "http://localhost", n = await c.fetch(new Request(`${t}${e}`));
|
|
45
|
+
if (n.status !== 200) {
|
|
46
|
+
console.warn(`Skipping ${e} — got status ${n.status}`);
|
|
41
47
|
return;
|
|
42
48
|
}
|
|
43
|
-
const s = await
|
|
44
|
-
new Request(`${t}${
|
|
45
|
-
)).text(), u =
|
|
49
|
+
const s = await n.text(), l = await (await c.fetch(
|
|
50
|
+
new Request(`${t}${e}?_data=1`)
|
|
51
|
+
)).text(), u = e === "/" ? o : a.join(o, e);
|
|
46
52
|
i.mkdirSync(u, { recursive: !0 }), i.writeFileSync(a.join(u, "index.html"), s), i.writeFileSync(a.join(u, "index.json"), l);
|
|
47
53
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
if (!i.existsSync(
|
|
51
|
-
const
|
|
54
|
+
function g(c) {
|
|
55
|
+
const e = a.resolve(process.cwd(), "public");
|
|
56
|
+
if (!i.existsSync(e)) return;
|
|
57
|
+
const o = (t, n) => {
|
|
52
58
|
if (i.statSync(t).isDirectory()) {
|
|
53
|
-
i.mkdirSync(
|
|
59
|
+
i.mkdirSync(n, { recursive: !0 });
|
|
54
60
|
for (const r of i.readdirSync(t))
|
|
55
|
-
|
|
61
|
+
o(a.join(t, r), a.join(n, r));
|
|
56
62
|
} else
|
|
57
|
-
i.copyFileSync(t,
|
|
63
|
+
i.copyFileSync(t, n);
|
|
58
64
|
};
|
|
59
|
-
e
|
|
65
|
+
o(e, c);
|
|
60
66
|
}
|
|
61
|
-
async function
|
|
62
|
-
const
|
|
67
|
+
async function R(c, e) {
|
|
68
|
+
const o = a.resolve(process.cwd(), "dist");
|
|
63
69
|
console.log("Generating static pages...");
|
|
64
|
-
const t = await
|
|
70
|
+
const t = await h(e);
|
|
65
71
|
if (t.length === 0) {
|
|
66
72
|
console.warn("No routes found for static generation.");
|
|
67
73
|
return;
|
|
68
74
|
}
|
|
69
|
-
for (const
|
|
70
|
-
await y(c,
|
|
71
|
-
|
|
75
|
+
for (const n of t)
|
|
76
|
+
await y(c, n.fullPath, o), console.log(` ✓ ${n.fullPath}`);
|
|
77
|
+
if (d(e)) {
|
|
78
|
+
const s = await (await c.fetch(
|
|
79
|
+
new Request("http://localhost/__velojs_not_found__")
|
|
80
|
+
)).text();
|
|
81
|
+
i.writeFileSync(a.join(o, "404.html"), s), console.log(" ✓ /404.html");
|
|
82
|
+
}
|
|
83
|
+
g(o), console.log(`
|
|
72
84
|
Generated ${t.length} static pages.`);
|
|
73
85
|
}
|
|
74
86
|
export {
|
|
75
|
-
|
|
87
|
+
R as generateStatic
|
|
76
88
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -39,5 +39,12 @@ export interface RouteNode {
|
|
|
39
39
|
children?: RouteNode[];
|
|
40
40
|
middlewares?: MiddlewareHandler[];
|
|
41
41
|
isRoot?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* HTTP status code for the rendered page (default 200). Lets a route
|
|
44
|
+
* respond with e.g. 404/410/503. The bare catch-all (`path: "*"`) defaults
|
|
45
|
+
* to 404 and is served via Hono's notFound hook. For conditional status
|
|
46
|
+
* (resource missing inside a valid route), call `c.status()` in the loader.
|
|
47
|
+
*/
|
|
48
|
+
statusCode?: number;
|
|
42
49
|
}
|
|
43
50
|
export type AppRoutes = RouteNode[];
|