@velastack/patterns 0.3.4 → 0.4.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.
- package/README.md +44 -2
- package/dist/chunks/_layout-kkgN0IF7.js +62 -0
- package/dist/chunks/_layout-kkgN0IF7.js.map +1 -0
- package/dist/chunks/{collections-CrOvS2E7.js → collections-Dz2fvKnz.js} +2 -2
- package/dist/chunks/{collections-CrOvS2E7.js.map → collections-Dz2fvKnz.js.map} +1 -1
- package/dist/chunks/{compose-handle-B-CkDcQD.js → compose-handle-D_Rz3Fzo.js} +10 -4
- package/dist/chunks/compose-handle-D_Rz3Fzo.js.map +1 -0
- package/dist/chunks/{config-target-Bln26FJe.js → config-target-Dx3w6WSk.js} +59 -70
- package/dist/chunks/config-target-Dx3w6WSk.js.map +1 -0
- package/dist/chunks/constants-BjyMU5s8.js +6 -0
- package/dist/chunks/constants-BjyMU5s8.js.map +1 -0
- package/dist/chunks/dispatch-CXOXPLFk.js +6 -0
- package/dist/chunks/dispatch-CXOXPLFk.js.map +1 -0
- package/dist/chunks/env-vars-C1NUX-bf.js +268 -0
- package/dist/chunks/env-vars-C1NUX-bf.js.map +1 -0
- package/dist/chunks/env-vars-Cr4lbMD_.js +21 -0
- package/dist/chunks/env-vars-Cr4lbMD_.js.map +1 -0
- package/dist/chunks/env-vars-De0Xs0L2.js +20 -0
- package/dist/chunks/env-vars-De0Xs0L2.js.map +1 -0
- package/dist/chunks/env-vars-file-B_6esJW3.js +34 -0
- package/dist/chunks/env-vars-file-B_6esJW3.js.map +1 -0
- package/dist/chunks/env-vars-mnRA0hOe.js +19 -0
- package/dist/chunks/env-vars-mnRA0hOe.js.map +1 -0
- package/dist/chunks/generate-BW3l5Fxw.js +252 -0
- package/dist/chunks/{generate-Ca_6FlPi.js.map → generate-BW3l5Fxw.js.map} +1 -1
- package/dist/chunks/{generate-CyuY2Ci7.js → generate-DeaBlnK6.js} +25 -24
- package/dist/chunks/generate-DeaBlnK6.js.map +1 -0
- package/dist/chunks/generate-DetW_gbr.js +68 -0
- package/dist/chunks/generate-DetW_gbr.js.map +1 -0
- package/dist/chunks/{generate-DwADTUob.js → generate-Gcc8iRkZ.js} +9 -6
- package/dist/chunks/{generate-DwADTUob.js.map → generate-Gcc8iRkZ.js.map} +1 -1
- package/dist/chunks/{generate-DQeWOEPY.js → generate-WMJo3QGZ.js} +9 -6
- package/dist/chunks/generate-WMJo3QGZ.js.map +1 -0
- package/dist/chunks/generate.runtime-1-91UmM8.js +85 -0
- package/dist/chunks/generate.runtime-1-91UmM8.js.map +1 -0
- package/dist/chunks/generate.runtime-6FXJM8hT.js +67 -0
- package/dist/chunks/generate.runtime-6FXJM8hT.js.map +1 -0
- package/dist/chunks/generate.runtime-B1jVAnDI.js +155 -0
- package/dist/chunks/generate.runtime-B1jVAnDI.js.map +1 -0
- package/dist/chunks/generate.runtime-BA3tDKnn.js +147 -0
- package/dist/chunks/generate.runtime-BA3tDKnn.js.map +1 -0
- package/dist/chunks/{generate.runtime-4FDxnvCl.js → generate.runtime-BO778G0r.js} +5 -5
- package/dist/chunks/{generate.runtime-4FDxnvCl.js.map → generate.runtime-BO778G0r.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D1DNAY6k.js → generate.runtime-BXkZob1O.js} +8 -8
- package/dist/chunks/generate.runtime-BXkZob1O.js.map +1 -0
- package/dist/chunks/{generate.runtime-Um77JfwC.js → generate.runtime-B_UVGa3q.js} +7 -7
- package/dist/chunks/{generate.runtime-Um77JfwC.js.map → generate.runtime-B_UVGa3q.js.map} +1 -1
- package/dist/chunks/{generate.runtime-FdZw277n.js → generate.runtime-C6bSvGMb.js} +108 -142
- package/dist/chunks/generate.runtime-C6bSvGMb.js.map +1 -0
- package/dist/chunks/generate.runtime-C8zJRNYG.js +124 -0
- package/dist/chunks/generate.runtime-C8zJRNYG.js.map +1 -0
- package/dist/chunks/{generate.runtime-BKiJvE8I.js → generate.runtime-CA7Ofjlx.js} +104 -100
- package/dist/chunks/generate.runtime-CA7Ofjlx.js.map +1 -0
- package/dist/chunks/generate.runtime-CCr1lvo4.js +43 -0
- package/dist/chunks/generate.runtime-CCr1lvo4.js.map +1 -0
- package/dist/chunks/generate.runtime-CYagyR5c.js +326 -0
- package/dist/chunks/generate.runtime-CYagyR5c.js.map +1 -0
- package/dist/chunks/{generate.runtime-n9AFWtPp.js → generate.runtime-Ce_rwzNa.js} +4 -4
- package/dist/chunks/{generate.runtime-n9AFWtPp.js.map → generate.runtime-Ce_rwzNa.js.map} +1 -1
- package/dist/chunks/{generate.runtime-cQGLxuZM.js → generate.runtime-CexC1Oky.js} +4 -4
- package/dist/chunks/{generate.runtime-cQGLxuZM.js.map → generate.runtime-CexC1Oky.js.map} +1 -1
- package/dist/chunks/{generate.runtime-AYQVW1S-.js → generate.runtime-CnPraLKv.js} +35 -31
- package/dist/chunks/generate.runtime-CnPraLKv.js.map +1 -0
- package/dist/chunks/generate.runtime-CslAvllQ.js +112 -0
- package/dist/chunks/generate.runtime-CslAvllQ.js.map +1 -0
- package/dist/chunks/{generate.runtime-onBnOiS7.js → generate.runtime-CuNhY5hn.js} +10 -10
- package/dist/chunks/generate.runtime-CuNhY5hn.js.map +1 -0
- package/dist/chunks/{generate.runtime-B45MvtYm.js → generate.runtime-DD51OSuL.js} +14 -14
- package/dist/chunks/generate.runtime-DD51OSuL.js.map +1 -0
- package/dist/chunks/generate.runtime-DHBRyMAq.js +65 -0
- package/dist/chunks/generate.runtime-DHBRyMAq.js.map +1 -0
- package/dist/chunks/generate.runtime-DV3WmZtb.js +35 -0
- package/dist/chunks/generate.runtime-DV3WmZtb.js.map +1 -0
- package/dist/chunks/generate.runtime-D_sQOeQa.js +164 -0
- package/dist/chunks/generate.runtime-D_sQOeQa.js.map +1 -0
- package/dist/chunks/{generate.runtime-ofdnLtxS.js → generate.runtime-DqD3PW-W.js} +3 -3
- package/dist/chunks/{generate.runtime-ofdnLtxS.js.map → generate.runtime-DqD3PW-W.js.map} +1 -1
- package/dist/chunks/{generate.runtime-VgVwRiiN.js → generate.runtime-Dtgw9IQO.js} +8 -8
- package/dist/chunks/generate.runtime-Dtgw9IQO.js.map +1 -0
- package/dist/chunks/{generate.runtime-CN5c2xH8.js → generate.runtime-IlBCcXvv.js} +14 -14
- package/dist/chunks/generate.runtime-IlBCcXvv.js.map +1 -0
- package/dist/chunks/{generate.runtime-BSRFv4cJ.js → generate.runtime-cwvAoKoH.js} +3 -3
- package/dist/chunks/{generate.runtime-BSRFv4cJ.js.map → generate.runtime-cwvAoKoH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DG-3G00z.js → generate.runtime-kvxmTlQb.js} +3 -3
- package/dist/chunks/{generate.runtime-DG-3G00z.js.map → generate.runtime-kvxmTlQb.js.map} +1 -1
- package/dist/chunks/generate.runtime-pVLzzpUM.js +122 -0
- package/dist/chunks/generate.runtime-pVLzzpUM.js.map +1 -0
- package/dist/chunks/{generate.runtime-BFOXm2DD.js → generate.runtime-zJpEufTc.js} +10 -10
- package/dist/chunks/generate.runtime-zJpEufTc.js.map +1 -0
- package/dist/chunks/lib-specifier-Cngo1zF_.js +33 -0
- package/dist/chunks/lib-specifier-Cngo1zF_.js.map +1 -0
- package/dist/chunks/{modify-file-Dwfv0dCI.js → modify-file-BlDeeurK.js} +3 -3
- package/dist/chunks/{modify-file-Dwfv0dCI.js.map → modify-file-BlDeeurK.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-BUU_EaDf.js → modify-svelte-config-remote-p0TfVzxm.js} +8 -10
- package/dist/chunks/modify-svelte-config-remote-p0TfVzxm.js.map +1 -0
- package/dist/chunks/nav-user-BRIHOOpG.js +6 -0
- package/dist/chunks/nav-user-BRIHOOpG.js.map +1 -0
- package/dist/chunks/package-imports-Bbw3iMPg.js +173 -0
- package/dist/chunks/package-imports-Bbw3iMPg.js.map +1 -0
- package/dist/chunks/{pocketbase-BkhUywtb.js → pocketbase-Dry6ry17.js} +2 -2
- package/dist/chunks/{pocketbase-BkhUywtb.js.map → pocketbase-Dry6ry17.js.map} +1 -1
- package/dist/chunks/{providers-BL9vJP_9.js → providers-BHR6-XZ7.js} +11 -4
- package/dist/chunks/providers-BHR6-XZ7.js.map +1 -0
- package/dist/chunks/{shared-C8GtNxpm.js → shared-CZC4d7Uj.js} +2 -2
- package/dist/chunks/{shared-C8GtNxpm.js.map → shared-CZC4d7Uj.js.map} +1 -1
- package/dist/chunks/{site-BdMX8qrH.js → site-BwCA18Sv.js} +2 -2
- package/dist/chunks/{site-BdMX8qrH.js.map → site-BwCA18Sv.js.map} +1 -1
- package/dist/chunks/table-core-AjBpYi-y.js +127 -0
- package/dist/chunks/table-core-AjBpYi-y.js.map +1 -0
- package/dist/chunks/{test-setup-DHEFKEHE.js → test-setup-DEmWd9Ul.js} +76 -67
- package/dist/chunks/test-setup-DEmWd9Ul.js.map +1 -0
- package/dist/chunks/{ts-morph-helpers-CeduA--o.js → ts-morph-helpers-CDW4lhox.js} +77 -63
- package/dist/chunks/ts-morph-helpers-CDW4lhox.js.map +1 -0
- package/dist/chunks/ui-DD4NltyN.js.map +1 -1
- package/dist/chunks/{ui-TlEuI2Sz.js → ui-X698F10c.js} +47 -47
- package/dist/chunks/{ui-TlEuI2Sz.js.map → ui-X698F10c.js.map} +1 -1
- package/dist/chunks/{unmodify-load-jfdcVZ_a.js → unmodify-load-CyGzC1Hu.js} +2 -2
- package/dist/chunks/{unmodify-load-jfdcVZ_a.js.map → unmodify-load-CyGzC1Hu.js.map} +1 -1
- package/dist/chunks/write-result-B68lvI57.js +511 -0
- package/dist/chunks/write-result-B68lvI57.js.map +1 -0
- package/dist/index.d.ts +224 -1
- package/dist/index.js +2121 -2064
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/dist/chunks/_layout-B7ujvjnA.js +0 -55
- package/dist/chunks/_layout-B7ujvjnA.js.map +0 -1
- package/dist/chunks/compose-handle-B-CkDcQD.js.map +0 -1
- package/dist/chunks/config-target-Bln26FJe.js.map +0 -1
- package/dist/chunks/constants-BYkd9jeJ.js +0 -6
- package/dist/chunks/constants-BYkd9jeJ.js.map +0 -1
- package/dist/chunks/dispatch-BRnt8PcW.js +0 -6
- package/dist/chunks/dispatch-BRnt8PcW.js.map +0 -1
- package/dist/chunks/generate-6snrlnpA.js +0 -64
- package/dist/chunks/generate-6snrlnpA.js.map +0 -1
- package/dist/chunks/generate-Ca_6FlPi.js +0 -252
- package/dist/chunks/generate-CyuY2Ci7.js.map +0 -1
- package/dist/chunks/generate-DQeWOEPY.js.map +0 -1
- package/dist/chunks/generate.runtime-AYQVW1S-.js.map +0 -1
- package/dist/chunks/generate.runtime-B2aFFaac.js +0 -117
- package/dist/chunks/generate.runtime-B2aFFaac.js.map +0 -1
- package/dist/chunks/generate.runtime-B45MvtYm.js.map +0 -1
- package/dist/chunks/generate.runtime-BFOXm2DD.js.map +0 -1
- package/dist/chunks/generate.runtime-BHkFmI2Y.js +0 -146
- package/dist/chunks/generate.runtime-BHkFmI2Y.js.map +0 -1
- package/dist/chunks/generate.runtime-BKiJvE8I.js.map +0 -1
- package/dist/chunks/generate.runtime-BUqsF3AF.js +0 -123
- package/dist/chunks/generate.runtime-BUqsF3AF.js.map +0 -1
- package/dist/chunks/generate.runtime-BsaSyTnU.js +0 -82
- package/dist/chunks/generate.runtime-BsaSyTnU.js.map +0 -1
- package/dist/chunks/generate.runtime-CMnvmeVt.js +0 -111
- package/dist/chunks/generate.runtime-CMnvmeVt.js.map +0 -1
- package/dist/chunks/generate.runtime-CN5c2xH8.js.map +0 -1
- package/dist/chunks/generate.runtime-CgoSrP55.js +0 -146
- package/dist/chunks/generate.runtime-CgoSrP55.js.map +0 -1
- package/dist/chunks/generate.runtime-D1DNAY6k.js.map +0 -1
- package/dist/chunks/generate.runtime-DQwSY6Nc.js +0 -38
- package/dist/chunks/generate.runtime-DQwSY6Nc.js.map +0 -1
- package/dist/chunks/generate.runtime-D_yqWLcI.js +0 -66
- package/dist/chunks/generate.runtime-D_yqWLcI.js.map +0 -1
- package/dist/chunks/generate.runtime-Drmahmdl.js +0 -313
- package/dist/chunks/generate.runtime-Drmahmdl.js.map +0 -1
- package/dist/chunks/generate.runtime-FdZw277n.js.map +0 -1
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js +0 -94
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js.map +0 -1
- package/dist/chunks/generate.runtime-QGHToXRY.js +0 -32
- package/dist/chunks/generate.runtime-QGHToXRY.js.map +0 -1
- package/dist/chunks/generate.runtime-VgVwRiiN.js.map +0 -1
- package/dist/chunks/generate.runtime-YyIVd4oy.js +0 -61
- package/dist/chunks/generate.runtime-YyIVd4oy.js.map +0 -1
- package/dist/chunks/generate.runtime-onBnOiS7.js.map +0 -1
- package/dist/chunks/modify-svelte-config-remote-BUU_EaDf.js.map +0 -1
- package/dist/chunks/nav-user-BYI-h8Od.js +0 -6
- package/dist/chunks/nav-user-BYI-h8Od.js.map +0 -1
- package/dist/chunks/providers-BL9vJP_9.js.map +0 -1
- package/dist/chunks/table-core-G9Shld4F.js +0 -126
- package/dist/chunks/table-core-G9Shld4F.js.map +0 -1
- package/dist/chunks/test-setup-DHEFKEHE.js.map +0 -1
- package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +0 -1
- package/dist/chunks/write-result-Djy0SZXX.js +0 -376
- package/dist/chunks/write-result-Djy0SZXX.js.map +0 -1
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./errors-DR3gF_7a.js";
|
|
2
|
-
import { n as t, r as n } from "./util-BLYliuUK.js";
|
|
3
|
-
import { a as r, n as i, r as a } from "./providers-BL9vJP_9.js";
|
|
4
|
-
import { t as o } from "./ui-DD4NltyN.js";
|
|
5
|
-
import { c as s } from "./constants-BYkd9jeJ.js";
|
|
6
|
-
//#region node_modules/change-case/dist/index.js
|
|
7
|
-
var c = /([\p{Ll}\d])(\p{Lu})/gu, l = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu, u = /(\d)\p{Ll}|(\p{L})\d/u, d = /[^\p{L}\d]+/giu, f = "$1\0$2", p = "";
|
|
8
|
-
function m(e) {
|
|
9
|
-
let t = e.trim();
|
|
10
|
-
t = t.replace(c, f).replace(l, f), t = t.replace(d, "\0");
|
|
11
|
-
let n = 0, r = t.length;
|
|
12
|
-
for (; t.charAt(n) === "\0";) n++;
|
|
13
|
-
if (n === r) return [];
|
|
14
|
-
for (; t.charAt(r - 1) === "\0";) r--;
|
|
15
|
-
return t.slice(n, r).split(/\0/g);
|
|
16
|
-
}
|
|
17
|
-
function h(e) {
|
|
18
|
-
let t = m(e);
|
|
19
|
-
for (let e = 0; e < t.length; e++) {
|
|
20
|
-
let n = t[e], r = u.exec(n);
|
|
21
|
-
if (r) {
|
|
22
|
-
let i = r.index + (r[1] ?? r[2]).length;
|
|
23
|
-
t.splice(e, 1, n.slice(0, i), n.slice(i));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
}
|
|
28
|
-
function g(e, t) {
|
|
29
|
-
let [n, r, i] = E(e, t);
|
|
30
|
-
return n + r.map(S(t?.locale)).join(t?.delimiter ?? " ") + i;
|
|
31
|
-
}
|
|
32
|
-
function _(e, t) {
|
|
33
|
-
let [n, r, i] = E(e, t), a = S(t?.locale), o = C(t?.locale), s = t?.mergeAmbiguousCharacters ? w(a, o) : T(a, o);
|
|
34
|
-
return n + r.map((e, t) => t === 0 ? a(e) : s(e, t)).join(t?.delimiter ?? "") + i;
|
|
35
|
-
}
|
|
36
|
-
function v(e, t) {
|
|
37
|
-
let [n, r, i] = E(e, t), a = S(t?.locale), o = C(t?.locale), s = t?.mergeAmbiguousCharacters ? w(a, o) : T(a, o);
|
|
38
|
-
return n + r.map(s).join(t?.delimiter ?? "") + i;
|
|
39
|
-
}
|
|
40
|
-
function y(e, t) {
|
|
41
|
-
let [n, r, i] = E(e, t), a = S(t?.locale), o = C(t?.locale);
|
|
42
|
-
return n + r.map(w(a, o)).join(t?.delimiter ?? " ") + i;
|
|
43
|
-
}
|
|
44
|
-
function b(e, t) {
|
|
45
|
-
return g(e, {
|
|
46
|
-
delimiter: "-",
|
|
47
|
-
...t
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
function x(e, t) {
|
|
51
|
-
return g(e, {
|
|
52
|
-
delimiter: "_",
|
|
53
|
-
...t
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function S(e) {
|
|
57
|
-
return e === !1 ? (e) => e.toLowerCase() : (t) => t.toLocaleLowerCase(e);
|
|
58
|
-
}
|
|
59
|
-
function C(e) {
|
|
60
|
-
return e === !1 ? (e) => e.toUpperCase() : (t) => t.toLocaleUpperCase(e);
|
|
61
|
-
}
|
|
62
|
-
function w(e, t) {
|
|
63
|
-
return (n) => `${t(n[0])}${e(n.slice(1))}`;
|
|
64
|
-
}
|
|
65
|
-
function T(e, t) {
|
|
66
|
-
return (n, r) => {
|
|
67
|
-
let i = n[0];
|
|
68
|
-
return (r > 0 && i >= "0" && i <= "9" ? "_" + i : t(i)) + e(n.slice(1));
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function E(e, t = {}) {
|
|
72
|
-
let n = t.split ?? (t.separateNumbers ? h : m), r = t.prefixCharacters ?? p, i = t.suffixCharacters ?? p, a = 0, o = e.length;
|
|
73
|
-
for (; a < e.length;) {
|
|
74
|
-
let t = e.charAt(a);
|
|
75
|
-
if (!r.includes(t)) break;
|
|
76
|
-
a++;
|
|
77
|
-
}
|
|
78
|
-
for (; o > a;) {
|
|
79
|
-
let t = o - 1, n = e.charAt(t);
|
|
80
|
-
if (!i.includes(n)) break;
|
|
81
|
-
o = t;
|
|
82
|
-
}
|
|
83
|
-
return [
|
|
84
|
-
e.slice(0, a),
|
|
85
|
-
n(e.slice(a, o)),
|
|
86
|
-
e.slice(o)
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/parse/route.ts
|
|
91
|
-
var D = "src/routes", O = /\[([^\]]+)\]/g, ee = /^[a-zA-Z0-9_\-[\]()]+$/;
|
|
92
|
-
function k({ features: e, routeGroups: t }) {
|
|
93
|
-
let n = t ?? {
|
|
94
|
-
public: "(public)",
|
|
95
|
-
app: "(app)"
|
|
96
|
-
};
|
|
97
|
-
return e.auth ? n.app ?? n.public : n.public;
|
|
98
|
-
}
|
|
99
|
-
function A(e, t) {
|
|
100
|
-
return [
|
|
101
|
-
D,
|
|
102
|
-
e,
|
|
103
|
-
t
|
|
104
|
-
].filter(Boolean).join("/");
|
|
105
|
-
}
|
|
106
|
-
function j(e, t) {
|
|
107
|
-
return b(t === "scaffold" ? e.pluralDisplayName : e.displayName);
|
|
108
|
-
}
|
|
109
|
-
function M(e) {
|
|
110
|
-
return `/${(e.startsWith(`${D}/`) ? e.slice(11) : e).split("/").filter((e) => !(e.startsWith("(") && e.endsWith(")"))).join("/")}`;
|
|
111
|
-
}
|
|
112
|
-
function N(e) {
|
|
113
|
-
let t = [];
|
|
114
|
-
for (let n of e.matchAll(O)) t.push(n[1]);
|
|
115
|
-
return t;
|
|
116
|
-
}
|
|
117
|
-
function P(t) {
|
|
118
|
-
if (t.startsWith("/")) throw new e(`Route must not start with "/". Got: "${t}"`);
|
|
119
|
-
if (t.startsWith(`${D}/`) || t === D) throw new e(`Route must not start with "${D}/" — paths are rooted there automatically. Got: "${t}"`);
|
|
120
|
-
let n = t.split("/");
|
|
121
|
-
for (let r of n) {
|
|
122
|
-
if (r.length === 0) throw new e(`Route must not contain empty segments. Got: "${t}"`);
|
|
123
|
-
if (r === "." || r === "..") throw new e(`Route must not contain "." or ".." segments. Got: "${t}"`);
|
|
124
|
-
if (r.startsWith("_")) throw new e(`Route segments must not start with underscore. Got: "${r}"`);
|
|
125
|
-
if (!ee.test(r)) throw new e(`Route segment "${r}" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function F(e) {
|
|
129
|
-
return e.split("/").some((e) => e.startsWith("(") && e.endsWith(")"));
|
|
130
|
-
}
|
|
131
|
-
function I(e, t, n, r) {
|
|
132
|
-
if (e === void 0 || e === "") {
|
|
133
|
-
let e = j(t, r), i = A(k(n), e);
|
|
134
|
-
return {
|
|
135
|
-
fileBase: i,
|
|
136
|
-
urlBase: M(i),
|
|
137
|
-
dynamicParams: N(i)
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
P(e);
|
|
141
|
-
let i = A(F(e) ? null : k(n), e);
|
|
142
|
-
return {
|
|
143
|
-
fileBase: i,
|
|
144
|
-
urlBase: M(i),
|
|
145
|
-
dynamicParams: N(i)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function L(e) {
|
|
149
|
-
return {
|
|
150
|
-
list: e.fileBase,
|
|
151
|
-
new: `${e.fileBase}/new`,
|
|
152
|
-
show: `${e.fileBase}/[id]`,
|
|
153
|
-
edit: `${e.fileBase}/[id]/edit`
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function R(e) {
|
|
157
|
-
return {
|
|
158
|
-
list: e.urlBase,
|
|
159
|
-
new: `${e.urlBase}/new`,
|
|
160
|
-
show: `${e.urlBase}/[id]`,
|
|
161
|
-
edit: `${e.urlBase}/[id]/edit`
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/patterns/enable/ai/creates/src/routes/(public)/ai/+page.svelte?raw
|
|
166
|
-
var z = "<script lang=\"ts\">\n import { Chat } from '@ai-sdk/svelte';\n import { Button } from '$lib/components/ui/button';\n import { Textarea } from '$lib/components/ui/textarea';\n\n // Posts to /api/chat (src/routes/api/chat/+server.ts) and streams the reply\n // into `chat.messages`. This page is a demo, and it is yours to delete.\n const chat = new Chat({});\n\n let input = $state('');\n const busy = $derived(chat.status === 'submitted' || chat.status === 'streaming');\n\n function send(event: SubmitEvent) {\n event.preventDefault();\n const text = input.trim();\n if (!text || busy) return;\n chat.sendMessage({ text });\n input = '';\n }\n\n // Enter sends; Shift+Enter starts a new line.\n function onkeydown(event: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {\n if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {\n event.preventDefault();\n event.currentTarget.form?.requestSubmit();\n }\n }\n<\/script>\n\n<div class=\"mx-auto flex w-full max-w-3xl flex-1 flex-col gap-6 px-4 py-10\">\n <div>\n <h1 class=\"text-2xl font-semibold\">AI chat</h1>\n <p class=\"text-muted-foreground text-sm\">\n Replies stream from <code>src/routes/api/chat/+server.ts</code>. Pick the model in\n <code>src/lib/server/ai.ts</code>.\n </p>\n </div>\n\n <div class=\"flex flex-1 flex-col gap-4\" aria-live=\"polite\">\n {#each chat.messages as message (message.id)}\n <div\n class={message.role === 'user'\n ? 'bg-primary text-primary-foreground ml-auto max-w-[80%] rounded-lg px-4 py-2'\n : 'max-w-[80%]'}\n >\n {#each message.parts as part, index (index)}\n {#if part.type === 'text'}\n <p class=\"whitespace-pre-wrap\">{part.text}</p>\n {/if}\n {/each}\n </div>\n {:else}\n <p class=\"text-muted-foreground\">Ask anything to start the conversation.</p>\n {/each}\n\n {#if chat.status === 'submitted'}\n <p class=\"text-muted-foreground text-sm\">Thinking…</p>\n {/if}\n\n {#if chat.error}\n <div\n role=\"alert\"\n class=\"border-destructive text-destructive flex items-center justify-between gap-4 rounded-md border px-4 py-2 text-sm\"\n >\n <span>{chat.error.message}</span>\n <Button variant=\"outline\" size=\"sm\" onclick={() => chat.regenerate()}>Retry</Button>\n </div>\n {/if}\n </div>\n\n <form onsubmit={send} class=\"bg-background sticky bottom-0 flex items-end gap-2 py-2\">\n <Textarea\n bind:value={input}\n {onkeydown}\n rows={1}\n placeholder=\"Send a message\"\n aria-label=\"Message\"\n class=\"max-h-40 min-h-10 resize-none\"\n />\n {#if busy}\n <Button type=\"button\" variant=\"outline\" onclick={() => chat.stop()}>Stop</Button>\n {:else}\n <Button type=\"submit\" disabled={!input.trim()}>Send</Button>\n {/if}\n </form>\n</div>\n", B = "import { text } from '@sveltejs/kit';\nimport { dev } from '$app/environment';\nimport {\n convertToModelMessages,\n createUIMessageStreamResponse,\n safeValidateUIMessages,\n streamText,\n toUIMessageStream\n} from 'ai';\nimport { API_KEY, languageModel } from '$lib/server/ai';\nimport type { RequestHandler } from './$types';\n\n// Sent ahead of every conversation: give the assistant its role here.\nconst INSTRUCTIONS = 'You are a helpful assistant. Keep answers short unless asked for detail.';\n\n/**\n * Where `new Chat()` from @ai-sdk/svelte posts by default: the conversation so\n * far comes in, the model's reply streams back. Anyone who can reach the site\n * can call it, and every reply is billed to your API key, so put it behind\n * sign-in or a rate limit before you deploy.\n *\n * Errors are plain text, which `Chat` shows as `chat.error.message`.\n */\nexport const POST: RequestHandler = async ({ request }) => {\n const body = await request.json().catch(() => null);\n const messages = await safeValidateUIMessages({ messages: body?.messages });\n if (!messages.success) {\n return text('Expected a JSON body with a messages array.', { status: 400 });\n }\n\n const model = languageModel();\n if (!model) {\n return text(`Set ${API_KEY} in .env to start chatting.`, { status: 503 });\n }\n\n const result = streamText({\n model,\n instructions: INSTRUCTIONS,\n messages: await convertToModelMessages(messages.data)\n });\n\n return createUIMessageStreamResponse({\n stream: toUIMessageStream({\n stream: result.stream,\n // Provider errors (a bad key, an unknown model id) reach the chat in\n // dev only; in production they stay in the server log.\n onError: (error) =>\n dev && error instanceof Error ? error.message : 'The model could not answer.'\n })\n });\n};\n", V = "import { describe, it, expect } from 'vitest';\nimport type { Match } from '@velastack/kit';\nimport type { RouteId } from './$types';\n\n// None of these requests reach the model, so they pass without an API key and\n// cost nothing.\ndescribe('POST /api/chat', () => {\n it('should return 400 if the body is not JSON', async (context) => {\n const response = await context.request\n .post('/api/chat' satisfies Match<RouteId>)\n .set('Content-Type', 'application/json')\n .send('not json');\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are missing', async (context) => {\n const response = await context.request.post('/api/chat' satisfies Match<RouteId>).send({});\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are malformed', async (context) => {\n const response = await context.request\n .post('/api/chat' satisfies Match<RouteId>)\n .send({ messages: [{ role: 'user', content: 'Hello' }] });\n\n expect(response.status).toBe(400);\n });\n});\n", H = "import { text } from '@sveltejs/kit';\nimport { dev } from '$app/environment';\nimport {\n convertToModelMessages,\n createUIMessageStreamResponse,\n safeValidateUIMessages,\n streamText,\n toUIMessageStream\n} from 'ai';\nimport { API_KEY, languageModel } from '$lib/server/ai';\nimport type { RequestHandler } from './$types';\n\n// Sent ahead of every conversation: give the assistant its role here.\nconst INSTRUCTIONS = 'You are a helpful assistant. Keep answers short unless asked for detail.';\n\n/**\n * Where `new Chat()` from @ai-sdk/svelte posts by default: the conversation so\n * far comes in, the model's reply streams back. Every reply is billed to your\n * API key, so only signed-in users get one.\n *\n * Errors are plain text, which `Chat` shows as `chat.error.message`.\n */\nexport const POST: RequestHandler = async ({ request, locals }) => {\n if (!locals.pb.authStore.isValid) {\n return text('Sign in to chat.', { status: 401 });\n }\n\n const body = await request.json().catch(() => null);\n const messages = await safeValidateUIMessages({ messages: body?.messages });\n if (!messages.success) {\n return text('Expected a JSON body with a messages array.', { status: 400 });\n }\n\n const model = languageModel();\n if (!model) {\n return text(`Set ${API_KEY} in .env to start chatting.`, { status: 503 });\n }\n\n const result = streamText({\n model,\n instructions: INSTRUCTIONS,\n messages: await convertToModelMessages(messages.data)\n });\n\n return createUIMessageStreamResponse({\n stream: toUIMessageStream({\n stream: result.stream,\n // Provider errors (a bad key, an unknown model id) reach the chat in\n // dev only; in production they stay in the server log.\n onError: (error) =>\n dev && error instanceof Error ? error.message : 'The model could not answer.'\n })\n });\n};\n", U = "import { describe, it, expect } from 'vitest';\nimport type { Match } from '@velastack/kit';\nimport type { RouteId } from './$types';\n\n// None of these requests reach the model, so they pass without an API key and\n// cost nothing.\ndescribe('POST /api/chat', () => {\n it('should return 401 when signed out', async (context) => {\n const response = await context.request.post('/api/chat' satisfies Match<RouteId>).send({\n messages: [{ id: '1', role: 'user', parts: [{ type: 'text', text: 'Hello' }] }]\n });\n\n expect(response.status).toBe(401);\n });\n\n it('should return 400 if the body is not JSON', async (context) => {\n await context.agent.authenticateUser();\n\n const response = await context.agent\n .post('/api/chat' satisfies Match<RouteId>)\n .set('Content-Type', 'application/json')\n .send('not json');\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are missing', async (context) => {\n await context.agent.authenticateUser();\n\n const response = await context.agent.post('/api/chat' satisfies Match<RouteId>).send({});\n\n expect(response.status).toBe(400);\n });\n\n it('should return 400 if messages are malformed', async (context) => {\n await context.agent.authenticateUser();\n\n const response = await context.agent\n .post('/api/chat' satisfies Match<RouteId>)\n .send({ messages: [{ role: 'user', content: 'Hello' }] });\n\n expect(response.status).toBe(400);\n });\n});\n", W = "<script lang=\"ts\">\n import { Chat } from '@ai-sdk/svelte';\n\n // Posts to /api/chat (src/routes/api/chat/+server.ts) and streams the reply\n // into `chat.messages`. This page is a demo, and it is yours to delete.\n const chat = new Chat({});\n\n let input = $state('');\n const busy = $derived(chat.status === 'submitted' || chat.status === 'streaming');\n\n function send(event: SubmitEvent) {\n event.preventDefault();\n const text = input.trim();\n if (!text || busy) return;\n chat.sendMessage({ text });\n input = '';\n }\n\n // Enter sends; Shift+Enter starts a new line.\n function onkeydown(event: KeyboardEvent & { currentTarget: HTMLTextAreaElement }) {\n if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {\n event.preventDefault();\n event.currentTarget.form?.requestSubmit();\n }\n }\n<\/script>\n\n<h1>AI chat</h1>\n<p>\n Replies stream from <code>src/routes/api/chat/+server.ts</code>. Pick the model in\n <code>src/lib/server/ai.ts</code>.\n</p>\n\n<section aria-live=\"polite\">\n {#each chat.messages as message (message.id)}\n <article data-role={message.role}>\n <strong>{message.role === 'user' ? 'You' : 'Assistant'}</strong>\n {#each message.parts as part, index (index)}\n {#if part.type === 'text'}\n <p style=\"white-space: pre-wrap\">{part.text}</p>\n {/if}\n {/each}\n </article>\n {:else}\n <p>Ask anything to start the conversation.</p>\n {/each}\n\n {#if chat.status === 'submitted'}\n <p>Thinking…</p>\n {/if}\n\n {#if chat.error}\n <p role=\"alert\">\n {chat.error.message}\n <button type=\"button\" onclick={() => chat.regenerate()}>Retry</button>\n </p>\n {/if}\n</section>\n\n<form onsubmit={send}>\n <textarea bind:value={input} {onkeydown} rows=\"2\" placeholder=\"Send a message\" aria-label=\"Message\"\n ></textarea>\n {#if busy}\n <button type=\"button\" onclick={() => chat.stop()}>Stop</button>\n {:else}\n <button type=\"submit\" disabled={!input.trim()}>Send</button>\n {/if}\n</form>\n", G = "import { createAnthropic } from '@ai-sdk/anthropic';\nimport { env } from '$env/dynamic/private';\n\n/** The `.env` key holding the Anthropic API key. */\nexport const API_KEY = 'ANTHROPIC_API_KEY';\n\n/**\n * The model the AI routes talk to, or `undefined` while ANTHROPIC_API_KEY is\n * blank. The key is read on every call, so a new value in `.env` needs no code\n * change. Any id from https://docs.claude.com/en/docs/about-claude/models works\n * in place of this one.\n */\nexport function languageModel() {\n const apiKey = env[API_KEY];\n return apiKey ? createAnthropic({ apiKey })('claude-sonnet-5') : undefined;\n}\n", K = "import { createGateway } from 'ai';\nimport { env } from '$env/dynamic/private';\n\n/** The `.env` key holding the Vercel AI Gateway API key. */\nexport const API_KEY = 'AI_GATEWAY_API_KEY';\n\n/**\n * The model the AI routes talk to, or `undefined` while AI_GATEWAY_API_KEY is\n * blank. The key is read on every call, so a new value in `.env` needs no code\n * change. The gateway routes `creator/model` ids to their provider; any id from\n * https://vercel.com/ai-gateway/models works in place of this one.\n */\nexport function languageModel() {\n const apiKey = env[API_KEY];\n return apiKey ? createGateway({ apiKey })('anthropic/claude-sonnet-5') : undefined;\n}\n", q = "import { createOpenAI } from '@ai-sdk/openai';\nimport { env } from '$env/dynamic/private';\n\n/** The `.env` key holding the OpenAI API key. */\nexport const API_KEY = 'OPENAI_API_KEY';\n\n/**\n * The model the AI routes talk to, or `undefined` while OPENAI_API_KEY is\n * blank. The key is read on every call, so a new value in `.env` needs no code\n * change. Any id from https://platform.openai.com/docs/models works in place of\n * this one.\n */\nexport function languageModel() {\n const apiKey = env[API_KEY];\n return apiKey ? createOpenAI({ apiKey })('gpt-5.5') : undefined;\n}\n", J = [
|
|
167
|
-
{
|
|
168
|
-
id: "gateway",
|
|
169
|
-
label: "Vercel AI Gateway",
|
|
170
|
-
env: [{
|
|
171
|
-
key: "AI_GATEWAY_API_KEY",
|
|
172
|
-
label: "Vercel AI Gateway API key",
|
|
173
|
-
secret: !0
|
|
174
|
-
}]
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
id: "openai",
|
|
178
|
-
label: "OpenAI",
|
|
179
|
-
env: [{
|
|
180
|
-
key: "OPENAI_API_KEY",
|
|
181
|
-
label: "OpenAI API key",
|
|
182
|
-
placeholder: "sk-...",
|
|
183
|
-
secret: !0
|
|
184
|
-
}]
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
id: "anthropic",
|
|
188
|
-
label: "Anthropic",
|
|
189
|
-
env: [{
|
|
190
|
-
key: "ANTHROPIC_API_KEY",
|
|
191
|
-
label: "Anthropic API key",
|
|
192
|
-
placeholder: "sk-ant-...",
|
|
193
|
-
secret: !0
|
|
194
|
-
}]
|
|
195
|
-
}
|
|
196
|
-
], Y = ["ai@^7.0.107", "@ai-sdk/svelte@^5.0.107"], X = {
|
|
197
|
-
openai: ["@ai-sdk/openai@^4.0.71"],
|
|
198
|
-
anthropic: ["@ai-sdk/anthropic@^4.0.58"]
|
|
199
|
-
}, Z = {
|
|
200
|
-
slug: "enable-ai",
|
|
201
|
-
providers: J
|
|
202
|
-
}, Q = "src/routes/(public)/ai/";
|
|
203
|
-
function $(e) {
|
|
204
|
-
return [
|
|
205
|
-
"src/routes",
|
|
206
|
-
k(e),
|
|
207
|
-
"ai"
|
|
208
|
-
].filter(Boolean).join("/");
|
|
209
|
-
}
|
|
210
|
-
function te(e, t = {}) {
|
|
211
|
-
return a(e, `AI SDK (${e.label})`, t);
|
|
212
|
-
}
|
|
213
|
-
var ne = /* #__PURE__ */ Object.assign({
|
|
214
|
-
"./creates/src/routes/(public)/ai/+page.svelte": z,
|
|
215
|
-
"./creates/src/routes/api/chat/+server.ts": B,
|
|
216
|
-
"./creates/src/routes/api/chat/server.test.ts": V
|
|
217
|
-
}), re = /* #__PURE__ */ Object.assign({
|
|
218
|
-
"./creates-app-mode/src/routes/api/chat/+server.ts": H,
|
|
219
|
-
"./creates-app-mode/src/routes/api/chat/server.test.ts": U
|
|
220
|
-
}), ie = /* #__PURE__ */ Object.assign({ "./variants/plain/src/routes/(public)/ai/+page.svelte": W }), ae = /* #__PURE__ */ Object.assign({
|
|
221
|
-
"./providers/anthropic/src/lib/server/ai.ts": G,
|
|
222
|
-
"./providers/gateway/src/lib/server/ai.ts": K,
|
|
223
|
-
"./providers/openai/src/lib/server/ai.ts": q
|
|
224
|
-
});
|
|
225
|
-
async function oe(e) {
|
|
226
|
-
let a = r(Z, e), c = o(e), l = e.input.serverTests ?? !0, u = {}, d = (e) => {
|
|
227
|
-
for (let t of e) u[t.path] = t;
|
|
228
|
-
};
|
|
229
|
-
d(t(ne, "./creates/", ie, c === "plain" ? "plain" : void 0)), e.features.auth && d(Object.values(n(re, "./creates-app-mode/"))), d(i(ae, a.id));
|
|
230
|
-
let f = `${$(e)}/`;
|
|
231
|
-
return {
|
|
232
|
-
creates: Object.values(u).filter((e) => l || !e.path.endsWith("server.test.ts")).map((e) => e.path.startsWith("src/routes/(public)/ai/") ? {
|
|
233
|
-
...e,
|
|
234
|
-
path: f + e.path.slice(23)
|
|
235
|
-
} : e).sort((e, t) => e.path.localeCompare(t.path)),
|
|
236
|
-
modifies: [],
|
|
237
|
-
deletes: [],
|
|
238
|
-
components: c === "plain" ? [] : ["button", "textarea"],
|
|
239
|
-
packages: [
|
|
240
|
-
...Y,
|
|
241
|
-
s,
|
|
242
|
-
...X[a.id] ?? []
|
|
243
|
-
],
|
|
244
|
-
collections: [],
|
|
245
|
-
collectionPatches: [],
|
|
246
|
-
collectionDrops: []
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
//#endregion
|
|
250
|
-
export { v as C, b as S, I as _, X as a, _ as b, oe as c, G as d, U as f, z as g, B as h, J as i, q as l, V as m, Z as n, $ as o, H as p, Y as r, te as s, Q as t, K as u, L as v, x as w, y as x, R as y };
|
|
251
|
-
|
|
252
|
-
//# sourceMappingURL=generate-Ca_6FlPi.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-CyuY2Ci7.js","names":[],"sources":["../../src/patterns/enable/cms/generate.ts"],"sourcesContent":["import type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { filesFromGlob } from \"../../../core/util\";\n\n// The backend, for an app that hosts the CMS itself: the SQLite-backed HTTP\n// API and the two routes that mount it and serve uploads.\nconst backendRaw = import.meta.glob<string>(\"./creates-backend/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst BACKEND_PREFIX = \"./creates-backend/\";\n\n/** Where an app that hosts the backend itself mounts it. Also the admin bar's default. */\nexport const LOCAL_ENDPOINT = \"/api/cms\";\n\nexport const ENDPOINT_EXAMPLE =\n \"https://velastack.dev/v1/projects/<project>/cms\";\n\nexport interface CmsMode {\n /** What the read path and the admin bar talk to. */\n endpoint: string;\n /** Whether this app hosts the backend at `endpoint` itself. */\n local: boolean;\n}\n\n/** `--endpoint <url>` or `--endpoint=<url>`, for callers that hand flags through in argv. */\nfunction endpointFromArgv(argv: string[]): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--endpoint\") return argv[i + 1];\n if (arg.startsWith(\"--endpoint=\")) return arg.slice(\"--endpoint=\".length);\n }\n return undefined;\n}\n\n/**\n * Which of the two shapes to produce.\n *\n * An explicit `--endpoint` means a hosted CMS: the app only reads from it and\n * the admin bar signs in there, so no backend is installed. Without one, an\n * app with a server hosts the backend itself at `/api/cms`. A static site has\n * no server to host it, so there the endpoint is required.\n */\nexport function resolveMode(options: Options): CmsMode {\n const raw =\n typeof options.input.endpoint === \"string\"\n ? options.input.endpoint\n : endpointFromArgv(options.argv);\n const endpoint = raw?.trim().replace(/\\/+$/, \"\");\n\n if (endpoint) {\n if (!/^https?:\\/\\/\\S+$/.test(endpoint)) {\n throw new InvalidArgumentError(\n `--endpoint must be the absolute URL of a hosted CMS, like ${ENDPOINT_EXAMPLE}; got ${endpoint}`,\n );\n }\n return { endpoint, local: false };\n }\n\n // A PocketBase backend implies a Node server, but it is not the only way to\n // have one: a project on adapter-node alone can host the SQLite backend too.\n // The caller detects that and says so with `input.server`.\n if (!(options.input.server ?? options.features.backend)) {\n throw new InvalidArgumentError(\n \"This site has no server to host the CMS backend. \" +\n `Point it at a hosted CMS instead: vela enable cms --endpoint ${ENDPOINT_EXAMPLE}`,\n );\n }\n\n return { endpoint: LOCAL_ENDPOINT, local: true };\n}\n\n/** `$lib/cms.ts`: the read path, with the endpoint and locales bound. */\nfunction cmsLibSource(mode: CmsMode, i18n: boolean): string {\n const imports = [\n \"import { apiAdapter, createCms } from '@velastack/cms/server';\",\n ];\n if (i18n) imports.push(\"import { locales } from '$locales/data';\");\n\n const where = mode.local\n ? [\n \" * `/api/cms` is where `src/routes/api/cms/[...path]/+server.ts` mounts the\",\n \" * backend. It is also the admin bar's default, so the endpoint is named here\",\n \" * and nowhere else.\",\n ]\n : [\n \" * The CMS is hosted at this endpoint: the app reads published content from\",\n \" * it and the admin bar signs in there. The same URL is given to the `cms()`\",\n \" * plugin in vite.config.ts, which downloads media into the build.\",\n ];\n\n const which = i18n\n ? [\n \" * The locales are the site's own, from wuchale, so the CMS supports exactly\",\n \" * the languages the UI does; the first is the default that a missing\",\n \" * translation falls back to.\",\n ]\n : [\n \" * `locales` lists every locale the site supports; the first is the default\",\n \" * that a missing translation falls back to.\",\n ];\n\n return [\n ...imports,\n \"\",\n \"/**\",\n \" * The CMS read path, called from the root `+layout.server.ts`.\",\n \" *\",\n ...where,\n \" *\",\n ...which,\n \" */\",\n \"export const { load: loadCms, generateEntries } = createCms({\",\n `\\tadapter: apiAdapter({ endpoint: '${mode.endpoint}' }),`,\n `\\tlocales: ${i18n ? \"[...locales]\" : \"['en']\"}`,\n \"});\",\n \"\",\n ].join(\"\\n\");\n}\n\nexport async function generate(options: Options) {\n const mode = resolveMode(options);\n const creates: Record<string, File> = {};\n\n if (mode.local) {\n Object.assign(creates, filesFromGlob(backendRaw, BACKEND_PREFIX));\n }\n\n creates[\"src/lib/cms.ts\"] = {\n path: \"src/lib/cms.ts\",\n language: \"ts\",\n content: cmsLibSource(mode, options.features.i18n),\n status: \"success\",\n };\n\n const sortedCreates = Object.values(creates).sort((a, b) =>\n a.path.localeCompare(b.path),\n );\n\n // better-sqlite3 and marked are the package's optional peers, which npm\n // skips on install precisely because they are optional — so they have to be\n // named here. The backend needs the first; the root entry imports the\n // second statically, so <AdminBar /> cannot render without it.\n // 0.2.2 is the first release whose Vite plugin imports from the package\n // name rather than its own source tree; 0.2.1 breaks every consumer route.\n // 0.2.3 is the first whose shipped admin-bar.css declares its tokens on the\n // @scope root; before it the bar renders unstyled in every consumer.\n // The backend's cms.ts resolves its database with `dataPath` from\n // @velastack/kit, which a backend template has and a project on adapter-node\n // alone does not.\n const packages = mode.local\n ? [\"@velastack/cms@^0.2.3\", \"@velastack/kit\", \"better-sqlite3\", \"marked\"]\n : [\"@velastack/cms@^0.2.3\", \"marked\"];\n\n return {\n creates: sortedCreates,\n modifies: [],\n deletes: [],\n components: [],\n packages,\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;AAMA,IAAM,IAAa,uBAAA,OAAA;CAAA,2CAAA;CAAA,6DAAA;CAAA,8DAAA;AAIlB,CAAA,GAEK,IAAiB,sBAGV,IAAiB,YAEjB,IACX;AAUF,SAAS,EAAiB,GAAoC;CAC5D,KAAK,IAAI,IAAI,GAAG,IAAI,EAAK,QAAQ,KAAK;EACpC,IAAM,IAAM,EAAK;EACjB,IAAI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BO;EACL,SApBoB,OAAO,OAAO,CAAO,CAAC,CAAC,MAAM,GAAG,MACpD,EAAE,KAAK,cAAc,EAAE,IAAI,CAmBlB;EACT,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UATe,EAAK,QAClB;GAAC;GAAyB;GAAkB;GAAkB;EAAQ,IACtE,CAAC,yBAAyB,QAAQ;EAQpC,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-DQeWOEPY.js","names":[],"sources":["../../src/patterns/disable/analytics/generate.ts"],"sourcesContent":["import type { Options, Result } from \"../../../core/types\";\nimport type { EnvEdit } from \"../../../runtime/env\";\nimport { allProviderPaths } from \"../../../core/providers\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { envEditsFor, PROVIDERS } from \"../../enable/analytics/generate\";\n\nconst providersRaw = import.meta.glob<string>(\n \"../../enable/analytics/providers/**\",\n { query: \"?raw\", import: \"default\", eager: true },\n);\n\n/**\n * The `.env` lines every provider writes. The project only has one set, but\n * which one is not recorded anywhere, so all are removed; keys that are not\n * there are skipped.\n */\nexport function allEnvEdits(): EnvEdit[] {\n return PROVIDERS.flatMap((provider) => envEditsFor(provider));\n}\n\nexport async function generate(_options: Options) {\n return {\n creates: [],\n modifies: [],\n // Every provider's files: missing ones are skipped, and the emptied\n // components/analytics directory goes with them.\n deletes: allProviderPaths(providersRaw).map(toDeleteEntry),\n components: [],\n packages: [],\n // PostHog's SDK; the other providers load a script and install nothing.\n uninstalls: [\"posthog-js\"],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;AAMA,IAAM,IAAe,uBAAA,OAAA;CAAA,yFAAA;CAAA,gFAAA;CAAA,4FAAA;CAAA,0FAAA;AAGrB,CAAA;AAOA,SAAgB,IAAyB;CACvC,OAAO,EAAU,SAAS,MAAa,EAAY,CAAQ,CAAC;AAC9D;AAEA,eAAsB,EAAS,GAAmB;CAChD,OAAO;EACL,SAAS,CAAC;EACV,UAAU,CAAC;EAGX,SAAS,EAAiB,CAAY,CAAC,CAAC,IAAI,CAAa;EACzD,YAAY,CAAC;EACb,UAAU,CAAC;EAEX,YAAY,CAAC,YAAY;EACzB,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-AYQVW1S-.js","names":[],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit';\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"$lib/server/workflows\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,IAAe,CAAM;;;GAKrB,IAAe,CAAM;;;;;;;;;GAWrB,IAAiB,CAAM;;;;;;;;AAS7B,SAAS,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAM,IAAW,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,CAAe;CAC9D,IAAI,CAAC,GAAU;EACb,EAAW,qBAAqB;GAC9B,YAAY;GACZ,cAAc,CAAC,CAAI;GACnB;EACF,CAAC;EACD;CACF;CACI,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAO,EAAG,QAAQ,MAAM,CAAI,KAGjE,EAAS,eACP,KAAY,CAAC,EAAS,WAAW,IAAI;EAAE;EAAM,YAAY;CAAK,IAAI,CACpE;AACF;AAEA,SAAS,EAAc,GAAiC;CAGtD,OAFI,EAAW,uBAAuB,MAAM,KACxC,EAAW,YAAY,MAAM,IAAU,KACpC,EACJ,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,gBAAgB,CAAC,CAAC,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM,CAAC;AACxE;AAMA,SAAgB,EACd,GACe;CACf,IAAI,CAAC,EAAG,WAAW,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAIxD,IADiB,EAAG,aAAa,GAAiB,MAC9C,CAAA,CAAS,SAAS,aAAa,GACjC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAO7C,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAe;CAc9D,OAZI,EAAc,CAAU,IACnB;EAAE,QAAQ;EAAU,SAAS;CAAa,KAGnD,EAAkB,GAAY,iBAAiB,cAAc,EAAI,GACjE,EAAkB,GAAY,yBAAyB,aAAa,GAGpE,EAAW,cAAc,KAAK,GAAc,GAE5C,EAAiB,CAAU,GAC3B,EAAW,SAAS,GACb;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;AC7FA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAmB,CAAC;CAE1B,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAkB,EAAK,KAAK,EAAQ,MAAM,OAAO,iBAAiB,GAClE,IAAY,EAChB,GACA,EAA2B,CAAe,CAC5C;CAGA,OAFI,KAAW,EAAS,KAAK,CAAS,GAE/B;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { t } from "./shared-C8GtNxpm.js";
|
|
3
|
-
import { n } from "./env-BPfk1VAw.js";
|
|
4
|
-
import { f as r, o as i } from "./ts-morph-helpers-CeduA--o.js";
|
|
5
|
-
import { modifyOutcomeToFile as a } from "./modify-file-Dwfv0dCI.js";
|
|
6
|
-
import { t as o } from "./svelte-file-B3RfgVdt.js";
|
|
7
|
-
import s from "node:fs";
|
|
8
|
-
import c from "node:path";
|
|
9
|
-
import { Project as l, QuoteKind as u, SyntaxKind as d } from "ts-morph";
|
|
10
|
-
//#region src/patterns/disable/payments/modifies/modify-nav-user.ts
|
|
11
|
-
function f(e) {
|
|
12
|
-
if (!s.existsSync(e)) return {
|
|
13
|
-
status: "success",
|
|
14
|
-
changed: !1
|
|
15
|
-
};
|
|
16
|
-
let t = s.readFileSync(e, "utf8");
|
|
17
|
-
if (!t.includes("/billing")) return {
|
|
18
|
-
status: "success",
|
|
19
|
-
changed: !1
|
|
20
|
-
};
|
|
21
|
-
let n = new o(t), i = !1, a = (e) => {
|
|
22
|
-
i || e((e) => {
|
|
23
|
-
let t = r(e, "Billing", "@lucide/svelte/icons/credit-card");
|
|
24
|
-
return t.wasRemoved && (i = !0), t.source;
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
return a((e) => n.modifyModuleScript(e)), i || a((e) => n.modifyScript(e)), i ? (s.writeFileSync(e, n.toString(), "utf8"), {
|
|
28
|
-
status: "success",
|
|
29
|
-
changed: !0
|
|
30
|
-
}) : {
|
|
31
|
-
status: "success",
|
|
32
|
-
changed: !1
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/patterns/disable/payments/modifies/modify-user-signup.ts
|
|
37
|
-
var p = /* @__PURE__ */ new Set(["linkStripeCustomer.run", "linkStripeCustomer"]);
|
|
38
|
-
function m(e) {
|
|
39
|
-
if (!s.existsSync(e)) return {
|
|
40
|
-
status: "success",
|
|
41
|
-
changed: !1
|
|
42
|
-
};
|
|
43
|
-
let t = s.readFileSync(e, "utf8");
|
|
44
|
-
if (!t.includes("linkStripeCustomer")) return {
|
|
45
|
-
status: "success",
|
|
46
|
-
changed: !1
|
|
47
|
-
};
|
|
48
|
-
let n = new l({ manipulationSettings: { quoteKind: u.Single } }).addSourceFileAtPath(e);
|
|
49
|
-
for (let e of ["$lib/workflows/link-stripe-customer", "$lib/stripe"]) {
|
|
50
|
-
let t = n.getImportDeclarations().find((t) => t.getModuleSpecifierValue() === e);
|
|
51
|
-
t && t.remove();
|
|
52
|
-
}
|
|
53
|
-
let r = n.getVariableStatement((e) => e.getDeclarations().some((e) => e.getName() === "linkStripeCustomer"));
|
|
54
|
-
r && r.remove();
|
|
55
|
-
let a = n.getDescendantsOfKind(d.CallExpression).filter((e) => p.has(e.getExpression().getText()));
|
|
56
|
-
for (let e of a) {
|
|
57
|
-
let t = e.getFirstAncestorByKind(d.ExpressionStatement);
|
|
58
|
-
t && t.remove();
|
|
59
|
-
}
|
|
60
|
-
return i(n), n.saveSync(), {
|
|
61
|
-
status: "success",
|
|
62
|
-
changed: n.getFullText() !== t
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/patterns/disable/payments/generate.runtime.ts
|
|
67
|
-
async function h(r) {
|
|
68
|
-
let i = r.features.auth, o = e(r), s = [], l = (e) => {
|
|
69
|
-
e && s.push(e);
|
|
70
|
-
};
|
|
71
|
-
o.info("Stripping Stripe credentials from .env");
|
|
72
|
-
let u = [
|
|
73
|
-
{
|
|
74
|
-
type: "comment",
|
|
75
|
-
key: "Stripe credentials"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
type: "var",
|
|
79
|
-
key: "STRIPE_SECRET_KEY"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
type: "var",
|
|
83
|
-
key: "PUBLIC_STRIPE_PUBLISHABLE_KEY"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: "var",
|
|
87
|
-
key: "STRIPE_WEBHOOK_SECRET"
|
|
88
|
-
}
|
|
89
|
-
], d = c.join(r.root, ".env");
|
|
90
|
-
if (l(a(d, n(d, u))), i) {
|
|
91
|
-
o.info("Reverting nav-user.svelte");
|
|
92
|
-
let e = c.join(r.root, "src", "lib", "components", "nav-user.svelte");
|
|
93
|
-
l(a(e, f(e))), o.info("Reverting signup +page.server.ts");
|
|
94
|
-
let t = c.join(r.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
|
|
95
|
-
l(a(t, m(t)));
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
creates: [],
|
|
99
|
-
modifies: s,
|
|
100
|
-
deletes: [],
|
|
101
|
-
components: [],
|
|
102
|
-
packages: [],
|
|
103
|
-
collections: [],
|
|
104
|
-
collectionPatches: [],
|
|
105
|
-
collectionDrops: await t(i ? [
|
|
106
|
-
"transactions",
|
|
107
|
-
"stripe_customers",
|
|
108
|
-
"stripe_payment_methods",
|
|
109
|
-
"stripe_prices",
|
|
110
|
-
"stripe_products"
|
|
111
|
-
] : ["stripe_prices", "stripe_products"], r)
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
export { h as generate };
|
|
116
|
-
|
|
117
|
-
//# sourceMappingURL=generate.runtime-B2aFFaac.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-B2aFFaac.js","names":[],"sources":["../../src/patterns/disable/payments/modifies/modify-nav-user.ts","../../src/patterns/disable/payments/modifies/modify-user-signup.ts","../../src/patterns/disable/payments/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/billing\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Billing\",\n \"@lucide/svelte/icons/credit-card\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst CALL_EXPRESSIONS = new Set([\n \"linkStripeCustomer.run\",\n // Projects from before the workflow: an inline helper called directly.\n \"linkStripeCustomer\",\n]);\n\nexport function unmodifyUserSignup(userSignupPath: string): ModifyOutcome {\n if (!fs.existsSync(userSignupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(userSignupPath, \"utf8\");\n if (!originalSource.includes(\"linkStripeCustomer\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n for (const specifier of [\n \"$lib/workflows/link-stripe-customer\",\n \"$lib/stripe\",\n ]) {\n const decl = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === specifier);\n if (decl) decl.remove();\n }\n\n const linkFn = sourceFile.getVariableStatement((s) =>\n s.getDeclarations().some((d) => d.getName() === \"linkStripeCustomer\"),\n );\n if (linkFn) linkFn.remove();\n\n const callStatements = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => CALL_EXPRESSIONS.has(ce.getExpression().getText()));\n for (const call of callStatements) {\n const stmt = call.getFirstAncestorByKind(SyntaxKind.ExpressionStatement);\n if (stmt) stmt.remove();\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnvRemove, type EnvEdit } from \"../../../runtime/env\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyUserSignup } from \"./modifies/modify-user-signup\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const isAppMode = options.features.auth;\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Stripping Stripe credentials from .env\");\n const envEdits: EnvEdit[] = [\n { type: \"comment\", key: \"Stripe credentials\" },\n { type: \"var\", key: \"STRIPE_SECRET_KEY\" },\n { type: \"var\", key: \"PUBLIC_STRIPE_PUBLISHABLE_KEY\" },\n { type: \"var\", key: \"STRIPE_WEBHOOK_SECRET\" },\n ];\n const envPath = path.join(options.root, \".env\");\n pushResult(modifyOutcomeToFile(envPath, modifyEnvRemove(envPath, envEdits)));\n\n if (isAppMode) {\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"(auth)\",\n \"signup\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(userSignupPath, unmodifyUserSignup(userSignupPath)),\n );\n }\n\n const collectionNames = [\n \"transactions\",\n \"stripe_customers\",\n \"stripe_payment_methods\",\n \"stripe_prices\",\n \"stripe_products\",\n ];\n const collectionDrops = await planDropsForCollections(\n isAppMode ? collectionNames : [\"stripe_prices\", \"stripe_products\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAKA,SAAgB,EAAgB,GAAoC;CAClE,IAAI,CAAC,EAAG,WAAW,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAS,EAAG,aAAa,GAAa,MAAM;CAClD,IAAI,CAAC,EAAO,SAAS,UAAU,GAC7B,O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Ab4B,EAC5B,IAAY;GAPZ;GACA;GACA;GACA;GACA;EAGY,IAAkB,CAAC,iBAAiB,iBAAiB,GACjE,CACF;CAWA;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-B45MvtYm.js","names":[],"sources":["../../src/patterns/enable/content-negotiation/modifies/hooks.server.ts","../../src/patterns/enable/content-negotiation/modifies/hooks.ts","../../src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts","../../src/patterns/enable/content-negotiation/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the negotiation handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = sequence(handleNegotiate, /* your existing handle */);\n`;\n\nconst HOOKS_SERVER_SNIPPET = dedent`\n import { handle as handleNegotiate } from '$lib/negotiate';\n\n export const handle = handleNegotiate;\n`;\n\nfunction ensureNegotiateHandleImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"handle\" &&\n ni.getAliasNode()?.getText() === \"handleNegotiate\"\n );\n });\n if (!has)\n existing.addNamedImport({ name: \"handle\", alias: \"handleNegotiate\" });\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"handle\", alias: \"handleNegotiate\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksServerNegotiate(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"handleNegotiate\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const composed = addHandle(sourceFile, { expression: \"handleNegotiate\" });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNegotiateHandleImport(sourceFile);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst NEGOTIATE_ONLY_SNIPPET = dedent`\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => negotiateReroute(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the negotiation reroute:\n\n import { reroute as negotiateReroute } from '$lib/negotiate';\n\n export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));\n`;\n\nfunction ensureNegotiateImport(sourceFile: SourceFile) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === \"$lib/negotiate\");\n if (existing) {\n const has = existing.getNamedImports().some((ni) => {\n return (\n ni.getName() === \"reroute\" &&\n ni.getAliasNode()?.getText() === \"negotiateReroute\"\n );\n });\n if (!has) {\n existing.addNamedImport({ name: \"reroute\", alias: \"negotiateReroute\" });\n }\n return;\n }\n sourceFile.addImportDeclaration({\n namedImports: [{ name: \"reroute\", alias: \"negotiateReroute\" }],\n moduleSpecifier: \"$lib/negotiate\",\n });\n}\n\nexport function modifyHooksNegotiate(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, NEGOTIATE_ONLY_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"negotiateReroute\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n ensureNegotiateImport(sourceFile);\n sourceFile.addStatements(\n `\\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const hasI18nHelper = sourceFile\n .getVariableDeclarations()\n .some((d) => d.getName() === \"rerouteDeLocalize\");\n const initText = init.getText();\n\n if (hasI18nHelper && initText.includes(\"rerouteDeLocalize\")) {\n ensureNegotiateImport(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n return { status: \"failed\", message: FAILURE_HINT };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { Negotiate } from '$lib/negotiate';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<Negotiate />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root +layout.svelte and mount <Negotiate /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nexport function modifyRootLayoutNegotiate(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"Negotiate\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"Negotiate\"],\n moduleSpecifier: \"$lib/negotiate\",\n },\n ]);\n });\n return out;\n });\n\n file.appendMarkup(MARKUP_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerNegotiate } from \"./modifies/hooks.server\";\nimport { modifyHooksNegotiate } from \"./modifies/hooks\";\nimport { modifyRootLayoutNegotiate } from \"./modifies/root-layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerNegotiate(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksNegotiate(hooksPath)));\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const rootLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutNegotiate(rootLayoutPath),\n ),\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAQA,IAAM,IAAe,CAAM;;;;;;;GASrB,IAAuB,CAAM;;;;;AAMnC,SAAS,EAA4B,GAAwB;CAC3D,IAAM,IAAW,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,gBAAgB;CAC/D,IAAI,GAAU;EAOZ,AANY,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAEzC,EAAG,QAAQ,MAAM,YACjB,EAAG,aAAa,CAAC,EAAE,QAAQ,MAAM,iBAGhC,KACH,EAAS,eAAe;GAAE,MAAM;GAAU,OAAO;EAAkB,CAAC;EACtE;CACF;CACA,EAAW,qBAAqB;EAC9B,cAAc,CAAC;GAAE,MAAM;GAAU,OAAO;EAAkB,CAAC;EAC3D,iBAAiB;CACnB,CAAC;AACH;AAEA,SAAgB,EACd,GACe;CACf,IAAI,CAAC,EAAG,WAAW,CAAe,GAQhC,OALI,EAAG,WAAW,EAAgB,QAAQ,SAAS,KAAK,CAAC,IAChD;EAAE,QAAQ;E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,"file":"generate.runtime-BFOXm2DD.js","names":[],"sources":["../../src/patterns/enable/auth/modifies/+layout.server.ts","../../src/patterns/enable/auth/modifies/root-layout.svelte.ts","../../src/patterns/enable/auth/modifies/hooks.server.ts","../../src/patterns/enable/auth/modifies/sidebar-menu-button.svelte.ts","../../src/patterns/enable/auth/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport function modifyLayoutServer(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n const snippet = dedent`\n\t\t\texport const load = async ({ locals }) => {\n\t\t\t\treturn { user: locals.pb.authStore.record };\n\t\t\t};\n\t\t`;\n\n fs.writeFileSync(layoutPath, snippet);\n return { status: \"success\", changed: true };\n }\n\n const originalSource = fs.readFileSync(layoutPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n // helper to add user property to an object literal if missing\n const addUserProp = (obj: import(\"ts-morph\").ObjectLiteralExpression) => {\n const hasUser = !!obj.getProperty(\"user\");\n if (!hasUser) {\n obj.addPropertyAssignment({\n name: \"user\",\n initializer: \"locals.pb.authStore.record\",\n });\n }\n };\n\n // find existing exported load (function or const with arrow)\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n const isExported = !!vs?.hasExportKeyword();\n if (isExported) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) {\n loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n }\n\n if (!loadArrow) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) {\n loadFn = maybeFn;\n }\n }\n\n // if no load found, create one\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals }\" }],\n statements: `return { user: locals.pb.authStore.record };`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // normalize function-like to a single handle\n const fnLike:\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression = (loadArrow ?? loadFn!) as any;\n\n // ensure first parameter destructures locals, preserving existing information\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const hasLocals = obp\n .getElements()\n .some((el) => el.getName() === \"locals\");\n if (!hasLocals) {\n const parts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const tail = parts.length > 0 ? \", \" + parts.join(\", \") : \"\";\n first.set({\n name: `{ locals${tail} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, ...${currentName} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n }\n }\n\n // add user to returned object literals without altering other properties\n if (loadArrow) {\n const body = loadArrow.getBody();\n if (body.getKind() === SyntaxKind.Block) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n } else {\n // concise body\n const bodyExpr = body as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(bodyExpr as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n } else if (loadFn) {\n const body = loadFn.getBody();\n if (body) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n ensurePropsBinding,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst AUTH_MENU_NAVBAR_ITEM = `\n\t\t<Navbar.Item\n\t\t\tclass=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n\t\t>\n\t\t\t<AuthMenu.Root>\n\t\t\t\t{#snippet user()}\n\t\t\t\t\t<AuthMenu.Trigger>\n\t\t\t\t\t\t<Avatar.Root>\n\t\t\t\t\t\t\t{#if data.user?.avatar}\n\t\t\t\t\t\t\t\t<Avatar.Image\n\t\t\t\t\t\t\t\t\tsrc=\"/api/files/users/{data.user?.id}/{data.user?.avatar}\"\n\t\t\t\t\t\t\t\t\talt={data.user?.email}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t\t<Avatar.Fallback>\n\t\t\t\t\t\t\t\t{data.user?.email?.charAt(0).toUpperCase()}\n\t\t\t\t\t\t\t</Avatar.Fallback>\n\t\t\t\t\t\t</Avatar.Root>\n\t\t\t\t\t</AuthMenu.Trigger>\n\n\t\t\t\t\t<AuthMenu.Content align=\"end\">\n\t\t\t\t\t\t<AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n\t\t\t\t\t\t<AuthMenu.Group>\n\t\t\t\t\t\t\t<AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n\t\t\t\t\t\t\t<AuthMenu.Item>\n\t\t\t\t\t\t\t\t<form action=\"/logout\" method=\"post\">\n\t\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"contents\">Logout</button>\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t</AuthMenu.Item>\n\t\t\t\t\t\t</AuthMenu.Group>\n\t\t\t\t\t</AuthMenu.Content>\n\t\t\t\t{/snippet}\n\n\t\t\t\t{#snippet guest()}\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\thref=\"/login\">Login</Button\n\t\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\t\thref=\"/signup\">Sign up</Button\n\t\t\t\t\t>\n\t\t\t\t{/snippet}\n\t\t\t</AuthMenu.Root>\n\t\t</Navbar.Item>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import * as AuthMenu from '$lib/components/ui/auth-menu';\n import * as Avatar from '$lib/components/ui/avatar';\n`;\n\nconst FAILURE_HINT = [\n \"Add the auth menu inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes an auth menu inside <Navbar.List>.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\n\");\n\nexport function modifyRootLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"AuthMenu.Root\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namespaceImport: \"AuthMenu\",\n moduleSpecifier: \"$lib/components/ui/auth-menu\",\n },\n {\n namespaceImport: \"Avatar\",\n moduleSpecifier: \"$lib/components/ui/avatar\",\n },\n ]);\n // The menu reads `data.user`; the template's layout takes no props.\n ensurePropsBinding(sf, \"data\");\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", AUTH_MENU_NAVBAR_ITEM);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with the auth option in hooks.server.ts:\n\n handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Find the handlePocketbase(...) call\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(`{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(0, `{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n // Ensure auth property exists\n const authProp = optionsObj.getProperty(\"auth\");\n if (!authProp) {\n optionsObj.addPropertyAssignment({\n name: \"auth\",\n initializer: `{ protectedRoutes: ['/(app)'] }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // If auth exists, ensure protectedRoutes includes '/(app)'\n if (authProp.getKind() === SyntaxKind.PropertyAssignment) {\n const authInit = (\n authProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (authInit && authInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const authObj = authInit as import(\"ts-morph\").ObjectLiteralExpression;\n const prProp = authObj.getProperty(\"protectedRoutes\");\n if (!prProp) {\n authObj.addPropertyAssignment({\n name: \"protectedRoutes\",\n initializer: `['/(app)']`,\n });\n } else if (prProp.getKind() === SyntaxKind.PropertyAssignment) {\n const prInit = (\n prProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (prInit && prInit.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = prInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasApp = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \"/(app)\");\n if (!hasApp) {\n arr.addElement(`'/(app)'`);\n }\n } else {\n (prProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `['/(app)']`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst VARIANTS = [\n {\n from: \"'data-active': isActive,\",\n to: \"'data-active': isActive ? true : undefined,\",\n },\n {\n from: '\"data-active\": isActive,',\n to: '\"data-active\": isActive ? true : undefined,',\n },\n];\n\nconst NOT_FOUND_HINT = dedent`\n The shadcn-svelte sidebar component was not installed at the expected path.\n Run: vela enable auth (or install the 'sidebar' shadcn-svelte component).\n`;\n\nexport function modifySidebarMenuButton(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n\n if (VARIANTS.some(({ to }) => original.includes(to))) {\n return { status: \"success\", changed: false };\n }\n\n const variant = VARIANTS.find(({ from }) => original.includes(from));\n if (!variant) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(variant.from, variant.to);\n fs.writeFileSync(filePath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { Options, Result, File } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { ensureSiteFile } from \"../../../runtime/site\";\n\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifySidebarMenuButton } from \"./modifies/sidebar-menu-button.svelte\";\n\nexport async function generate(options: Options) {\n const { input } = options;\n const logger = getLogger(options);\n\n let creates: File[] = [];\n\n // Update PocketBase\n await withPocketbase(options.root, async (pb) => {\n logger.info(\"Updating PocketBase mail settings\");\n await pb.settings.update({\n meta: {\n senderName: input.senderName,\n senderAddress: input.senderAddress,\n },\n });\n await migrationDelay();\n\n const userCollection = await pb.collections.getOne(\"users\");\n\n if (!userCollection) {\n throw new Error(\"Users collection not found\");\n }\n\n const verificationTemplate =\n userCollection.verificationTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\",\n \"{APP_URL}/confirm-verification/{TOKEN}\",\n );\n const resetPasswordTemplate =\n userCollection.resetPasswordTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-reset/{TOKEN}\",\n \"{APP_URL}/confirm-reset/{TOKEN}\",\n );\n const confirmEmailChangeTemplate =\n userCollection.confirmEmailChangeTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\",\n \"{APP_URL}/confirm-email-change/{TOKEN}\",\n );\n\n logger.info(\"Locking down users collection rules and email templates\");\n // Update user auth rules to lock down access to the user's own account\n await pb.collections.update(\"users\", {\n listRule: \"@request.auth.id = id\",\n viewRule: \"@request.auth.id = id\",\n createRule: \"@request.auth.id = id\",\n updateRule: \"@request.auth.id = id\",\n deleteRule: \"@request.auth.id = id\",\n\n // Update email templates to VelaStack auth urls\n verificationTemplate: {\n body: verificationTemplate,\n },\n resetPasswordTemplate: {\n body: resetPasswordTemplate,\n },\n confirmEmailChangeTemplate: {\n body: confirmEmailChangeTemplate,\n },\n });\n await migrationDelay();\n\n const migrationFile = getMigrationFile(\"users\", \"updated\", options);\n if (migrationFile) {\n creates.push({\n path: migrationFile,\n language: \"ts\",\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n });\n\n // Modify files\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying +layout.server.ts\");\n const layoutServerFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(layoutServerFile, modifyLayoutServer(layoutServerFile)),\n );\n\n logger.info(\"Modifying root layout\");\n // TODO: make this more robust by searching for Navbar.Root > Navbar.List\n // src/routes/(public)/root-layout.svelte is what vela creates by default\n const layoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const layoutFile =\n layoutCandidates.find((p) => fs.existsSync(p)) ?? layoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(layoutFile, modifyRootLayoutSvelte(layoutFile)),\n );\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerFile = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerFile, modifyHooksServer(hooksServerFile)),\n );\n\n logger.info(\"Modifying sidebar-menu-button.svelte\");\n const sidebarMenuButtonFile = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"ui\",\n \"sidebar\",\n \"sidebar-menu-button.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n sidebarMenuButtonFile,\n modifySidebarMenuButton(sidebarMenuButtonFile),\n ),\n );\n\n // The auth pages and the app sidebar show `site.name`.\n const siteFile = await ensureSiteFile(options);\n\n return {\n creates: siteFile ? [siteFile] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAgB,EAAmB,GAAmC;CACpE,IAAI,CAAC,EAAG,WAAW,CAAU,GAAG;EAC9B,IAAM,IAAU,CAAM;;;;;EAOtB,OADA,EAAG,cAAc,GAAY,CAAO,GAC7B;GAAE,QAAQ;GAAW,SAAS;EAAK;CAC5C;CAEA,IAAM,IAAiB,EAAG,aAAa,GAAY,MAAM,GAEnD,IAAa,IADC,EACD,CAAA,CAAQ,oBAAoB,CAAU,GAGnD,KAAe,MAAoD;EAEvE,AADkB,EAAI,YAAY,MAAM,KAEtC,EAAI,sBAAsB;GACxB,MAAM;GACN,aAAa;EACf,CAAC;CAEL,GAGI,GACA,GAKE,IAAU,EAAW,uBAAuB,MAAM;CACxD,IAAI,KACS,EAAQ,uBAAuB,EAAW,iBAChC,CAAA,EAAI,iBAAiB,GAC1B;EACd,IAAM,IAAc,EAAQ,qBAC1B,EAAW,aACb;EACA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