@velastack/patterns 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -3
- package/dist/chunks/_layout-B7ujvjnA.js +55 -0
- package/dist/chunks/_layout-B7ujvjnA.js.map +1 -0
- package/dist/chunks/{collections-CgdvZXmh.js → collections-CrOvS2E7.js} +3 -3
- package/dist/chunks/{collections-CgdvZXmh.js.map → collections-CrOvS2E7.js.map} +1 -1
- package/dist/chunks/{compose-handle-Cg9jnCsS.js → compose-handle-B-CkDcQD.js} +23 -23
- package/dist/chunks/{compose-handle-Cg9jnCsS.js.map → compose-handle-B-CkDcQD.js.map} +1 -1
- package/dist/chunks/config-target-Bln26FJe.js +164 -0
- package/dist/chunks/config-target-Bln26FJe.js.map +1 -0
- package/dist/chunks/{constants-DSFKQwtP.js → constants-BYkd9jeJ.js} +2 -2
- package/dist/chunks/constants-BYkd9jeJ.js.map +1 -0
- package/dist/chunks/errors-DR3gF_7a.js +18 -0
- package/dist/chunks/errors-DR3gF_7a.js.map +1 -0
- package/dist/chunks/{format-result-Cb2hWsb8.js → format-result-DZ8De8KY.js} +19 -11
- package/dist/chunks/format-result-DZ8De8KY.js.map +1 -0
- package/dist/chunks/{generate-DRA63W0r.js → generate-6snrlnpA.js} +2 -2
- package/dist/chunks/{generate-DRA63W0r.js.map → generate-6snrlnpA.js.map} +1 -1
- package/dist/chunks/{generate-iQP31-m1.js → generate-Ca_6FlPi.js} +5 -5
- package/dist/chunks/{generate-iQP31-m1.js.map → generate-Ca_6FlPi.js.map} +1 -1
- package/dist/chunks/{generate-tOkjJFUf.js → generate-CyuY2Ci7.js} +4 -3
- package/dist/chunks/generate-CyuY2Ci7.js.map +1 -0
- package/dist/chunks/{generate-BkQ1xMDp.js → generate-DQeWOEPY.js} +4 -4
- package/dist/chunks/{generate-BkQ1xMDp.js.map → generate-DQeWOEPY.js.map} +1 -1
- package/dist/chunks/{generate-_LvrYK6i.js → generate-DwADTUob.js} +4 -4
- package/dist/chunks/{generate-_LvrYK6i.js.map → generate-DwADTUob.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BbIN0tUZ.js → generate.runtime-4FDxnvCl.js} +67 -66
- package/dist/chunks/generate.runtime-4FDxnvCl.js.map +1 -0
- package/dist/chunks/{generate.runtime-B0hhtyAL.js → generate.runtime-AYQVW1S-.js} +27 -26
- package/dist/chunks/generate.runtime-AYQVW1S-.js.map +1 -0
- package/dist/chunks/{generate.runtime-wA1G3tQ4.js → generate.runtime-B2aFFaac.js} +38 -37
- package/dist/chunks/generate.runtime-B2aFFaac.js.map +1 -0
- package/dist/chunks/{generate.runtime-DhkaXTq3.js → generate.runtime-B45MvtYm.js} +61 -59
- package/dist/chunks/generate.runtime-B45MvtYm.js.map +1 -0
- package/dist/chunks/{generate.runtime-S5RIgbQx.js → generate.runtime-BFOXm2DD.js} +98 -92
- package/dist/chunks/generate.runtime-BFOXm2DD.js.map +1 -0
- package/dist/chunks/{generate.runtime-BnWE4qsu.js → generate.runtime-BHkFmI2Y.js} +55 -54
- package/dist/chunks/generate.runtime-BHkFmI2Y.js.map +1 -0
- package/dist/chunks/{generate.runtime-DNaQxed-.js → generate.runtime-BKiJvE8I.js} +84 -83
- package/dist/chunks/generate.runtime-BKiJvE8I.js.map +1 -0
- package/dist/chunks/{generate.runtime-DoZdSh9W.js → generate.runtime-BSRFv4cJ.js} +58 -57
- package/dist/chunks/generate.runtime-BSRFv4cJ.js.map +1 -0
- package/dist/chunks/{generate.runtime-B49wetSx.js → generate.runtime-BUqsF3AF.js} +43 -42
- package/dist/chunks/generate.runtime-BUqsF3AF.js.map +1 -0
- package/dist/chunks/{generate.runtime-acRmiU7e.js → generate.runtime-BsaSyTnU.js} +9 -8
- package/dist/chunks/{generate.runtime-acRmiU7e.js.map → generate.runtime-BsaSyTnU.js.map} +1 -1
- package/dist/chunks/generate.runtime-CMnvmeVt.js +111 -0
- package/dist/chunks/generate.runtime-CMnvmeVt.js.map +1 -0
- package/dist/chunks/{generate.runtime-BORbegw_.js → generate.runtime-CN5c2xH8.js} +123 -122
- package/dist/chunks/generate.runtime-CN5c2xH8.js.map +1 -0
- package/dist/chunks/{generate.runtime-flFRYzpi.js → generate.runtime-CgoSrP55.js} +62 -61
- package/dist/chunks/generate.runtime-CgoSrP55.js.map +1 -0
- package/dist/chunks/{generate.runtime-D0icLb5j.js → generate.runtime-D1DNAY6k.js} +12 -11
- package/dist/chunks/{generate.runtime-D0icLb5j.js.map → generate.runtime-D1DNAY6k.js.map} +1 -1
- package/dist/chunks/generate.runtime-DG-3G00z.js +87 -0
- package/dist/chunks/generate.runtime-DG-3G00z.js.map +1 -0
- package/dist/chunks/{generate.runtime-BKo-Nidn.js → generate.runtime-DQwSY6Nc.js} +6 -6
- package/dist/chunks/{generate.runtime-BKo-Nidn.js.map → generate.runtime-DQwSY6Nc.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DSqkXvps.js → generate.runtime-D_yqWLcI.js} +15 -14
- package/dist/chunks/{generate.runtime-DSqkXvps.js.map → generate.runtime-D_yqWLcI.js.map} +1 -1
- package/dist/chunks/generate.runtime-Drmahmdl.js +313 -0
- package/dist/chunks/generate.runtime-Drmahmdl.js.map +1 -0
- package/dist/chunks/{generate.runtime-D8vgh5MH.js → generate.runtime-FdZw277n.js} +156 -76
- package/dist/chunks/generate.runtime-FdZw277n.js.map +1 -0
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js +94 -0
- package/dist/chunks/generate.runtime-Lh1cW9Tz.js.map +1 -0
- package/dist/chunks/{generate.runtime-DAmYsIvF.js → generate.runtime-QGHToXRY.js} +5 -5
- package/dist/chunks/{generate.runtime-DAmYsIvF.js.map → generate.runtime-QGHToXRY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CRYjWJRe.js → generate.runtime-Um77JfwC.js} +89 -88
- package/dist/chunks/generate.runtime-Um77JfwC.js.map +1 -0
- package/dist/chunks/{generate.runtime-BwhGDnGu.js → generate.runtime-VgVwRiiN.js} +151 -150
- package/dist/chunks/generate.runtime-VgVwRiiN.js.map +1 -0
- package/dist/chunks/{generate.runtime-CcuAXuV2.js → generate.runtime-YyIVd4oy.js} +15 -14
- package/dist/chunks/{generate.runtime-CcuAXuV2.js.map → generate.runtime-YyIVd4oy.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DOuufRLr.js → generate.runtime-cQGLxuZM.js} +82 -81
- package/dist/chunks/generate.runtime-cQGLxuZM.js.map +1 -0
- package/dist/chunks/generate.runtime-n9AFWtPp.js +94 -0
- package/dist/chunks/generate.runtime-n9AFWtPp.js.map +1 -0
- package/dist/chunks/generate.runtime-ofdnLtxS.js +57 -0
- package/dist/chunks/generate.runtime-ofdnLtxS.js.map +1 -0
- package/dist/chunks/generate.runtime-onBnOiS7.js +328 -0
- package/dist/chunks/generate.runtime-onBnOiS7.js.map +1 -0
- package/dist/chunks/modify-file-Dwfv0dCI.js +46 -0
- package/dist/chunks/modify-file-Dwfv0dCI.js.map +1 -0
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js → modify-svelte-config-remote-BUU_EaDf.js} +2 -2
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js.map → modify-svelte-config-remote-BUU_EaDf.js.map} +1 -1
- package/dist/chunks/{pocketbase-CeG5BMN2.js → pocketbase-BkhUywtb.js} +2 -2
- package/dist/chunks/{pocketbase-CeG5BMN2.js.map → pocketbase-BkhUywtb.js.map} +1 -1
- package/dist/chunks/{providers-DO9kMyzB.js → providers-BL9vJP_9.js} +2 -2
- package/dist/chunks/{providers-DO9kMyzB.js.map → providers-BL9vJP_9.js.map} +1 -1
- package/dist/chunks/{shared-BwHQM-a9.js → shared-C8GtNxpm.js} +2 -2
- package/dist/chunks/{shared-BwHQM-a9.js.map → shared-C8GtNxpm.js.map} +1 -1
- package/dist/chunks/{site-D027dpBm.js → site-BdMX8qrH.js} +2 -2
- package/dist/chunks/{site-D027dpBm.js.map → site-BdMX8qrH.js.map} +1 -1
- package/dist/chunks/table-core-G9Shld4F.js +126 -0
- package/dist/chunks/table-core-G9Shld4F.js.map +1 -0
- package/dist/chunks/{test-setup-B2hd8I-s.js → test-setup-DHEFKEHE.js} +23 -10
- package/dist/chunks/test-setup-DHEFKEHE.js.map +1 -0
- package/dist/chunks/ts-morph-helpers-CeduA--o.js +253 -0
- package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +1 -0
- package/dist/chunks/{ui-jhXrsw4T.js → ui-DD4NltyN.js} +2 -2
- package/dist/chunks/{ui-jhXrsw4T.js.map → ui-DD4NltyN.js.map} +1 -1
- package/dist/chunks/{ui-B4Tuit-7.js → ui-TlEuI2Sz.js} +50 -49
- package/dist/chunks/{ui-B4Tuit-7.js.map → ui-TlEuI2Sz.js.map} +1 -1
- package/dist/chunks/unmodify-load-jfdcVZ_a.js +81 -0
- package/dist/chunks/unmodify-load-jfdcVZ_a.js.map +1 -0
- package/dist/chunks/write-result-Djy0SZXX.js +376 -0
- package/dist/chunks/write-result-Djy0SZXX.js.map +1 -0
- package/dist/index.d.ts +33 -1
- package/dist/index.js +2240 -2020
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/_layout-DqH4lA_r.js +0 -47
- package/dist/chunks/_layout-DqH4lA_r.js.map +0 -1
- package/dist/chunks/config-target-Co-ij8p3.js +0 -163
- package/dist/chunks/config-target-Co-ij8p3.js.map +0 -1
- package/dist/chunks/constants-DSFKQwtP.js.map +0 -1
- package/dist/chunks/errors-D6gyegUK.js +0 -14
- package/dist/chunks/errors-D6gyegUK.js.map +0 -1
- package/dist/chunks/format-result-Cb2hWsb8.js.map +0 -1
- package/dist/chunks/generate-tOkjJFUf.js.map +0 -1
- package/dist/chunks/generate.runtime-B0hhtyAL.js.map +0 -1
- package/dist/chunks/generate.runtime-B49wetSx.js.map +0 -1
- package/dist/chunks/generate.runtime-B7LRx-BU.js +0 -86
- package/dist/chunks/generate.runtime-B7LRx-BU.js.map +0 -1
- package/dist/chunks/generate.runtime-BORbegw_.js.map +0 -1
- package/dist/chunks/generate.runtime-BbIN0tUZ.js.map +0 -1
- package/dist/chunks/generate.runtime-BnWE4qsu.js.map +0 -1
- package/dist/chunks/generate.runtime-BwhGDnGu.js.map +0 -1
- package/dist/chunks/generate.runtime-CCg2Pjcv.js +0 -257
- package/dist/chunks/generate.runtime-CCg2Pjcv.js.map +0 -1
- package/dist/chunks/generate.runtime-CRYjWJRe.js.map +0 -1
- package/dist/chunks/generate.runtime-D2e_KRj0.js +0 -56
- package/dist/chunks/generate.runtime-D2e_KRj0.js.map +0 -1
- package/dist/chunks/generate.runtime-D44gjxRA.js +0 -332
- package/dist/chunks/generate.runtime-D44gjxRA.js.map +0 -1
- package/dist/chunks/generate.runtime-D8vgh5MH.js.map +0 -1
- package/dist/chunks/generate.runtime-DNaQxed-.js.map +0 -1
- package/dist/chunks/generate.runtime-DOuufRLr.js.map +0 -1
- package/dist/chunks/generate.runtime-DhkaXTq3.js.map +0 -1
- package/dist/chunks/generate.runtime-DoZdSh9W.js.map +0 -1
- package/dist/chunks/generate.runtime-S5RIgbQx.js.map +0 -1
- package/dist/chunks/generate.runtime-WmSMWL15.js +0 -82
- package/dist/chunks/generate.runtime-WmSMWL15.js.map +0 -1
- package/dist/chunks/generate.runtime-flFRYzpi.js.map +0 -1
- package/dist/chunks/generate.runtime-gtpOuLNO.js +0 -110
- package/dist/chunks/generate.runtime-gtpOuLNO.js.map +0 -1
- package/dist/chunks/generate.runtime-kLxeDGnS.js +0 -93
- package/dist/chunks/generate.runtime-kLxeDGnS.js.map +0 -1
- package/dist/chunks/generate.runtime-wA1G3tQ4.js.map +0 -1
- package/dist/chunks/modify-file-GQD6uNgI.js +0 -254
- package/dist/chunks/modify-file-GQD6uNgI.js.map +0 -1
- package/dist/chunks/test-setup-B2hd8I-s.js.map +0 -1
- package/dist/chunks/unmodify-load-W1ePZQHr.js +0 -80
- package/dist/chunks/unmodify-load-W1ePZQHr.js.map +0 -1
- package/dist/chunks/write-result-DewHCNhM.js +0 -451
- package/dist/chunks/write-result-DewHCNhM.js.map +0 -1
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { t as o } from "./
|
|
6
|
-
import s from "
|
|
7
|
-
import c from "node:
|
|
8
|
-
import
|
|
3
|
+
import { _ as n, o as r, r as i } from "./ts-morph-helpers-CeduA--o.js";
|
|
4
|
+
import { modifyOutcomeToFile as a } from "./modify-file-Dwfv0dCI.js";
|
|
5
|
+
import { t as o } from "./svelte-file-B3RfgVdt.js";
|
|
6
|
+
import { t as s } from "./compose-handle-B-CkDcQD.js";
|
|
7
|
+
import c from "node:fs";
|
|
8
|
+
import l from "node:path";
|
|
9
|
+
import { Project as u, QuoteKind as d, SyntaxKind as f } from "ts-morph";
|
|
9
10
|
//#region src/patterns/enable/content-negotiation/modifies/hooks.server.ts
|
|
10
|
-
var
|
|
11
|
+
var p = e`
|
|
11
12
|
Wrap your exported handle with the negotiation handler:
|
|
12
13
|
|
|
13
14
|
import { sequence } from '@sveltejs/kit/hooks';
|
|
14
15
|
import { handle as handleNegotiate } from '$lib/negotiate';
|
|
15
16
|
|
|
16
17
|
export const handle = sequence(handleNegotiate, /* your existing handle */);
|
|
17
|
-
`,
|
|
18
|
-
Create src/hooks.server.ts with a negotiation handle:
|
|
19
|
-
|
|
18
|
+
`, m = e`
|
|
20
19
|
import { handle as handleNegotiate } from '$lib/negotiate';
|
|
21
20
|
|
|
22
21
|
export const handle = handleNegotiate;
|
|
23
22
|
`;
|
|
24
|
-
function
|
|
23
|
+
function h(e) {
|
|
25
24
|
let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/negotiate");
|
|
26
25
|
if (t) {
|
|
27
26
|
t.getNamedImports().some((e) => e.getName() === "handle" && e.getAliasNode()?.getText() === "handleNegotiate") || t.addNamedImport({
|
|
@@ -38,42 +37,45 @@ function m(e) {
|
|
|
38
37
|
moduleSpecifier: "$lib/negotiate"
|
|
39
38
|
});
|
|
40
39
|
}
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
43
|
-
status: "
|
|
40
|
+
function g(e) {
|
|
41
|
+
if (!c.existsSync(e)) return c.existsSync(e.replace(/\.ts$/, ".js")) ? {
|
|
42
|
+
status: "failed",
|
|
44
43
|
message: p
|
|
45
|
-
}
|
|
46
|
-
|
|
44
|
+
} : (c.mkdirSync(l.dirname(e), { recursive: !0 }), c.writeFileSync(e, m + "\n"), {
|
|
45
|
+
status: "success",
|
|
46
|
+
changed: !0
|
|
47
|
+
});
|
|
48
|
+
let t = c.readFileSync(e, "utf8");
|
|
47
49
|
if (t.includes("handleNegotiate")) return {
|
|
48
50
|
status: "success",
|
|
49
51
|
changed: !1
|
|
50
52
|
};
|
|
51
|
-
let n = new
|
|
53
|
+
let n = new u({
|
|
52
54
|
compilerOptions: { allowJs: !0 },
|
|
53
|
-
manipulationSettings: { quoteKind:
|
|
55
|
+
manipulationSettings: { quoteKind: d.Single }
|
|
54
56
|
}).addSourceFileAtPath(e);
|
|
55
|
-
return
|
|
57
|
+
return s(n, { expression: "handleNegotiate" }).status === "unsupported" ? {
|
|
56
58
|
status: "failed",
|
|
57
|
-
message:
|
|
58
|
-
} : (
|
|
59
|
+
message: p
|
|
60
|
+
} : (h(n), r(n), n.saveSync(), {
|
|
59
61
|
status: "success",
|
|
60
62
|
changed: n.getFullText() !== t
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
65
|
//#endregion
|
|
64
66
|
//#region src/patterns/enable/content-negotiation/modifies/hooks.ts
|
|
65
|
-
var
|
|
67
|
+
var _ = e`
|
|
66
68
|
import { reroute as negotiateReroute } from '$lib/negotiate';
|
|
67
69
|
|
|
68
70
|
export const reroute = ({ url }) => negotiateReroute(url.pathname);
|
|
69
|
-
`,
|
|
71
|
+
`, v = e`
|
|
70
72
|
Compose your existing reroute in src/hooks.ts with the negotiation reroute:
|
|
71
73
|
|
|
72
74
|
import { reroute as negotiateReroute } from '$lib/negotiate';
|
|
73
75
|
|
|
74
76
|
export const reroute = ({ url }) => existingReroute(negotiateReroute(url.pathname));
|
|
75
77
|
`;
|
|
76
|
-
function
|
|
78
|
+
function y(e) {
|
|
77
79
|
let t = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === "$lib/negotiate");
|
|
78
80
|
if (t) {
|
|
79
81
|
t.getNamedImports().some((e) => e.getName() === "reroute" && e.getAliasNode()?.getText() === "negotiateReroute") || t.addNamedImport({
|
|
@@ -90,61 +92,61 @@ function v(e) {
|
|
|
90
92
|
moduleSpecifier: "$lib/negotiate"
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
|
-
function
|
|
94
|
-
if (!
|
|
95
|
+
function b(e) {
|
|
96
|
+
if (!c.existsSync(e)) return c.mkdirSync(l.dirname(e), { recursive: !0 }), c.writeFileSync(e, _ + "\n"), {
|
|
95
97
|
status: "success",
|
|
96
98
|
changed: !0
|
|
97
99
|
};
|
|
98
|
-
if (
|
|
100
|
+
if (c.readFileSync(e, "utf8").includes("negotiateReroute")) return {
|
|
99
101
|
status: "success",
|
|
100
102
|
changed: !1
|
|
101
103
|
};
|
|
102
|
-
let t = new
|
|
104
|
+
let t = new u({
|
|
103
105
|
compilerOptions: { allowJs: !0 },
|
|
104
|
-
manipulationSettings: { quoteKind:
|
|
106
|
+
manipulationSettings: { quoteKind: d.Single }
|
|
105
107
|
}).addSourceFileAtPath(e), n = t.getVariableDeclaration("reroute");
|
|
106
|
-
if (!n) return
|
|
108
|
+
if (!n) return y(t), t.addStatements("\nexport const reroute = ({ url }) => negotiateReroute(url.pathname);\n"), r(t), t.saveSync(), {
|
|
107
109
|
status: "success",
|
|
108
110
|
changed: !0
|
|
109
111
|
};
|
|
110
|
-
if (!n.getFirstAncestorByKind(
|
|
112
|
+
if (!n.getFirstAncestorByKind(f.VariableStatement)?.hasExportKeyword()) return {
|
|
111
113
|
status: "failed",
|
|
112
|
-
message:
|
|
114
|
+
message: v
|
|
113
115
|
};
|
|
114
|
-
let
|
|
115
|
-
if (!
|
|
116
|
+
let i = n.getInitializer();
|
|
117
|
+
if (!i) return {
|
|
116
118
|
status: "failed",
|
|
117
|
-
message:
|
|
119
|
+
message: v
|
|
118
120
|
};
|
|
119
|
-
let
|
|
120
|
-
return
|
|
121
|
+
let a = t.getVariableDeclarations().some((e) => e.getName() === "rerouteDeLocalize"), o = i.getText();
|
|
122
|
+
return a && o.includes("rerouteDeLocalize") ? (y(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))"), r(t), t.saveSync(), {
|
|
121
123
|
status: "success",
|
|
122
124
|
changed: !0
|
|
123
125
|
}) : {
|
|
124
126
|
status: "failed",
|
|
125
|
-
message:
|
|
127
|
+
message: v
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
130
|
//#endregion
|
|
129
131
|
//#region src/patterns/enable/content-negotiation/modifies/root-layout.svelte.ts
|
|
130
|
-
var
|
|
132
|
+
var x = e`
|
|
131
133
|
import { Negotiate } from '$lib/negotiate';
|
|
132
|
-
`,
|
|
134
|
+
`, S = "\n<Negotiate />\n", C = [
|
|
133
135
|
"Create the root +layout.svelte and mount <Negotiate /> inside it.",
|
|
134
136
|
"",
|
|
135
137
|
"Import for the <script> tag:",
|
|
136
138
|
"",
|
|
137
|
-
|
|
139
|
+
x,
|
|
138
140
|
"",
|
|
139
141
|
"Markup to add at the top level of the layout:",
|
|
140
|
-
|
|
142
|
+
S.trim()
|
|
141
143
|
].join("\n");
|
|
142
|
-
function
|
|
143
|
-
if (!
|
|
144
|
+
function w(e) {
|
|
145
|
+
if (!c.existsSync(e)) return {
|
|
144
146
|
status: "not-found",
|
|
145
|
-
message:
|
|
147
|
+
message: C
|
|
146
148
|
};
|
|
147
|
-
let t =
|
|
149
|
+
let t = o.fromPath(e);
|
|
148
150
|
return t.hasElement("Negotiate") ? {
|
|
149
151
|
status: "success",
|
|
150
152
|
changed: !1
|
|
@@ -156,26 +158,26 @@ function C(e) {
|
|
|
156
158
|
}]);
|
|
157
159
|
});
|
|
158
160
|
return t;
|
|
159
|
-
}), t.appendMarkup(
|
|
161
|
+
}), t.appendMarkup(S), t.writeTo(e), {
|
|
160
162
|
status: "success",
|
|
161
163
|
changed: t.hasChanged()
|
|
162
164
|
});
|
|
163
165
|
}
|
|
164
166
|
//#endregion
|
|
165
167
|
//#region src/patterns/enable/content-negotiation/generate.runtime.ts
|
|
166
|
-
async function
|
|
167
|
-
let n = t(e),
|
|
168
|
-
e &&
|
|
168
|
+
async function T(e) {
|
|
169
|
+
let n = t(e), r = [], i = (e) => {
|
|
170
|
+
e && r.push(e);
|
|
169
171
|
};
|
|
170
172
|
n.info("Modifying hooks.server.ts");
|
|
171
|
-
let o =
|
|
172
|
-
a(
|
|
173
|
-
let s =
|
|
174
|
-
a(
|
|
175
|
-
let
|
|
176
|
-
return a(
|
|
173
|
+
let o = l.join(e.root, "src", "hooks.server.ts");
|
|
174
|
+
i(a(o, g(o))), n.info("Modifying hooks.ts");
|
|
175
|
+
let s = l.join(e.root, "src", "hooks.ts");
|
|
176
|
+
i(a(s, b(s))), n.info("Modifying src/routes/+layout.svelte");
|
|
177
|
+
let c = l.join(e.root, "src", "routes", "+layout.svelte");
|
|
178
|
+
return i(a(c, w(c))), {
|
|
177
179
|
creates: [],
|
|
178
|
-
modifies:
|
|
180
|
+
modifies: r,
|
|
179
181
|
deletes: [],
|
|
180
182
|
components: [],
|
|
181
183
|
packages: [],
|
|
@@ -185,6 +187,6 @@ async function w(e) {
|
|
|
185
187
|
};
|
|
186
188
|
}
|
|
187
189
|
//#endregion
|
|
188
|
-
export {
|
|
190
|
+
export { T as generate };
|
|
189
191
|
|
|
190
|
-
//# sourceMappingURL=generate.runtime-
|
|
192
|
+
//# sourceMappingURL=generate.runtime-B45MvtYm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":"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"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as u } from "./
|
|
7
|
-
import {
|
|
3
|
+
import { _ as n, a as r, o as i, r as a } from "./ts-morph-helpers-CeduA--o.js";
|
|
4
|
+
import { modifyOutcomeToFile as o } from "./modify-file-Dwfv0dCI.js";
|
|
5
|
+
import { t as s } from "./svelte-file-B3RfgVdt.js";
|
|
6
|
+
import { i as c, n as l, t as u } from "./pocketbase-BkhUywtb.js";
|
|
7
|
+
import { t as d } from "./site-BdMX8qrH.js";
|
|
8
8
|
import f from "node:fs";
|
|
9
9
|
import p from "node:path";
|
|
10
10
|
import { Project as m, SyntaxKind as h } from "ts-morph";
|
|
11
|
-
//#region src/patterns/enable/auth
|
|
11
|
+
//#region src/patterns/enable/auth/modifies/+layout.server.ts
|
|
12
12
|
function g(t) {
|
|
13
13
|
if (!f.existsSync(t)) {
|
|
14
14
|
let n = e`
|
|
@@ -21,45 +21,45 @@ function g(t) {
|
|
|
21
21
|
changed: !0
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
let n = f.readFileSync(t, "utf8"), r = new m().addSourceFileAtPath(t),
|
|
24
|
+
let n = f.readFileSync(t, "utf8"), r = new m().addSourceFileAtPath(t), a = (e) => {
|
|
25
25
|
e.getProperty("user") || e.addPropertyAssignment({
|
|
26
26
|
name: "user",
|
|
27
27
|
initializer: "locals.pb.authStore.record"
|
|
28
28
|
});
|
|
29
|
-
},
|
|
30
|
-
if (
|
|
31
|
-
let e =
|
|
32
|
-
if (e)
|
|
29
|
+
}, o, s, c = r.getVariableDeclaration("load");
|
|
30
|
+
if (c && c.getFirstAncestorByKind(h.VariableStatement)?.hasExportKeyword()) {
|
|
31
|
+
let e = c.getInitializerIfKind(h.ArrowFunction);
|
|
32
|
+
if (e) o = e;
|
|
33
33
|
else {
|
|
34
|
-
let e =
|
|
34
|
+
let e = c.getInitializer();
|
|
35
35
|
if (e) {
|
|
36
36
|
let t = e.getFirstDescendantByKind(h.ArrowFunction);
|
|
37
|
-
if (t)
|
|
37
|
+
if (t) o = t;
|
|
38
38
|
else {
|
|
39
39
|
let t = e.getFirstDescendantByKind(h.FunctionExpression);
|
|
40
|
-
t && (
|
|
40
|
+
t && (s = t);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
if (!
|
|
45
|
+
if (!o) {
|
|
46
46
|
let e = r.getFunction("load");
|
|
47
|
-
e && e.isExported() && (
|
|
47
|
+
e && e.isExported() && (s = e);
|
|
48
48
|
}
|
|
49
|
-
if (!
|
|
49
|
+
if (!o && !s) return r.addFunction({
|
|
50
50
|
isExported: !0,
|
|
51
51
|
isAsync: !0,
|
|
52
52
|
name: "load",
|
|
53
53
|
parameters: [{ name: "{ locals }" }],
|
|
54
54
|
statements: "return { user: locals.pb.authStore.record };"
|
|
55
|
-
}), r
|
|
55
|
+
}), i(r), r.saveSync(), {
|
|
56
56
|
status: "success",
|
|
57
57
|
changed: !0
|
|
58
58
|
};
|
|
59
|
-
let
|
|
60
|
-
if (
|
|
59
|
+
let l = o ?? s, u = l.getParameters();
|
|
60
|
+
if (u.length === 0) l.insertParameter(0, { name: "{ locals }" });
|
|
61
61
|
else {
|
|
62
|
-
let e =
|
|
62
|
+
let e = u[0], t = e.getStructure(), n = e.getNameNode();
|
|
63
63
|
if (n.getKind() === h.ObjectBindingPattern) {
|
|
64
64
|
let r = n;
|
|
65
65
|
if (!r.getElements().some((e) => e.getName() === "locals")) {
|
|
@@ -79,15 +79,15 @@ function g(t) {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
if (
|
|
83
|
-
let e =
|
|
82
|
+
if (o) {
|
|
83
|
+
let e = o.getBody();
|
|
84
84
|
if (e.getKind() === h.Block) e.getDescendantsOfKind(h.ReturnStatement).forEach((e) => {
|
|
85
85
|
let t = e.getExpression();
|
|
86
86
|
if (t) {
|
|
87
|
-
if (t.getKind() === h.ObjectLiteralExpression)
|
|
87
|
+
if (t.getKind() === h.ObjectLiteralExpression) a(t);
|
|
88
88
|
else if (t.getKind() === h.ParenthesizedExpression) {
|
|
89
89
|
let e = t.getExpression();
|
|
90
|
-
e.getKind() === h.ObjectLiteralExpression &&
|
|
90
|
+
e.getKind() === h.ObjectLiteralExpression && a(e);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
});
|
|
@@ -95,29 +95,29 @@ function g(t) {
|
|
|
95
95
|
let t = e;
|
|
96
96
|
if (t.getKind() === h.ParenthesizedExpression) {
|
|
97
97
|
let e = t.getExpression();
|
|
98
|
-
e.getKind() === h.ObjectLiteralExpression &&
|
|
99
|
-
} else t.getKind() === h.ObjectLiteralExpression &&
|
|
98
|
+
e.getKind() === h.ObjectLiteralExpression && a(e);
|
|
99
|
+
} else t.getKind() === h.ObjectLiteralExpression && a(t);
|
|
100
100
|
}
|
|
101
|
-
} else if (
|
|
102
|
-
let e =
|
|
101
|
+
} else if (s) {
|
|
102
|
+
let e = s.getBody();
|
|
103
103
|
e && e.getDescendantsOfKind(h.ReturnStatement).forEach((e) => {
|
|
104
104
|
let t = e.getExpression();
|
|
105
105
|
if (t) {
|
|
106
|
-
if (t.getKind() === h.ObjectLiteralExpression)
|
|
106
|
+
if (t.getKind() === h.ObjectLiteralExpression) a(t);
|
|
107
107
|
else if (t.getKind() === h.ParenthesizedExpression) {
|
|
108
108
|
let e = t.getExpression();
|
|
109
|
-
e.getKind() === h.ObjectLiteralExpression &&
|
|
109
|
+
e.getKind() === h.ObjectLiteralExpression && a(e);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
return r
|
|
114
|
+
return i(r), r.saveSync(), {
|
|
115
115
|
status: "success",
|
|
116
116
|
changed: r.getFullText() !== n
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
//#endregion
|
|
120
|
-
//#region src/patterns/enable/auth
|
|
120
|
+
//#region src/patterns/enable/auth/modifies/root-layout.svelte.ts
|
|
121
121
|
var _ = "\n <Navbar.Item\n class=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n >\n <AuthMenu.Root>\n {#snippet user()}\n <AuthMenu.Trigger>\n <Avatar.Root>\n {#if data.user?.avatar}\n <Avatar.Image\n src=\"/api/files/users/{data.user?.id}/{data.user?.avatar}\"\n alt={data.user?.email}\n />\n {/if}\n <Avatar.Fallback>\n {data.user?.email?.charAt(0).toUpperCase()}\n </Avatar.Fallback>\n </Avatar.Root>\n </AuthMenu.Trigger>\n\n <AuthMenu.Content align=\"end\">\n <AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n <AuthMenu.Group>\n <AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n <AuthMenu.Item>\n <form action=\"/logout\" method=\"post\">\n <button type=\"submit\" class=\"contents\">Logout</button>\n </form>\n </AuthMenu.Item>\n </AuthMenu.Group>\n </AuthMenu.Content>\n {/snippet}\n\n {#snippet guest()}\n <Button\n class=\"w-full justify-start md:justify-center md:w-auto\"\n variant=\"ghost\"\n href=\"/login\">Login</Button\n >\n <Button\n class=\"w-full justify-start md:justify-center md:w-auto\"\n variant=\"outline\"\n href=\"/signup\">Sign up</Button\n >\n {/snippet}\n </AuthMenu.Root>\n </Navbar.Item>\n ", v = e`
|
|
122
122
|
import * as AuthMenu from '$lib/components/ui/auth-menu';
|
|
123
123
|
import * as Avatar from '$lib/components/ui/avatar';
|
|
@@ -145,19 +145,19 @@ function x(e) {
|
|
|
145
145
|
status: "not-found",
|
|
146
146
|
message: b
|
|
147
147
|
};
|
|
148
|
-
let t =
|
|
148
|
+
let t = s.fromPath(e);
|
|
149
149
|
return t.hasElement("Navbar.List") ? t.hasElement("AuthMenu.Root") ? {
|
|
150
150
|
status: "success",
|
|
151
151
|
changed: !1
|
|
152
152
|
} : (t.modifyScript((e) => {
|
|
153
|
-
let { source: t } =
|
|
153
|
+
let { source: t } = n(e, (e) => {
|
|
154
154
|
a(e, [{
|
|
155
155
|
namespaceImport: "AuthMenu",
|
|
156
156
|
moduleSpecifier: "$lib/components/ui/auth-menu"
|
|
157
157
|
}, {
|
|
158
158
|
namespaceImport: "Avatar",
|
|
159
159
|
moduleSpecifier: "$lib/components/ui/avatar"
|
|
160
|
-
}]),
|
|
160
|
+
}]), r(e, "data");
|
|
161
161
|
});
|
|
162
162
|
return t;
|
|
163
163
|
}), t.insertBeforeClosingTag("Navbar.List", _), t.writeTo(e), {
|
|
@@ -169,7 +169,7 @@ function x(e) {
|
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
171
|
//#endregion
|
|
172
|
-
//#region src/patterns/enable/auth
|
|
172
|
+
//#region src/patterns/enable/auth/modifies/hooks.server.ts
|
|
173
173
|
var S = e`
|
|
174
174
|
Configure handlePocketbase() with the auth option in hooks.server.ts:
|
|
175
175
|
|
|
@@ -179,7 +179,7 @@ var S = e`
|
|
|
179
179
|
`, C = e`
|
|
180
180
|
Create src/hooks.server.ts with handlePocketbase:
|
|
181
181
|
|
|
182
|
-
import { handlePocketbase } from '
|
|
182
|
+
import { handlePocketbase } from 'velastack/handle';
|
|
183
183
|
|
|
184
184
|
export const handle = handlePocketbase({
|
|
185
185
|
auth: { protectedRoutes: ['/(app)'] },
|
|
@@ -195,26 +195,26 @@ function w(e) {
|
|
|
195
195
|
status: "failed",
|
|
196
196
|
message: S
|
|
197
197
|
};
|
|
198
|
-
let
|
|
199
|
-
if (
|
|
198
|
+
let a = r.getArguments();
|
|
199
|
+
if (a.length === 0) return r.addArgument("{ auth: { protectedRoutes: ['/(app)'] } }"), i(n), n.saveSync(), {
|
|
200
200
|
status: "success",
|
|
201
201
|
changed: !0
|
|
202
202
|
};
|
|
203
|
-
let
|
|
204
|
-
if (
|
|
203
|
+
let o = a[0];
|
|
204
|
+
if (o.getKind() !== h.ObjectLiteralExpression) return r.insertArgument(0, "{ auth: { protectedRoutes: ['/(app)'] } }"), i(n), n.saveSync(), {
|
|
205
205
|
status: "success",
|
|
206
206
|
changed: !0
|
|
207
207
|
};
|
|
208
|
-
let
|
|
209
|
-
if (!
|
|
208
|
+
let s = o.asKindOrThrow(h.ObjectLiteralExpression), c = s.getProperty("auth");
|
|
209
|
+
if (!c) return s.addPropertyAssignment({
|
|
210
210
|
name: "auth",
|
|
211
211
|
initializer: "{ protectedRoutes: ['/(app)'] }"
|
|
212
|
-
}), n
|
|
212
|
+
}), i(n), n.saveSync(), {
|
|
213
213
|
status: "success",
|
|
214
214
|
changed: !0
|
|
215
215
|
};
|
|
216
|
-
if (
|
|
217
|
-
let e =
|
|
216
|
+
if (c.getKind() === h.PropertyAssignment) {
|
|
217
|
+
let e = c.getInitializer();
|
|
218
218
|
if (e && e.getKind() === h.ObjectLiteralExpression) {
|
|
219
219
|
let t = e, n = t.getProperty("protectedRoutes");
|
|
220
220
|
if (!n) t.addPropertyAssignment({
|
|
@@ -230,48 +230,56 @@ function w(e) {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
return n
|
|
233
|
+
return i(n), n.saveSync(), {
|
|
234
234
|
status: "success",
|
|
235
235
|
changed: n.getFullText() !== t
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
238
|
//#endregion
|
|
239
|
-
//#region src/patterns/enable/auth
|
|
240
|
-
var T =
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
239
|
+
//#region src/patterns/enable/auth/modifies/sidebar-menu-button.svelte.ts
|
|
240
|
+
var T = [{
|
|
241
|
+
from: "'data-active': isActive,",
|
|
242
|
+
to: "'data-active': isActive ? true : undefined,"
|
|
243
|
+
}, {
|
|
244
|
+
from: "\"data-active\": isActive,",
|
|
245
|
+
to: "\"data-active\": isActive ? true : undefined,"
|
|
246
|
+
}], E = e`
|
|
247
|
+
The shadcn-svelte sidebar component was not installed at the expected path.
|
|
248
|
+
Run: vela enable auth (or install the 'sidebar' shadcn-svelte component).
|
|
248
249
|
`;
|
|
249
|
-
function
|
|
250
|
+
function D(e) {
|
|
250
251
|
if (!f.existsSync(e)) return {
|
|
252
|
+
status: "not-found",
|
|
253
|
+
message: E
|
|
254
|
+
};
|
|
255
|
+
let t = f.readFileSync(e, "utf8");
|
|
256
|
+
if (T.some(({ to: e }) => t.includes(e))) return {
|
|
251
257
|
status: "success",
|
|
252
258
|
changed: !1
|
|
253
259
|
};
|
|
254
|
-
let
|
|
255
|
-
|
|
260
|
+
let n = T.find(({ from: e }) => t.includes(e));
|
|
261
|
+
if (!n) return {
|
|
256
262
|
status: "success",
|
|
257
263
|
changed: !1
|
|
258
|
-
}
|
|
264
|
+
};
|
|
265
|
+
let r = t.replace(n.from, n.to);
|
|
266
|
+
return f.writeFileSync(e, r, "utf8"), {
|
|
259
267
|
status: "success",
|
|
260
268
|
changed: !0
|
|
261
|
-
}
|
|
269
|
+
};
|
|
262
270
|
}
|
|
263
271
|
//#endregion
|
|
264
|
-
//#region src/patterns/enable/auth
|
|
265
|
-
async function
|
|
266
|
-
let { input: n } = e, r = t(e),
|
|
267
|
-
await
|
|
272
|
+
//#region src/patterns/enable/auth/generate.runtime.ts
|
|
273
|
+
async function O(e) {
|
|
274
|
+
let { input: n } = e, r = t(e), i = [];
|
|
275
|
+
await c(e.root, async (t) => {
|
|
268
276
|
r.info("Updating PocketBase mail settings"), await t.settings.update({ meta: {
|
|
269
277
|
senderName: n.senderName,
|
|
270
278
|
senderAddress: n.senderAddress
|
|
271
|
-
} }), await
|
|
272
|
-
let
|
|
273
|
-
if (!
|
|
274
|
-
let o =
|
|
279
|
+
} }), await l();
|
|
280
|
+
let a = await t.collections.getOne("users");
|
|
281
|
+
if (!a) throw Error("Users collection not found");
|
|
282
|
+
let o = a.verificationTemplate.body.replace("{APP_URL}/_/#/auth/confirm-verification/{TOKEN}", "{APP_URL}/confirm-verification/{TOKEN}"), s = a.resetPasswordTemplate.body.replace("{APP_URL}/_/#/auth/confirm-reset/{TOKEN}", "{APP_URL}/confirm-reset/{TOKEN}"), c = a.confirmEmailChangeTemplate.body.replace("{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}", "{APP_URL}/confirm-email-change/{TOKEN}");
|
|
275
283
|
r.info("Locking down users collection rules and email templates"), await t.collections.update("users", {
|
|
276
284
|
listRule: "@request.auth.id = id",
|
|
277
285
|
viewRule: "@request.auth.id = id",
|
|
@@ -280,39 +288,37 @@ async function D(e) {
|
|
|
280
288
|
deleteRule: "@request.auth.id = id",
|
|
281
289
|
verificationTemplate: { body: o },
|
|
282
290
|
resetPasswordTemplate: { body: s },
|
|
283
|
-
confirmEmailChangeTemplate: { body:
|
|
284
|
-
}), await
|
|
285
|
-
let d =
|
|
286
|
-
d &&
|
|
291
|
+
confirmEmailChangeTemplate: { body: c }
|
|
292
|
+
}), await l();
|
|
293
|
+
let d = u("users", "updated", e);
|
|
294
|
+
d && i.push({
|
|
287
295
|
path: d,
|
|
288
296
|
language: "ts",
|
|
289
297
|
content: f.readFileSync(d, "utf8"),
|
|
290
298
|
status: "success"
|
|
291
299
|
});
|
|
292
300
|
});
|
|
293
|
-
let
|
|
294
|
-
e &&
|
|
301
|
+
let a = [], s = (e) => {
|
|
302
|
+
e && a.push(e);
|
|
295
303
|
};
|
|
296
304
|
r.info("Modifying +layout.server.ts");
|
|
297
|
-
let
|
|
298
|
-
|
|
299
|
-
let
|
|
305
|
+
let m = p.join(e.root, "src", "routes", "+layout.server.ts");
|
|
306
|
+
s(o(m, g(m))), r.info("Modifying root layout");
|
|
307
|
+
let h = [
|
|
300
308
|
p.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
|
|
301
309
|
p.join(e.root, "src", "routes", "root-layout.svelte"),
|
|
302
310
|
p.join(e.root, "src", "routes", "(public)", "+layout.svelte"),
|
|
303
311
|
p.join(e.root, "src", "routes", "+layout.svelte")
|
|
304
|
-
],
|
|
305
|
-
|
|
306
|
-
let
|
|
307
|
-
|
|
308
|
-
let
|
|
309
|
-
|
|
310
|
-
let
|
|
311
|
-
m(i(S.filePath, S.outcome));
|
|
312
|
-
let C = await u(e);
|
|
312
|
+
], _ = h.find((e) => f.existsSync(e)) ?? h[0];
|
|
313
|
+
s(o(_, x(_))), r.info("Modifying hooks.server.ts");
|
|
314
|
+
let v = p.join(e.root, "src", "hooks.server.ts");
|
|
315
|
+
s(o(v, w(v))), r.info("Modifying sidebar-menu-button.svelte");
|
|
316
|
+
let y = p.join(e.root, "src", "lib", "components", "ui", "sidebar", "sidebar-menu-button.svelte");
|
|
317
|
+
s(o(y, D(y)));
|
|
318
|
+
let b = await d(e);
|
|
313
319
|
return {
|
|
314
|
-
creates:
|
|
315
|
-
modifies:
|
|
320
|
+
creates: b ? [b] : [],
|
|
321
|
+
modifies: a,
|
|
316
322
|
deletes: [],
|
|
317
323
|
components: [],
|
|
318
324
|
packages: [],
|
|
@@ -322,6 +328,6 @@ async function D(e) {
|
|
|
322
328
|
};
|
|
323
329
|
}
|
|
324
330
|
//#endregion
|
|
325
|
-
export {
|
|
331
|
+
export { O as generate };
|
|
326
332
|
|
|
327
|
-
//# sourceMappingURL=generate.runtime-
|
|
333
|
+
//# sourceMappingURL=generate.runtime-BFOXm2DD.js.map
|