@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,11 +1,12 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
|
-
import { t } from "./ui-
|
|
2
|
+
import { t } from "./ui-DD4NltyN.js";
|
|
3
3
|
import { n } from "./logger-CQONztPm.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { t as c } from "./
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { _ as r, i, o as a, r as o } from "./ts-morph-helpers-CeduA--o.js";
|
|
5
|
+
import { modifyOutcomeToFile as s } from "./modify-file-Dwfv0dCI.js";
|
|
6
|
+
import { t as c } from "./svelte-file-B3RfgVdt.js";
|
|
7
|
+
import { t as l } from "./compose-handle-B-CkDcQD.js";
|
|
8
|
+
import { a as u, i as d, r as f, t as p } from "./config-target-Bln26FJe.js";
|
|
9
|
+
import { n as ee } from "./_layout-B7ujvjnA.js";
|
|
9
10
|
import m from "node:fs";
|
|
10
11
|
import h from "node:path";
|
|
11
12
|
import { Project as g, QuoteKind as _, SyntaxKind as v } from "ts-morph";
|
|
@@ -41,11 +42,11 @@ function x(e) {
|
|
|
41
42
|
namedImports: ["wuchale"],
|
|
42
43
|
moduleSpecifier: "wuchale/vite"
|
|
43
44
|
}), n = !0);
|
|
44
|
-
let i = t.getDescendantsOfKind(v.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0],
|
|
45
|
-
if (!
|
|
45
|
+
let i = t.getDescendantsOfKind(v.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], o = i?.getKind() === v.ObjectLiteralExpression ? i : null;
|
|
46
|
+
if (!o) r = !0;
|
|
46
47
|
else {
|
|
47
|
-
let e =
|
|
48
|
-
if (!e)
|
|
48
|
+
let e = o.getProperty("plugins");
|
|
49
|
+
if (!e) o.addPropertyAssignment({
|
|
49
50
|
name: "plugins",
|
|
50
51
|
initializer: "[wuchale()]"
|
|
51
52
|
}), n = !0;
|
|
@@ -60,7 +61,7 @@ function x(e) {
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
return n && (t
|
|
64
|
+
return n && (a(t), t.saveSync()), r ? {
|
|
64
65
|
status: "failed",
|
|
65
66
|
message: y
|
|
66
67
|
} : {
|
|
@@ -87,13 +88,13 @@ var S = [
|
|
|
87
88
|
"});"
|
|
88
89
|
].join("\n");
|
|
89
90
|
function w(e) {
|
|
90
|
-
return
|
|
91
|
+
return d(e, {
|
|
91
92
|
notFound: C,
|
|
92
93
|
failed: S
|
|
93
94
|
}, (e) => {
|
|
94
95
|
let t = e.kitContainer();
|
|
95
96
|
if (!t) return !1;
|
|
96
|
-
let n =
|
|
97
|
+
let n = f(t, "alias", "{}");
|
|
97
98
|
if (!n) return !1;
|
|
98
99
|
let r = n.getProperty("$locales");
|
|
99
100
|
return r ? r.getKind() === v.PropertyAssignment && (r.getInitializer()?.getText()?.replace(/['"`]/g, "") !== "src/locales" && r.setInitializer("'src/locales'"), !0) : (n.addPropertyAssignment({
|
|
@@ -172,17 +173,17 @@ function k(t) {
|
|
|
172
173
|
let r = new g({
|
|
173
174
|
compilerOptions: { allowJs: !0 },
|
|
174
175
|
manipulationSettings: { quoteKind: _.Single }
|
|
175
|
-
}).addSourceFileAtPath(t),
|
|
176
|
-
if (
|
|
176
|
+
}).addSourceFileAtPath(t), o = l(r, { expression: T });
|
|
177
|
+
if (o.status === "unsupported" || !o.statement) return {
|
|
177
178
|
status: "failed",
|
|
178
179
|
message: E
|
|
179
180
|
};
|
|
180
|
-
let
|
|
181
|
+
let s = o.statement;
|
|
181
182
|
i(r, "wuchale/load-utils/server", "runWithLocale"), i(r, "wuchale/load-utils/server", "loadLocales"), i(r, "$locales/main.url", "getLocale"), i(r, "$locales/data", "locales"), O(r, "$locales/main.loader.server.svelte.js", "main"), O(r, "$locales/js.loader.server.js", "js");
|
|
182
|
-
let
|
|
183
|
+
let c = e`
|
|
183
184
|
loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
|
|
184
185
|
loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
|
|
185
|
-
`,
|
|
186
|
+
`, u = e`
|
|
186
187
|
const ${T} = async ({ event, resolve }: any) => {
|
|
187
188
|
const locale = getLocale(event.url);
|
|
188
189
|
return await runWithLocale(locale, () =>
|
|
@@ -193,18 +194,95 @@ function k(t) {
|
|
|
193
194
|
);
|
|
194
195
|
};
|
|
195
196
|
`;
|
|
196
|
-
return r.insertText(
|
|
197
|
+
return r.insertText(s.getStart(!0), `${c}\n\n${u}\n\n`), a(r), r.saveSync(), {
|
|
198
|
+
status: "success",
|
|
199
|
+
changed: !0
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/patterns/enable/i18n/modifies/hooks.ts
|
|
204
|
+
var A = e`
|
|
205
|
+
const rerouteDeLocalize = (url: string) => {
|
|
206
|
+
const [upath, locale] = deLocalizeDefault(url, locales);
|
|
207
|
+
const { path } = matchUrl(upath, locale);
|
|
208
|
+
return path ?? url;
|
|
209
|
+
};
|
|
210
|
+
`, j = e`
|
|
211
|
+
import { deLocalizeDefault } from 'wuchale/url';
|
|
212
|
+
import { matchUrl } from '$locales/main.url';
|
|
213
|
+
import { locales } from '$locales/data';
|
|
214
|
+
|
|
215
|
+
const rerouteDeLocalize = (url: string) => {
|
|
216
|
+
const [upath, locale] = deLocalizeDefault(url, locales);
|
|
217
|
+
const { path } = matchUrl(upath, locale);
|
|
218
|
+
return path ?? url;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);
|
|
222
|
+
`, M = e`
|
|
223
|
+
Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:
|
|
224
|
+
|
|
225
|
+
import { deLocalizeDefault } from 'wuchale/url';
|
|
226
|
+
import { matchUrl } from '$locales/main.url';
|
|
227
|
+
import { locales } from '$locales/data';
|
|
228
|
+
|
|
229
|
+
const rerouteDeLocalize = (url: string) => {
|
|
230
|
+
const [upath, locale] = deLocalizeDefault(url, locales);
|
|
231
|
+
const { path } = matchUrl(upath, locale);
|
|
232
|
+
return path ?? url;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));
|
|
236
|
+
`, N = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*negotiateReroute\(\s*url\.pathname\s*\)$/;
|
|
237
|
+
function te(e) {
|
|
238
|
+
return e.getFunction("reroute") ? !0 : e.getExportDeclarations().some((e) => e.getNamedExports().some((e) => (e.getAliasNode()?.getText() ?? e.getName()) === "reroute"));
|
|
239
|
+
}
|
|
240
|
+
function P(e) {
|
|
241
|
+
i(e, "wuchale/url", "deLocalizeDefault"), i(e, "$locales/main.url", "matchUrl"), i(e, "$locales/data", "locales");
|
|
242
|
+
}
|
|
243
|
+
function F(e) {
|
|
244
|
+
if (!m.existsSync(e)) return m.mkdirSync(h.dirname(e), { recursive: !0 }), m.writeFileSync(e, j + "\n"), {
|
|
245
|
+
status: "success",
|
|
246
|
+
changed: !0
|
|
247
|
+
};
|
|
248
|
+
if (m.readFileSync(e, "utf8").includes("rerouteDeLocalize")) return {
|
|
249
|
+
status: "success",
|
|
250
|
+
changed: !1
|
|
251
|
+
};
|
|
252
|
+
let t = new g({
|
|
253
|
+
compilerOptions: { allowJs: !0 },
|
|
254
|
+
manipulationSettings: { quoteKind: _.Single }
|
|
255
|
+
}).addSourceFileAtPath(e), n = t.getVariableDeclaration("reroute");
|
|
256
|
+
if (!n) return te(t) ? {
|
|
257
|
+
status: "failed",
|
|
258
|
+
message: M
|
|
259
|
+
} : (P(t), t.addStatements(`\n${A}\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`), a(t), t.saveSync(), {
|
|
260
|
+
status: "success",
|
|
261
|
+
changed: !0
|
|
262
|
+
});
|
|
263
|
+
if (!n.getFirstAncestorByKind(v.VariableStatement)?.hasExportKeyword()) return {
|
|
264
|
+
status: "failed",
|
|
265
|
+
message: M
|
|
266
|
+
};
|
|
267
|
+
let r = n.getInitializer();
|
|
268
|
+
if (!r || !N.test(r.getText())) return {
|
|
269
|
+
status: "failed",
|
|
270
|
+
message: M
|
|
271
|
+
};
|
|
272
|
+
P(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))");
|
|
273
|
+
let i = t.getVariableStatements().find((e) => e.getDeclarations().some((e) => e.getName() === "reroute"));
|
|
274
|
+
return t.insertText(i.getStart(!0), `${A}\n\n`), a(t), t.saveSync(), {
|
|
197
275
|
status: "success",
|
|
198
276
|
changed: !0
|
|
199
277
|
};
|
|
200
278
|
}
|
|
201
279
|
//#endregion
|
|
202
280
|
//#region src/patterns/enable/i18n/modifies/app-html.ts
|
|
203
|
-
var
|
|
281
|
+
var I = [
|
|
204
282
|
"Add the sveltekit lang placeholder to the <html> tag:",
|
|
205
283
|
"",
|
|
206
284
|
"<html lang=\"%sveltekit.lang%\">"
|
|
207
|
-
].join("\n"),
|
|
285
|
+
].join("\n"), L = [
|
|
208
286
|
"Create src/app.html with a lang placeholder:",
|
|
209
287
|
"",
|
|
210
288
|
"<!doctype html>",
|
|
@@ -218,10 +296,10 @@ var A = [
|
|
|
218
296
|
" </body>",
|
|
219
297
|
"</html>"
|
|
220
298
|
].join("\n");
|
|
221
|
-
function
|
|
299
|
+
function R(e) {
|
|
222
300
|
if (!m.existsSync(e)) return {
|
|
223
301
|
status: "not-found",
|
|
224
|
-
message:
|
|
302
|
+
message: L
|
|
225
303
|
};
|
|
226
304
|
let t = m.readFileSync(e, "utf8");
|
|
227
305
|
if (t.includes("lang=\"%sveltekit.lang%\"") || t.includes("lang='%sveltekit.lang%'")) return {
|
|
@@ -231,7 +309,7 @@ function M(e) {
|
|
|
231
309
|
let n = t.replace(/<html(\s[^>]*?)?>/i, (e) => /\slang\s*=/i.test(e) ? e.replace(/\slang\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i, " lang=\"%sveltekit.lang%\"") : e.replace(/<html/i, "<html lang=\"%sveltekit.lang%\""));
|
|
232
310
|
return n === t ? {
|
|
233
311
|
status: "failed",
|
|
234
|
-
message:
|
|
312
|
+
message: I
|
|
235
313
|
} : (m.writeFileSync(e, n), {
|
|
236
314
|
status: "success",
|
|
237
315
|
changed: !0
|
|
@@ -239,16 +317,16 @@ function M(e) {
|
|
|
239
317
|
}
|
|
240
318
|
//#endregion
|
|
241
319
|
//#region src/patterns/enable/i18n/modifies/gitignore.ts
|
|
242
|
-
var
|
|
320
|
+
var z = [
|
|
243
321
|
"Create a .gitignore with the wuchale cache ignored:",
|
|
244
322
|
"",
|
|
245
323
|
"# Wuchale",
|
|
246
324
|
"src/locales/.wuchale"
|
|
247
325
|
].join("\n");
|
|
248
|
-
function
|
|
326
|
+
function B(t) {
|
|
249
327
|
if (!m.existsSync(t)) return {
|
|
250
328
|
status: "not-found",
|
|
251
|
-
message:
|
|
329
|
+
message: z
|
|
252
330
|
};
|
|
253
331
|
let n = m.readFileSync(t, "utf8");
|
|
254
332
|
if (n.includes("src/locales/.wuchale")) return {
|
|
@@ -266,48 +344,48 @@ function P(t) {
|
|
|
266
344
|
}
|
|
267
345
|
//#endregion
|
|
268
346
|
//#region src/patterns/enable/i18n/modifies/root-layout.svelte.ts
|
|
269
|
-
var
|
|
347
|
+
var V = "<Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n ", H = "<LanguageSelect />", U = e`
|
|
270
348
|
import LanguageSelect from '$lib/components/language-select.svelte';
|
|
271
|
-
`,
|
|
349
|
+
`, W = [
|
|
272
350
|
"Add the language select inside your <Navbar.List> in the root layout.",
|
|
273
351
|
"",
|
|
274
352
|
"Import to add to the <script> tag:",
|
|
275
353
|
"",
|
|
276
|
-
|
|
354
|
+
U,
|
|
277
355
|
"",
|
|
278
356
|
"Markup to add at the end of <Navbar.List>:",
|
|
279
|
-
|
|
280
|
-
].join("\n"),
|
|
357
|
+
V
|
|
358
|
+
].join("\n"), G = [
|
|
281
359
|
"Create a root layout that includes a language select inside <Navbar.List>.",
|
|
282
360
|
"",
|
|
283
361
|
"Import for the <script> tag:",
|
|
284
362
|
"",
|
|
285
|
-
|
|
363
|
+
U,
|
|
286
364
|
"",
|
|
287
365
|
"Markup at the end of <Navbar.List>:",
|
|
288
|
-
|
|
289
|
-
].join("\n"),
|
|
366
|
+
V
|
|
367
|
+
].join("\n"), K = [
|
|
290
368
|
"Add the language select to your root layout.",
|
|
291
369
|
"",
|
|
292
370
|
"Import to add to the <script> tag:",
|
|
293
371
|
"",
|
|
294
|
-
|
|
372
|
+
U,
|
|
295
373
|
"",
|
|
296
374
|
"Markup to add wherever it should render, e.g. above {@render children()}:",
|
|
297
375
|
"",
|
|
298
|
-
|
|
299
|
-
].join("\n"),
|
|
376
|
+
H
|
|
377
|
+
].join("\n"), q = [
|
|
300
378
|
"Create a root layout that includes the language select.",
|
|
301
379
|
"",
|
|
302
380
|
"Import for the <script> tag:",
|
|
303
381
|
"",
|
|
304
|
-
|
|
382
|
+
U,
|
|
305
383
|
"",
|
|
306
384
|
"Markup above {@render children()}:",
|
|
307
385
|
"",
|
|
308
|
-
|
|
386
|
+
H
|
|
309
387
|
].join("\n");
|
|
310
|
-
function
|
|
388
|
+
function J(e) {
|
|
311
389
|
e.modifyScript((e) => {
|
|
312
390
|
let { source: t } = r(e, (e) => {
|
|
313
391
|
o(e, [{
|
|
@@ -318,45 +396,45 @@ function H(e) {
|
|
|
318
396
|
return t;
|
|
319
397
|
});
|
|
320
398
|
}
|
|
321
|
-
function
|
|
399
|
+
function Y(e, t = "shadcn") {
|
|
322
400
|
let n = t === "plain";
|
|
323
401
|
if (!m.existsSync(e)) return {
|
|
324
402
|
status: "not-found",
|
|
325
|
-
message: n ?
|
|
403
|
+
message: n ? q : G
|
|
326
404
|
};
|
|
327
|
-
let r =
|
|
405
|
+
let r = c.fromPath(e);
|
|
328
406
|
return r.hasElement("LanguageSelect") ? {
|
|
329
407
|
status: "success",
|
|
330
408
|
changed: !1
|
|
331
|
-
} : n ? !r.getScript() || !r.insertBeforeChildren(
|
|
409
|
+
} : n ? !r.getScript() || !r.insertBeforeChildren(H) ? {
|
|
332
410
|
status: "failed",
|
|
333
|
-
message:
|
|
334
|
-
} : (
|
|
411
|
+
message: K
|
|
412
|
+
} : (J(r), r.writeTo(e), {
|
|
335
413
|
status: "success",
|
|
336
414
|
changed: r.hasChanged()
|
|
337
|
-
}) : r.hasElement("Navbar.List") ? (
|
|
415
|
+
}) : r.hasElement("Navbar.List") ? (J(r), r.insertBeforeClosingTag("Navbar.List", V), r.writeTo(e), {
|
|
338
416
|
status: "success",
|
|
339
417
|
changed: r.hasChanged()
|
|
340
418
|
}) : {
|
|
341
419
|
status: "failed",
|
|
342
|
-
message:
|
|
420
|
+
message: W
|
|
343
421
|
};
|
|
344
422
|
}
|
|
345
423
|
//#endregion
|
|
346
424
|
//#region src/patterns/enable/i18n/welcome-catalog.ts
|
|
347
|
-
var
|
|
348
|
-
reference:
|
|
425
|
+
var X = "src/routes/+page.svelte", Z = "src/locales/es.po", ne = ["<h1>Welcome to SvelteKit</h1>", "<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>"].join("\n"), Q = [{
|
|
426
|
+
reference: X,
|
|
349
427
|
msgid: "Welcome to SvelteKit",
|
|
350
428
|
msgstr: "Bienvenido a SvelteKit"
|
|
351
429
|
}, {
|
|
352
|
-
reference:
|
|
430
|
+
reference: X,
|
|
353
431
|
msgid: "Visit <0>svelte.dev/docs/kit</0> to read the documentation",
|
|
354
432
|
msgstr: "Visita <0>svelte.dev/docs/kit</0> para leer la documentación"
|
|
355
|
-
}],
|
|
433
|
+
}], re = {
|
|
356
434
|
reference: "src/lib/components/language-select.svelte",
|
|
357
435
|
msgid: "Language",
|
|
358
436
|
msgstr: "Idioma"
|
|
359
|
-
},
|
|
437
|
+
}, ie = [
|
|
360
438
|
"msgid \"\"",
|
|
361
439
|
"msgstr \"\"",
|
|
362
440
|
"\"Source-Language: en\\n\"",
|
|
@@ -366,14 +444,14 @@ var W = "src/routes/+page.svelte", G = "src/locales/es.po", K = ["<h1>Welcome to
|
|
|
366
444
|
"\"Content-Transfer-Encoding: 8bit\\n\"",
|
|
367
445
|
"\"Plural-Forms: nplurals=3\\n\"",
|
|
368
446
|
"\"X-Plurals-Order: one, many, other\\n\""
|
|
369
|
-
].join("\n"),
|
|
370
|
-
function
|
|
371
|
-
if (m.existsSync(h.join(e,
|
|
372
|
-
let n = h.join(e,
|
|
373
|
-
return !m.existsSync(n) ||
|
|
374
|
-
path:
|
|
447
|
+
].join("\n"), $ = (e) => e.replace(/\s+/g, "");
|
|
448
|
+
function ae(e, t) {
|
|
449
|
+
if (m.existsSync(h.join(e, Z))) return null;
|
|
450
|
+
let n = h.join(e, X);
|
|
451
|
+
return !m.existsSync(n) || $(m.readFileSync(n, "utf8")) !== $(ne) ? null : {
|
|
452
|
+
path: Z,
|
|
375
453
|
language: "text",
|
|
376
|
-
content: [
|
|
454
|
+
content: [ie, ...(t === "plain" ? [...Q, re] : Q).map((e) => [
|
|
377
455
|
`#: ${e.reference}`,
|
|
378
456
|
`msgid "${e.msgid}"`,
|
|
379
457
|
`msgstr "${e.msgstr}"`
|
|
@@ -383,31 +461,33 @@ function Z(e, t) {
|
|
|
383
461
|
}
|
|
384
462
|
//#endregion
|
|
385
463
|
//#region src/patterns/enable/i18n/generate.runtime.ts
|
|
386
|
-
async function
|
|
387
|
-
let r = n(e), i = [],
|
|
464
|
+
async function oe(e) {
|
|
465
|
+
let r = n(e), i = [], a = (e) => {
|
|
388
466
|
e && i.push(e);
|
|
389
467
|
};
|
|
390
468
|
r.info("Modifying vite.config");
|
|
391
|
-
let
|
|
392
|
-
|
|
469
|
+
let o = u(e.root, p) ?? h.join(e.root, p[0]);
|
|
470
|
+
a(s(o, x(o))), r.info("Modifying config for i18n alias");
|
|
393
471
|
let c = w(e.root);
|
|
394
|
-
|
|
395
|
-
let
|
|
396
|
-
|
|
397
|
-
let d = h.join(e.root, "src", "
|
|
398
|
-
|
|
472
|
+
a(s(c.filePath, c.outcome)), r.info("Modifying hooks.server.ts");
|
|
473
|
+
let l = h.join(e.root, "src", "hooks.server.ts");
|
|
474
|
+
a(s(l, k(l))), r.info("Modifying hooks.ts");
|
|
475
|
+
let d = h.join(e.root, "src", "hooks.ts");
|
|
476
|
+
a(s(d, F(d))), r.info("Modifying app.html");
|
|
477
|
+
let f = h.join(e.root, "src", "app.html");
|
|
478
|
+
a(s(f, R(f))), r.info("Modifying root +layout.ts");
|
|
399
479
|
let g = h.join(e.root, "src", "routes", "+layout.ts");
|
|
400
|
-
|
|
480
|
+
a(s(g, ee(g))), r.info("Modifying root layout language select");
|
|
401
481
|
let _ = [
|
|
402
482
|
h.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
|
|
403
483
|
h.join(e.root, "src", "routes", "root-layout.svelte"),
|
|
404
484
|
h.join(e.root, "src", "routes", "(public)", "+layout.svelte"),
|
|
405
485
|
h.join(e.root, "src", "routes", "+layout.svelte")
|
|
406
486
|
], v = t(e), y = _.find((e) => m.existsSync(e)) ?? (v === "plain" ? _[3] : _[0]);
|
|
407
|
-
|
|
487
|
+
a(s(y, Y(y, v))), r.info("Updating .gitignore");
|
|
408
488
|
let b = h.join(e.root, ".gitignore");
|
|
409
|
-
|
|
410
|
-
let S =
|
|
489
|
+
a(s(b, B(b)));
|
|
490
|
+
let S = ae(e.root, v);
|
|
411
491
|
return S && r.info("Translating the welcome page into Spanish"), {
|
|
412
492
|
creates: S ? [S] : [],
|
|
413
493
|
modifies: i,
|
|
@@ -420,6 +500,6 @@ async function Q(e) {
|
|
|
420
500
|
};
|
|
421
501
|
}
|
|
422
502
|
//#endregion
|
|
423
|
-
export {
|
|
503
|
+
export { oe as generate };
|
|
424
504
|
|
|
425
|
-
//# sourceMappingURL=generate.runtime-
|
|
505
|
+
//# sourceMappingURL=generate.runtime-FdZw277n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-FdZw277n.js","names":[],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/svelte-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/hooks.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/welcome-catalog.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["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 FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as import(\"ts-morph\").ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import { SyntaxKind, type PropertyAssignment } from \"ts-morph\";\nimport {\n getOrCreateObjectLiteralProperty,\n modifyConfig,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your config (sveltekit() arg in vite.config, or svelte.config):\",\n \"\",\n \"alias: {\",\n \" $locales: 'src/locales',\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Add the $locales alias by passing config to the sveltekit() plugin in vite.config.ts:\",\n \"\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { defineConfig } from 'vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [sveltekit({ alias: { $locales: 'src/locales' } })],\",\n \"});\",\n].join(\"\\n\");\n\n/** Ensure the `$locales` alias points at `src/locales`. */\nexport function modifySvelteConfig(root: string): ConfigModifyResult {\n return modifyConfig(\n root,\n { notFound: NOT_FOUND_HINT, failed: FAILURE_HINT },\n (target) => {\n const kit = target.kitContainer();\n if (!kit) return false;\n const aliasObj = getOrCreateObjectLiteralProperty(kit, \"alias\", \"{}\");\n if (!aliasObj) return false;\n\n const existing = aliasObj.getProperty(\"$locales\");\n if (!existing) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n return true;\n }\n if (existing.getKind() !== SyntaxKind.PropertyAssignment) return false;\n\n const init = (existing as PropertyAssignment).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current !== \"src/locales\") {\n (existing as PropertyAssignment).setInitializer(\"'src/locales'\");\n }\n return true;\n },\n );\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\n`;\n\n/**\n * The whole file, for a project that had no server hooks: a fresh `sv create`\n * app or a static site. `disable-i18n` deletes it again once the i18n handle\n * is all that is left.\n */\nexport const HOOKS_SERVER_SNIPPET = dedent`\n import type { Handle } from '@sveltejs/kit';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale: Handle = async ({ event, resolve }) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }) => html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n\n export const handle = handleWuchale;\n`;\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): 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(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\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 // Composed first: an unsupported handle leaves the file untouched.\n const composed = addHandle(sourceFile, { expression: I18N_HANDLE });\n if (composed.status === \"unsupported\" || !composed.statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const handleStmt = composed.statement;\n\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"$locales/main.url\", \"getLocale\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"locales\");\n ensureNamespaceImport(\n sourceFile,\n \"$locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"$locales/js.loader.server.js\", \"js\");\n\n const startupSnippet = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${I18N_HANDLE} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\n\n // Above the handle and its JSDoc, so `handleWuchale` is declared before\n // the handle reads it.\n sourceFile.insertText(\n handleStmt.getStart(true),\n `${startupSnippet}\\n\\n${i18nHandleSnippet}\\n\\n`,\n );\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\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 {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = dedent`\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n`;\n\n/**\n * The whole file, for a project that had no universal hooks. `disable-i18n`\n * deletes it again once the de-localizing reroute is all that is left.\n */\nexport const HOOKS_SNIPPET = dedent`\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '$locales/main.url';\n import { locales } from '$locales/data';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:\n\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '$locales/main.url';\n import { locales } from '$locales/data';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));\n`;\n\n/** What `enable-content-negotiation` leaves behind, to the whitespace. */\nconst NEGOTIATE_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)$/;\n\n/** A `reroute` this modifier cannot compose with: not a variable declaration. */\nfunction hasOtherReroute(sourceFile: SourceFile): boolean {\n if (sourceFile.getFunction(\"reroute\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) =>\n d\n .getNamedExports()\n .some(\n (n) => (n.getAliasNode()?.getText() ?? n.getName()) === \"reroute\",\n ),\n );\n}\n\nfunction ensureDeLocalizeImports(sourceFile: SourceFile) {\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"$locales/main.url\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"locales\");\n}\n\n/**\n * Add the de-localizing reroute to `src/hooks.ts`, composing with the one\n * `enable-content-negotiation` wrote rather than replacing the file: either\n * pattern may be enabled first, and negotiation's `modifyHooksNegotiate`\n * composes the other way round.\n */\nexport function modifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, HOOKS_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"rerouteDeLocalize\")) {\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 // A reroute in a shape ts-morph cannot rewrite (a function declaration,\n // a re-export) would collide with the one added below.\n if (hasOtherReroute(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n ensureDeLocalizeImports(sourceFile);\n sourceFile.addStatements(\n `\\n${DELOCALIZE_HELPER}\\n\\nexport const reroute = ({ url }) => rerouteDeLocalize(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 || !NEGOTIATE_ONLY_REROUTE.test(init.getText())) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureDeLocalizeImports(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n\n // Last: inserting text forgets the nodes above, and the helper has to be\n // declared before the reroute that reads it.\n const target = sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"reroute\"))!;\n sourceFile.insertText(target.getStart(true), `${DELOCALIZE_HELPER}\\n\\n`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n // A static lang (the templates ship lang=\"en\") is replaced by the\n // placeholder so the server hook can fill in the negotiated locale.\n if (/\\slang\\s*=/i.test(match)) {\n return match.replace(\n /\\slang\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n ' lang=\"%sveltekit.lang%\"',\n );\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\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\";\nimport type { Ui } from \"../../../../core/field/ui\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst PLAIN_LANGUAGE_SELECT_SNIPPET = \"<LanguageSelect />\";\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '$lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_FAILURE_HINT = [\n \"Add the language select to your root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add wherever it should render, e.g. above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_NOT_FOUND_HINT = [\n \"Create a root layout that includes the language select.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nfunction addImport(file: SvelteFile): void {\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"$lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n}\n\n/**\n * A vela layout gets the select as the last `<Navbar.List>` item. A plain one\n * (a project vela did not create) has no navbar, so the select goes above the\n * layout's children.\n */\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n ui: Ui = \"shadcn\",\n): ModifyOutcome {\n const plain = ui === \"plain\";\n if (!fs.existsSync(layoutPath)) {\n return {\n status: \"not-found\",\n message: plain ? PLAIN_NOT_FOUND_HINT : NOT_FOUND_HINT,\n };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n if (plain) {\n // Without a <script> the import has nowhere to go, and the markup alone\n // would not compile.\n if (!file.getScript()) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n if (!file.insertBeforeChildren(PLAIN_LANGUAGE_SELECT_SNIPPET)) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n addImport(file);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n }\n\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n addImport(file);\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File } from \"../../../core/types\";\nimport type { Ui } from \"../../../core/field/ui\";\n\nconst PAGE_PATH = \"src/routes/+page.svelte\";\nconst CATALOG_PATH = \"src/locales/es.po\";\n\n/** `src/routes/+page.svelte` as `sv create` writes it. */\nconst WELCOME_PAGE = [\n \"<h1>Welcome to SvelteKit</h1>\",\n '<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>',\n].join(\"\\n\");\n\ninterface Entry {\n reference: string;\n msgid: string;\n msgstr: string;\n}\n\nconst PAGE_ENTRIES: Entry[] = [\n {\n reference: PAGE_PATH,\n msgid: \"Welcome to SvelteKit\",\n msgstr: \"Bienvenido a SvelteKit\",\n },\n {\n reference: PAGE_PATH,\n msgid: \"Visit <0>svelte.dev/docs/kit</0> to read the documentation\",\n msgstr: \"Visita <0>svelte.dev/docs/kit</0> para leer la documentación\",\n },\n];\n\n// The native <select>'s aria-label. The shadcn select has no text of its own:\n// locale names come from Intl.DisplayNames.\nconst PLAIN_SELECT_ENTRY: Entry = {\n reference: \"src/lib/components/language-select.svelte\",\n msgid: \"Language\",\n msgstr: \"Idioma\",\n};\n\n// What wuchale writes for `es`. It rewrites the file on the first extraction,\n// keeping these translations and adding the source locale's catalog.\nconst HEADER = [\n 'msgid \"\"',\n 'msgstr \"\"',\n '\"Source-Language: en\\\\n\"',\n '\"Language: es\\\\n\"',\n '\"MIME-Version: 1.0\\\\n\"',\n '\"Content-Type: text/plain; charset=utf-8\\\\n\"',\n '\"Content-Transfer-Encoding: 8bit\\\\n\"',\n '\"Plural-Forms: nplurals=3\\\\n\"',\n '\"X-Plurals-Order: one, many, other\\\\n\"',\n].join(\"\\n\");\n\n// Whitespace is ignored so a page prettier has rewrapped still counts.\nconst normalize = (source: string) => source.replace(/\\s+/g, \"\");\n\n/**\n * A Spanish catalog for the `sv create` welcome page, so the language select\n * visibly does something on a fresh project. Anything else in the project is\n * left for the user to translate. Null unless the page is untouched, and never\n * over an existing catalog.\n */\nexport function welcomePageCatalog(root: string, ui: Ui): File | null {\n if (fs.existsSync(path.join(root, CATALOG_PATH))) return null;\n\n const pagePath = path.join(root, PAGE_PATH);\n if (!fs.existsSync(pagePath)) return null;\n const page = fs.readFileSync(pagePath, \"utf8\");\n if (normalize(page) !== normalize(WELCOME_PAGE)) return null;\n\n const entries =\n ui === \"plain\" ? [...PAGE_ENTRIES, PLAIN_SELECT_ENTRY] : PAGE_ENTRIES;\n const blocks = entries.map((entry) =>\n [\n `#: ${entry.reference}`,\n `msgid \"${entry.msgid}\"`,\n `msgstr \"${entry.msgstr}\"`,\n ].join(\"\\n\"),\n );\n\n return {\n path: CATALOG_PATH,\n language: \"text\",\n content: [HEADER, ...blocks].join(\"\\n\\n\") + \"\\n\",\n status: \"success\",\n };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { resolveUi } from \"../../../core/field/ui\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\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 vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Modifying config for i18n alias\");\n const alias = modifySvelteConfig(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.outcome));\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 modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksI18n(hooksPath)));\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\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 ui = resolveUi(options);\n // With no layout at all, a plain project's not-found hint names the\n // +layout.svelte it would have rather than vela's root-layout.svelte.\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n (ui === \"plain\" ? rootLayoutCandidates[3] : rootLayoutCandidates[0]);\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath, ui),\n ),\n );\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n return {\n creates: catalog ? [catalog] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgB,EAAiB,GAAuC;CACtE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAOxD,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAc,GAEzD,IAAU,IACV,IAAS;CAMb,AAJkB,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,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D,OAFI,KAAS,EAAO,KAAK,2CAA2C,GAE7D;EACL,SAAS,IAAU,CAAC,CAAO,IAAI,CAAC;EAChC;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { a as e } from "./util-BLYliuUK.js";
|
|
2
|
+
import { t } from "./dedent-Gq6Krl4n.js";
|
|
3
|
+
import { n } from "./logger-CQONztPm.js";
|
|
4
|
+
import { c as r, i, n as a, o } from "./ts-morph-helpers-CeduA--o.js";
|
|
5
|
+
import { modifyOutcomeToFile as s } from "./modify-file-Dwfv0dCI.js";
|
|
6
|
+
import { r as c } from "./compose-handle-B-CkDcQD.js";
|
|
7
|
+
import { c as l, i as u, n as d, o as f, r as p, t as m } from "./test-setup-DHEFKEHE.js";
|
|
8
|
+
import h from "node:fs";
|
|
9
|
+
import g from "node:path";
|
|
10
|
+
import { Node as _, Project as v, QuoteKind as y } from "ts-morph";
|
|
11
|
+
//#region src/patterns/enable/backend/modifies/hooks.server.ts
|
|
12
|
+
var b = t`
|
|
13
|
+
handlePocketbase({
|
|
14
|
+
pocketbaseUrl: env.POCKETBASE_URL,
|
|
15
|
+
superuserEmail: env.POCKETBASE_SUPERUSER_EMAIL,
|
|
16
|
+
superuserPassword: env.POCKETBASE_SUPERUSER_PASSWORD
|
|
17
|
+
})
|
|
18
|
+
`, x = t`
|
|
19
|
+
Add the PocketBase handle to the exported handle in src/hooks.server.ts:
|
|
20
|
+
|
|
21
|
+
import { sequence } from '@sveltejs/kit/hooks';
|
|
22
|
+
import { env } from '$env/dynamic/private';
|
|
23
|
+
import { handlePocketbase } from '@velastack/pocketbase';
|
|
24
|
+
|
|
25
|
+
export const handle = sequence(
|
|
26
|
+
/* your existing handle */,
|
|
27
|
+
${b.replace(/\n/g, "\n ")}
|
|
28
|
+
);
|
|
29
|
+
`;
|
|
30
|
+
function S(e) {
|
|
31
|
+
if (!h.existsSync(e)) return {
|
|
32
|
+
status: "success",
|
|
33
|
+
changed: !1
|
|
34
|
+
};
|
|
35
|
+
let t = h.readFileSync(e, "utf8"), n = new v({
|
|
36
|
+
compilerOptions: { allowJs: !0 },
|
|
37
|
+
manipulationSettings: { quoteKind: y.Single }
|
|
38
|
+
}).addSourceFileAtPath(e), s = c(n, "handleStatic", {
|
|
39
|
+
expression: b,
|
|
40
|
+
name: "handlePocketbase",
|
|
41
|
+
position: "last"
|
|
42
|
+
});
|
|
43
|
+
if (s.status === "unsupported") return {
|
|
44
|
+
status: "failed",
|
|
45
|
+
message: x
|
|
46
|
+
};
|
|
47
|
+
if (s.status === "unchanged") return {
|
|
48
|
+
status: "success",
|
|
49
|
+
changed: !1
|
|
50
|
+
};
|
|
51
|
+
let l = s.statement;
|
|
52
|
+
if (l && _.isJSDocable(l)) for (let e of l.getJsDocs()) e.getText().includes("vela legal") && e.remove();
|
|
53
|
+
return r(n, ["@velastack/kit"]), i(n, "$env/dynamic/private", "env"), i(n, "@velastack/pocketbase", "handlePocketbase"), o(n), a(n), n.saveSync(), {
|
|
54
|
+
status: "success",
|
|
55
|
+
changed: n.getFullText() !== t
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/patterns/enable/backend/generate.runtime.ts
|
|
60
|
+
async function C(t) {
|
|
61
|
+
let r = n(t), i = [], a = [], o = (t, n) => a.push({
|
|
62
|
+
path: t,
|
|
63
|
+
language: e(t),
|
|
64
|
+
content: n,
|
|
65
|
+
status: "success"
|
|
66
|
+
});
|
|
67
|
+
r.info("Modifying adapter config");
|
|
68
|
+
let c = l(t.root), _ = s(c.filePath, c.outcome);
|
|
69
|
+
_ && i.push(_);
|
|
70
|
+
let v = g.join(t.root, "src", "hooks.server.ts"), y = s(v, S(v));
|
|
71
|
+
y && (r.info("Modifying hooks.server.ts"), i.push(y)), r.info("Modifying .gitignore");
|
|
72
|
+
let b = g.join(t.root, ".gitignore"), x = s(b, f(b));
|
|
73
|
+
x && i.push(x);
|
|
74
|
+
let C = g.join(t.root, "test", "setup.ts");
|
|
75
|
+
if (h.existsSync(C)) {
|
|
76
|
+
r.info("Modifying test/setup.ts");
|
|
77
|
+
let e = s(C, u(C));
|
|
78
|
+
e && i.push(e);
|
|
79
|
+
} else r.info("Creating test/setup.ts"), o("test/setup.ts", d);
|
|
80
|
+
return p(t.root) || (r.info("Creating vitest.config.ts"), o("vitest.config.ts", m)), {
|
|
81
|
+
creates: a,
|
|
82
|
+
modifies: i,
|
|
83
|
+
deletes: [],
|
|
84
|
+
components: [],
|
|
85
|
+
packages: [],
|
|
86
|
+
collections: [],
|
|
87
|
+
collectionPatches: [],
|
|
88
|
+
collectionDrops: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { C as generate };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=generate.runtime-Lh1cW9Tz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-Lh1cW9Tz.js","names":[],"sources":["../../src/patterns/enable/backend/modifies/hooks.server.ts","../../src/patterns/enable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node, Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { replaceHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n ensureNamedImport,\n pruneUnusedImports,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** The handle `creates/src/hooks.server.ts` exports, for a file that already exists. */\nexport const POCKETBASE_HANDLE = dedent`\n handlePocketbase({\n \tpocketbaseUrl: env.POCKETBASE_URL,\n \tsuperuserEmail: env.POCKETBASE_SUPERUSER_EMAIL,\n \tsuperuserPassword: env.POCKETBASE_SUPERUSER_PASSWORD\n })\n`;\n\nconst FAILURE_HINT = dedent`\n Add the PocketBase handle to the exported handle in src/hooks.server.ts:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { env } from '$env/dynamic/private';\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = sequence(\n \t/* your existing handle */,\n \t${POCKETBASE_HANDLE.replace(/\\n/g, \"\\n\\t\")}\n );\n`;\n\n/**\n * Compose the PocketBase handle into a `hooks.server.ts` the project already\n * has, instead of the create overwriting it: a static site's, or one i18n or\n * content negotiation wrote. It takes `handleStatic()`'s place, since\n * `handlePocketbase` does what that did and more; otherwise it goes last, so\n * the handles already there keep running first.\n */\nexport function modifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // The create writes it.\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\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 = replaceHandle(sourceFile, \"handleStatic\", {\n expression: POCKETBASE_HANDLE,\n name: \"handlePocketbase\",\n position: \"last\",\n });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (composed.status === \"unchanged\") {\n return { status: \"success\", changed: false };\n }\n\n // The static template's comment explains handleStatic(). Where that was the\n // whole handle, replaceHandle already dropped it; in a sequence (i18n or\n // negotiation composed in since) it is still there, describing a handle\n // that is gone.\n const statement = composed.statement;\n if (statement && Node.isJSDocable(statement)) {\n for (const doc of statement.getJsDocs()) {\n if (doc.getText().includes(\"vela legal\")) doc.remove();\n }\n }\n\n pruneUnusedImports(sourceFile, [\"@velastack/kit\"]);\n ensureNamedImport(sourceFile, \"$env/dynamic/private\", \"env\");\n ensureNamedImport(sourceFile, \"@velastack/pocketbase\", \"handlePocketbase\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(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 type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { languageFromPath } from \"../../../core/util\";\nimport {\n hasVitestConfig,\n modifyTestSetup,\n VITEST_CONFIG,\n WITH_BACKEND,\n} from \"./modifies/test-setup\";\nimport { modifyHooksServerBackend } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const creates: File[] = [];\n const create = (filePath: string, content: string) =>\n creates.push({\n path: filePath,\n language: languageFromPath(filePath),\n content,\n status: \"success\",\n });\n\n logger.info(\"Modifying adapter config\");\n const adapter = modifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(\n adapter.filePath,\n adapter.outcome,\n );\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // A hooks.server.ts the project already has keeps its handles; the create\n // only writes the file where there is none (see `keepMissing` in index.ts).\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerFile) {\n logger.info(\"Modifying hooks.server.ts\");\n modifies.push(hooksServerFile);\n }\n\n logger.info(\"Modifying .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n modifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n // A backend brings server tests with it. The static template and a project\n // vela did not create have no harness at all, so what is missing is created:\n // the setup file, and the vitest config that loads it.\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n if (fs.existsSync(testSetupPath)) {\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n modifyTestSetup(testSetupPath),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n } else {\n logger.info(\"Creating test/setup.ts\");\n create(\"test/setup.ts\", WITH_BACKEND);\n }\n\n if (!hasVitestConfig(options.root)) {\n logger.info(\"Creating vitest.config.ts\");\n create(\"vitest.config.ts\", VITEST_CONFIG);\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":";;;;;;;;;;;AAaA,IAAa,IAAoB,CAAM;;;;;;GAQjC,IAAe,CAAM;;;;;;;;;KAStB,EAAkB,QAAQ,OAAO,KAAM,EAAE;;;AAW9C,SAAgB,EACd,GACe;CACf,IAAI,CAAC,EAAG,WAAW,CAAe,GAEhC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAW,EAAG,aAAa,GAAiB,MAAM,GAKlD,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAe,GAExD,IAAW,EAAc,GAAY,gBAAgB;EACzD,YAAY;EACZ,MAAM;EACN,UAAU;CACZ,CAAC;CACD,IAAI,EAAS,WAAW,eACtB,OAAO;EAAE,QAAQ;EAAU,SAAS;CAAa;CAEnD,IAAI,EAAS,WAAW,aACtB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAO7C,IAAM,IAAY,EAAS;CAC3B,IAAI,KAAa,EAAK,YAAY,CAAS,GACpC,KAAA,IAAM,KAAO,EAAU,UAAU,GACpC,AAAI,EAAI,QAAQ,CAAC,CAAC,SAAS,YAAY,KAAG,EAAI,OAAO;CAWzD,OAPA,EAAmB,GAAY,CAAC,gBAAgB,CAAC,GACjD,EAAkB,GAAY,wBAAwB,KAAK,GAC3D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