@mauroandre/velojs 0.0.12 → 0.0.13
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/static.js +51 -38
- package/package.json +1 -1
package/dist/static.js
CHANGED
|
@@ -1,62 +1,75 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
async function h(
|
|
4
|
-
const
|
|
5
|
-
for (const t of
|
|
6
|
-
const
|
|
1
|
+
import i from "node:fs";
|
|
2
|
+
import a from "node:path";
|
|
3
|
+
async function h(c, n = "") {
|
|
4
|
+
const e = [];
|
|
5
|
+
for (const t of c) {
|
|
6
|
+
const o = t.module.metadata?.fullPath ?? "";
|
|
7
7
|
if (t.children) {
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const s = await h(t.children, o);
|
|
9
|
+
e.push(...s);
|
|
10
10
|
} else {
|
|
11
|
-
const
|
|
12
|
-
if (!
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
`⚠ Route ${
|
|
16
|
-
),
|
|
17
|
-
const
|
|
18
|
-
if (typeof
|
|
19
|
-
const
|
|
20
|
-
for (const d of
|
|
21
|
-
let
|
|
22
|
-
for (const [
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
const s = t.module.metadata?.fullPath;
|
|
12
|
+
if (!s) continue;
|
|
13
|
+
const r = Object.keys(t.module).filter((l) => l.startsWith("action_"));
|
|
14
|
+
if (r.length > 0 && console.warn(
|
|
15
|
+
`⚠ Route ${s} has actions (${r.join(", ")}) — they won't work in static mode`
|
|
16
|
+
), s.includes(":")) {
|
|
17
|
+
const l = t.module.staticPaths;
|
|
18
|
+
if (typeof l == "function") {
|
|
19
|
+
const u = await l();
|
|
20
|
+
for (const d of u) {
|
|
21
|
+
let f = s;
|
|
22
|
+
for (const [p, m] of Object.entries(d))
|
|
23
|
+
f = f.replace(`:${p}`, m);
|
|
24
|
+
e.push({ fullPath: f, module: t.module });
|
|
25
25
|
}
|
|
26
26
|
} else
|
|
27
27
|
console.warn(
|
|
28
|
-
`Skipping ${
|
|
28
|
+
`Skipping ${s} — dynamic route without staticPaths export`
|
|
29
29
|
);
|
|
30
30
|
} else
|
|
31
|
-
|
|
31
|
+
e.push({ fullPath: s, module: t.module });
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return e;
|
|
35
35
|
}
|
|
36
|
-
async function
|
|
37
|
-
const t = "http://localhost",
|
|
38
|
-
if (
|
|
39
|
-
console.warn(`Skipping ${n} — got status ${
|
|
36
|
+
async function y(c, n, e) {
|
|
37
|
+
const t = "http://localhost", o = await c.fetch(new Request(`${t}${n}`));
|
|
38
|
+
if (o.status !== 200) {
|
|
39
|
+
console.warn(`Skipping ${n} — got status ${o.status}`);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const
|
|
42
|
+
const s = await o.text(), l = await (await c.fetch(
|
|
43
43
|
new Request(`${t}${n}?_data=1`)
|
|
44
|
-
)).text(),
|
|
45
|
-
|
|
44
|
+
)).text(), u = n === "/" ? e : a.join(e, n);
|
|
45
|
+
i.mkdirSync(u, { recursive: !0 }), i.writeFileSync(a.join(u, "index.html"), s), i.writeFileSync(a.join(u, "index.json"), l);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
const
|
|
47
|
+
function w(c) {
|
|
48
|
+
const n = a.resolve(process.cwd(), "public");
|
|
49
|
+
if (!i.existsSync(n)) return;
|
|
50
|
+
const e = (t, o) => {
|
|
51
|
+
if (i.statSync(t).isDirectory()) {
|
|
52
|
+
i.mkdirSync(o, { recursive: !0 });
|
|
53
|
+
for (const r of i.readdirSync(t))
|
|
54
|
+
e(a.join(t, r), a.join(o, r));
|
|
55
|
+
} else
|
|
56
|
+
i.copyFileSync(t, o);
|
|
57
|
+
};
|
|
58
|
+
e(n, c);
|
|
59
|
+
}
|
|
60
|
+
async function j(c, n) {
|
|
61
|
+
const e = a.resolve(process.cwd(), "dist");
|
|
49
62
|
console.log("Generating static pages...");
|
|
50
63
|
const t = await h(n);
|
|
51
64
|
if (t.length === 0) {
|
|
52
65
|
console.warn("No routes found for static generation.");
|
|
53
66
|
return;
|
|
54
67
|
}
|
|
55
|
-
for (const
|
|
56
|
-
await
|
|
57
|
-
console.log(`
|
|
68
|
+
for (const o of t)
|
|
69
|
+
await y(c, o.fullPath, e), console.log(` ✓ ${o.fullPath}`);
|
|
70
|
+
w(e), console.log(`
|
|
58
71
|
Generated ${t.length} static pages.`);
|
|
59
72
|
}
|
|
60
73
|
export {
|
|
61
|
-
|
|
74
|
+
j as generateStatic
|
|
62
75
|
};
|