@velastack/patterns 0.13.1 → 0.13.2

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.
Files changed (32) hide show
  1. package/dist/chunks/{_layout-Dju9EYqa.js → _layout-xBzFhszN.js} +31 -13
  2. package/dist/chunks/_layout-xBzFhszN.js.map +1 -0
  3. package/dist/chunks/{generate.runtime-DGnXHELM.js → generate.runtime-B6FeCL5I.js} +2 -2
  4. package/dist/chunks/{generate.runtime-DGnXHELM.js.map → generate.runtime-B6FeCL5I.js.map} +1 -1
  5. package/dist/chunks/{generate.runtime-DHJqOJTr.js → generate.runtime-Bv_16lWi.js} +2 -2
  6. package/dist/chunks/{generate.runtime-DHJqOJTr.js.map → generate.runtime-Bv_16lWi.js.map} +1 -1
  7. package/dist/chunks/{generate.runtime-BEmSIAop.js → generate.runtime-C_SdcnRs.js} +2 -2
  8. package/dist/chunks/{generate.runtime-BEmSIAop.js.map → generate.runtime-C_SdcnRs.js.map} +1 -1
  9. package/dist/chunks/{generate.runtime-DWHoDisZ.js → generate.runtime-CzYArKUA.js} +2 -2
  10. package/dist/chunks/{generate.runtime-DWHoDisZ.js.map → generate.runtime-CzYArKUA.js.map} +1 -1
  11. package/dist/chunks/{generate.runtime-Dtf3tF3-.js → generate.runtime-DLg2CKxQ.js} +96 -71
  12. package/dist/chunks/generate.runtime-DLg2CKxQ.js.map +1 -0
  13. package/dist/chunks/{generate.runtime-Cgam_XCc.js → generate.runtime-DaPA2NNL.js} +2 -2
  14. package/dist/chunks/{generate.runtime-Cgam_XCc.js.map → generate.runtime-DaPA2NNL.js.map} +1 -1
  15. package/dist/chunks/{generate.runtime-DvTbN-no.js → generate.runtime-Dfl-07VS.js} +134 -132
  16. package/dist/chunks/generate.runtime-Dfl-07VS.js.map +1 -0
  17. package/dist/chunks/test-setup-cZj1tqaf.js +176 -0
  18. package/dist/chunks/test-setup-cZj1tqaf.js.map +1 -0
  19. package/dist/chunks/{ui-Ct6YQuPw.js → ui-IkdkLwmB.js} +2 -2
  20. package/dist/chunks/{ui-Ct6YQuPw.js.map → ui-IkdkLwmB.js.map} +1 -1
  21. package/dist/chunks/write-result-C1GYInL8.js +499 -0
  22. package/dist/chunks/write-result-C1GYInL8.js.map +1 -0
  23. package/dist/index.js +194 -197
  24. package/dist/index.js.map +1 -1
  25. package/package.json +1 -1
  26. package/dist/chunks/_layout-Dju9EYqa.js.map +0 -1
  27. package/dist/chunks/generate.runtime-Dtf3tF3-.js.map +0 -1
  28. package/dist/chunks/generate.runtime-DvTbN-no.js.map +0 -1
  29. package/dist/chunks/test-setup-CbwhAJT4.js +0 -176
  30. package/dist/chunks/test-setup-CbwhAJT4.js.map +0 -1
  31. package/dist/chunks/write-result-B5KFCqxw.js +0 -487
  32. package/dist/chunks/write-result-B5KFCqxw.js.map +0 -1
@@ -3,30 +3,30 @@ import { t } from "./ui-D5xgIDR_.js";
3
3
  import { r as n } from "./modify-file-CRZ_gMg0.js";
4
4
  import { a as r, t as i } from "./config-target-DJbVHwHl.js";
5
5
  import { _ as a, i as o, o as s, r as c } from "./ts-morph-helpers-B4KZXP44.js";
6
- import { i as l, n as u } from "./_layout-Dju9EYqa.js";
7
- import { t as d } from "./dedent-CCUOcPFW.js";
8
- import { t as f } from "./compose-handle-Da7m6lV_.js";
9
- import { t as p } from "./svelte-file-DfplF3BU.js";
10
- import { r as m, t as h } from "./wuchale-config-CNXoq4rc.js";
11
- import g from "node:fs";
12
- import _ from "node:path";
13
- import { Project as v, QuoteKind as y, SyntaxKind as b } from "ts-morph";
6
+ import { i as l, n as u, s as d } from "./_layout-xBzFhszN.js";
7
+ import { t as f } from "./dedent-CCUOcPFW.js";
8
+ import { t as p } from "./compose-handle-Da7m6lV_.js";
9
+ import { t as m } from "./svelte-file-DfplF3BU.js";
10
+ import { r as h, t as g } from "./wuchale-config-CNXoq4rc.js";
11
+ import _ from "node:fs";
12
+ import v from "node:path";
13
+ import { Project as y, QuoteKind as b, SyntaxKind as x } from "ts-morph";
14
14
  // src/patterns/enable/i18n/modifies/vite-config.ts
15
- var x = "Add the wuchale plugin to your Vite config:\n\nimport { wuchale } from 'wuchale/vite';\n\nexport default defineConfig({\n plugins: [wuchale(), /* ...existing plugins */],\n});", S = "Create a Vite config with the wuchale plugin:\n\nimport { defineConfig } from 'vite';\nimport { wuchale } from 'wuchale/vite';\n\nexport default defineConfig({\n plugins: [wuchale()],\n});";
16
- function C(e) {
17
- if (!g.existsSync(e)) return {
15
+ var S = "Add the wuchale plugin to your Vite config:\n\nimport { wuchale } from 'wuchale/vite';\n\nexport default defineConfig({\n plugins: [wuchale(), /* ...existing plugins */],\n});", C = "Create a Vite config with the wuchale plugin:\n\nimport { defineConfig } from 'vite';\nimport { wuchale } from 'wuchale/vite';\n\nexport default defineConfig({\n plugins: [wuchale()],\n});";
16
+ function w(e) {
17
+ if (!_.existsSync(e)) return {
18
18
  status: "not-found",
19
- message: S
19
+ message: C
20
20
  };
21
- let t = new v({
21
+ let t = new y({
22
22
  compilerOptions: { allowJs: !0 },
23
- manipulationSettings: { quoteKind: y.Single }
23
+ manipulationSettings: { quoteKind: b.Single }
24
24
  }).addSourceFileAtPath(e), n = !1, r = !1;
25
25
  t.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "wuchale/vite") || (t.insertImportDeclaration(0, {
26
26
  namedImports: ["wuchale"],
27
27
  moduleSpecifier: "wuchale/vite"
28
28
  }), n = !0);
29
- let i = t.getDescendantsOfKind(b.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], a = i?.getKind() === b.ObjectLiteralExpression ? i : null;
29
+ let i = t.getDescendantsOfKind(x.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], a = i?.getKind() === x.ObjectLiteralExpression ? i : null;
30
30
  if (!a) r = !0;
31
31
  else {
32
32
  let e = a.getProperty("plugins");
@@ -34,11 +34,11 @@ function C(e) {
34
34
  name: "plugins",
35
35
  initializer: "[wuchale()]"
36
36
  }), n = !0;
37
- else if (e.getKind() !== b.PropertyAssignment) r = !0;
37
+ else if (e.getKind() !== x.PropertyAssignment) r = !0;
38
38
  else {
39
39
  let t = e.getInitializer();
40
40
  if (!t) e.setInitializer("[wuchale()]"), n = !0;
41
- else if (t.getKind() !== b.ArrayLiteralExpression) r = !0;
41
+ else if (t.getKind() !== x.ArrayLiteralExpression) r = !0;
42
42
  else {
43
43
  let e = t;
44
44
  e.getElements().some((e) => e.getText().replace(/\s/g, "") === "wuchale()") || (e.insertElement(0, "wuchale()"), n = !0);
@@ -47,14 +47,14 @@ function C(e) {
47
47
  }
48
48
  return n && (s(t), t.saveSync()), r ? {
49
49
  status: "failed",
50
- message: x
50
+ message: S
51
51
  } : {
52
52
  status: "success",
53
53
  changed: n
54
54
  };
55
55
  }
56
56
  // src/patterns/enable/i18n/modifies/hooks.server.ts
57
- var w = "handleWuchale", T = d`
57
+ var T = "handleWuchale", E = f`
58
58
  Wrap your exported handle with the wuchale i18n handler:
59
59
 
60
60
  import { sequence } from '@sveltejs/kit/hooks';
@@ -78,7 +78,7 @@ var w = "handleWuchale", T = d`
78
78
  };
79
79
 
80
80
  export const handle = sequence(handleWuchale, /* your existing handle */);
81
- `, E = d`
81
+ `, D = f`
82
82
  import type { Handle } from '@sveltejs/kit/hooks';
83
83
  import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';
84
84
  import { getLocale } from '#locales/main.url.js';
@@ -100,40 +100,40 @@ var w = "handleWuchale", T = d`
100
100
 
101
101
  export const handle = handleWuchale;
102
102
  `;
103
- function D(e, t, n) {
103
+ function O(e, t, n) {
104
104
  e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t) || e.addImportDeclaration({
105
105
  namespaceImport: n,
106
106
  moduleSpecifier: t
107
107
  });
108
108
  }
109
- function O(e) {
110
- if (!g.existsSync(e)) return g.existsSync(e.replace(/\.ts$/, ".js")) ? {
109
+ function k(e) {
110
+ if (!_.existsSync(e)) return _.existsSync(e.replace(/\.ts$/, ".js")) ? {
111
111
  status: "failed",
112
- message: T
113
- } : (g.mkdirSync(_.dirname(e), { recursive: !0 }), g.writeFileSync(e, E + "\n"), {
112
+ message: E
113
+ } : (_.mkdirSync(v.dirname(e), { recursive: !0 }), _.writeFileSync(e, D + "\n"), {
114
114
  status: "success",
115
115
  changed: !0
116
116
  });
117
- let t = g.readFileSync(e, "utf8");
117
+ let t = _.readFileSync(e, "utf8");
118
118
  if (t.includes("runWithLocale") || t.includes("loadLocales(")) return {
119
119
  status: "success",
120
120
  changed: !1
121
121
  };
122
- let n = new v({
122
+ let n = new y({
123
123
  compilerOptions: { allowJs: !0 },
124
- manipulationSettings: { quoteKind: y.Single }
125
- }).addSourceFileAtPath(e), r = f(n, { expression: w });
124
+ manipulationSettings: { quoteKind: b.Single }
125
+ }).addSourceFileAtPath(e), r = p(n, { expression: T });
126
126
  if (r.status === "unsupported" || !r.statement) return {
127
127
  status: "failed",
128
- message: T
128
+ message: E
129
129
  };
130
130
  let i = r.statement;
131
- o(n, "wuchale/load-utils/server", "runWithLocale"), o(n, "wuchale/load-utils/server", "loadLocales"), o(n, "#locales/main.url.js", "getLocale"), o(n, "#locales/data.js", "locales"), D(n, "#locales/main.loader.server.svelte.js", "main"), D(n, "#locales/js.loader.server.js", "js");
132
- let a = d`
131
+ o(n, "wuchale/load-utils/server", "runWithLocale"), o(n, "wuchale/load-utils/server", "loadLocales"), o(n, "#locales/main.url.js", "getLocale"), o(n, "#locales/data.js", "locales"), O(n, "#locales/main.loader.server.svelte.js", "main"), O(n, "#locales/js.loader.server.js", "js");
132
+ let a = f`
133
133
  loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
134
134
  loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
135
- `, c = d`
136
- const ${w} = async ({ event, resolve }: any) => {
135
+ `, c = f`
136
+ const ${T} = async ({ event, resolve }: any) => {
137
137
  const locale = getLocale(event.url);
138
138
  return await runWithLocale(locale, () =>
139
139
  resolve(event, {
@@ -149,13 +149,13 @@ function O(e) {
149
149
  };
150
150
  }
151
151
  // src/patterns/enable/i18n/modifies/hooks.ts
152
- var k = d`
152
+ var A = f`
153
153
  const rerouteDeLocalize = (url: string) => {
154
154
  const [upath, locale] = deLocalizeDefault(url, locales);
155
155
  const { path } = matchUrl(upath, locale);
156
156
  return path ?? url;
157
157
  };
158
- `, A = d`
158
+ `, j = f`
159
159
  import { deLocalizeDefault } from 'wuchale/url';
160
160
  import { matchUrl } from '#locales/main.url.js';
161
161
  import { locales } from '#locales/data.js';
@@ -167,7 +167,7 @@ var k = d`
167
167
  };
168
168
 
169
169
  export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);
170
- `, j = d`
170
+ `, M = f`
171
171
  Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:
172
172
 
173
173
  import { deLocalizeDefault } from 'wuchale/url';
@@ -181,57 +181,57 @@ var k = d`
181
181
  };
182
182
 
183
183
  export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));
184
- `, M = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*negotiateReroute\(\s*url\.pathname\s*\)$/;
185
- function N(e) {
184
+ `, N = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*negotiateReroute\(\s*url\.pathname\s*\)$/;
185
+ function P(e) {
186
186
  return e.getFunction("reroute") ? !0 : e.getExportDeclarations().some((e) => e.getNamedExports().some((e) => (e.getAliasNode()?.getText() ?? e.getName()) === "reroute"));
187
187
  }
188
- function P(e) {
188
+ function F(e) {
189
189
  o(e, "wuchale/url", "deLocalizeDefault"), o(e, "#locales/main.url.js", "matchUrl"), o(e, "#locales/data.js", "locales");
190
190
  }
191
- function ee(e) {
192
- if (!g.existsSync(e)) return g.mkdirSync(_.dirname(e), { recursive: !0 }), g.writeFileSync(e, A + "\n"), {
191
+ function I(e) {
192
+ if (!_.existsSync(e)) return _.mkdirSync(v.dirname(e), { recursive: !0 }), _.writeFileSync(e, j + "\n"), {
193
193
  status: "success",
194
194
  changed: !0
195
195
  };
196
- if (g.readFileSync(e, "utf8").includes("rerouteDeLocalize")) return {
196
+ if (_.readFileSync(e, "utf8").includes("rerouteDeLocalize")) return {
197
197
  status: "success",
198
198
  changed: !1
199
199
  };
200
- let t = new v({
200
+ let t = new y({
201
201
  compilerOptions: { allowJs: !0 },
202
- manipulationSettings: { quoteKind: y.Single }
202
+ manipulationSettings: { quoteKind: b.Single }
203
203
  }).addSourceFileAtPath(e), n = t.getVariableDeclaration("reroute");
204
- if (!n) return N(t) ? {
204
+ if (!n) return P(t) ? {
205
205
  status: "failed",
206
- message: j
207
- } : (P(t), t.addStatements(`\n${k}\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`), s(t), t.saveSync(), {
206
+ message: M
207
+ } : (F(t), t.addStatements(`\n${A}\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`), s(t), t.saveSync(), {
208
208
  status: "success",
209
209
  changed: !0
210
210
  });
211
- if (!n.getFirstAncestorByKind(b.VariableStatement)?.hasExportKeyword()) return {
211
+ if (!n.getFirstAncestorByKind(x.VariableStatement)?.hasExportKeyword()) return {
212
212
  status: "failed",
213
- message: j
213
+ message: M
214
214
  };
215
215
  let r = n.getInitializer();
216
- if (!r || !M.test(r.getText())) return {
216
+ if (!r || !N.test(r.getText())) return {
217
217
  status: "failed",
218
- message: j
218
+ message: M
219
219
  };
220
- P(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))");
220
+ F(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))");
221
221
  let i = t.getVariableStatements().find((e) => e.getDeclarations().some((e) => e.getName() === "reroute"));
222
- return t.insertText(i.getStart(!0), `${k}\n\n`), s(t), t.saveSync(), {
222
+ return t.insertText(i.getStart(!0), `${A}\n\n`), s(t), t.saveSync(), {
223
223
  status: "success",
224
224
  changed: !0
225
225
  };
226
226
  }
227
227
  // src/patterns/enable/i18n/modifies/app-html.ts
228
- var F = "Add the sveltekit lang placeholder to the <html> tag:\n\n<html lang=\"%sveltekit.lang%\">", I = "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>";
229
- function L(e) {
230
- if (!g.existsSync(e)) return {
228
+ var L = "Add the sveltekit lang placeholder to the <html> tag:\n\n<html lang=\"%sveltekit.lang%\">", R = "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>";
229
+ function z(e) {
230
+ if (!_.existsSync(e)) return {
231
231
  status: "not-found",
232
- message: I
232
+ message: R
233
233
  };
234
- let t = g.readFileSync(e, "utf8");
234
+ let t = _.readFileSync(e, "utf8");
235
235
  if (t.includes("lang=\"%sveltekit.lang%\"") || t.includes("lang='%sveltekit.lang%'")) return {
236
236
  status: "success",
237
237
  changed: !1
@@ -239,76 +239,76 @@ function L(e) {
239
239
  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%\""));
240
240
  return n === t ? {
241
241
  status: "failed",
242
- message: F
243
- } : (g.writeFileSync(e, n), {
242
+ message: L
243
+ } : (_.writeFileSync(e, n), {
244
244
  status: "success",
245
245
  changed: !0
246
246
  });
247
247
  }
248
248
  // src/patterns/enable/i18n/modifies/gitignore.ts
249
- var R = "Create a .gitignore with the wuchale cache ignored:\n\n# Wuchale\nsrc/locales/.wuchale";
250
- function z(e) {
251
- if (!g.existsSync(e)) return {
249
+ var B = "Create a .gitignore with the wuchale cache ignored:\n\n# Wuchale\nsrc/locales/.wuchale";
250
+ function V(e) {
251
+ if (!_.existsSync(e)) return {
252
252
  status: "not-found",
253
- message: R
253
+ message: B
254
254
  };
255
- let t = g.readFileSync(e, "utf8");
255
+ let t = _.readFileSync(e, "utf8");
256
256
  if (t.includes("src/locales/.wuchale")) return {
257
257
  status: "success",
258
258
  changed: !1
259
259
  };
260
- let n = d`
260
+ let n = f`
261
261
  # Wuchale
262
262
  src/locales/.wuchale
263
263
  `, r = t + (t.length > 0 && !t.endsWith("\n") ? "\n" : "") + "\n" + n + "\n";
264
- return g.writeFileSync(e, r), {
264
+ return _.writeFileSync(e, r), {
265
265
  status: "success",
266
266
  changed: !0
267
267
  };
268
268
  }
269
269
  // src/patterns/enable/i18n/modifies/root-layout.svelte.ts
270
- var B = "<Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n ", V = "<LanguageSelect />", H = d`
270
+ var H = "<Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n ", U = "<LanguageSelect />", W = f`
271
271
  import LanguageSelect from '#lib/components/language-select.svelte';
272
- `, U = [
272
+ `, G = [
273
273
  "Add the language select inside your <Navbar.List> in the root layout.",
274
274
  "",
275
275
  "Import to add to the <script> tag:",
276
276
  "",
277
- H,
277
+ W,
278
278
  "",
279
279
  "Markup to add at the end of <Navbar.List>:",
280
- B
281
- ].join("\n"), W = [
280
+ H
281
+ ].join("\n"), K = [
282
282
  "Create a root layout that includes a language select inside <Navbar.List>.",
283
283
  "",
284
284
  "Import for the <script> tag:",
285
285
  "",
286
- H,
286
+ W,
287
287
  "",
288
288
  "Markup at the end of <Navbar.List>:",
289
- B
290
- ].join("\n"), G = [
289
+ H
290
+ ].join("\n"), q = [
291
291
  "Add the language select to your root layout.",
292
292
  "",
293
293
  "Import to add to the <script> tag:",
294
294
  "",
295
- H,
295
+ W,
296
296
  "",
297
297
  "Markup to add wherever it should render, e.g. above {@render children()}:",
298
298
  "",
299
- V
300
- ].join("\n"), K = [
299
+ U
300
+ ].join("\n"), J = [
301
301
  "Create a root layout that includes the language select.",
302
302
  "",
303
303
  "Import for the <script> tag:",
304
304
  "",
305
- H,
305
+ W,
306
306
  "",
307
307
  "Markup above {@render children()}:",
308
308
  "",
309
- V
309
+ U
310
310
  ].join("\n");
311
- function q(e) {
311
+ function Y(e) {
312
312
  e.modifyScript((e) => {
313
313
  let { source: t } = a(e, (e) => {
314
314
  c(e, [{
@@ -319,51 +319,51 @@ function q(e) {
319
319
  return t;
320
320
  });
321
321
  }
322
- function J(e, t = "shadcn") {
322
+ function ee(e, t = "shadcn") {
323
323
  let n = t === "plain";
324
- if (!g.existsSync(e)) return {
324
+ if (!_.existsSync(e)) return {
325
325
  status: "not-found",
326
- message: n ? K : W
326
+ message: n ? J : K
327
327
  };
328
- let r = p.fromPath(e);
328
+ let r = m.fromPath(e);
329
329
  return r.hasElement("LanguageSelect") ? {
330
330
  status: "success",
331
331
  changed: !1
332
- } : n ? !r.getScript() || !r.insertBeforeChildren(V) ? {
332
+ } : n ? !r.getScript() || !r.insertBeforeChildren(U) ? {
333
333
  status: "failed",
334
- message: G
335
- } : (q(r), r.writeTo(e), {
334
+ message: q
335
+ } : (Y(r), r.writeTo(e), {
336
336
  status: "success",
337
337
  changed: r.hasChanged()
338
- }) : r.hasElement("Navbar.List") ? (q(r), r.insertBeforeClosingTag("Navbar.List", B), r.writeTo(e), {
338
+ }) : r.hasElement("Navbar.List") ? (Y(r), r.insertBeforeClosingTag("Navbar.List", H), r.writeTo(e), {
339
339
  status: "success",
340
340
  changed: r.hasChanged()
341
341
  }) : {
342
342
  status: "failed",
343
- message: U
343
+ message: G
344
344
  };
345
345
  }
346
346
  // src/patterns/enable/i18n/welcome-catalog.ts
347
- var Y = "src/routes/+page.svelte", X = "src/locales/es.po", Z = "<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>", Q = [{
348
- reference: Y,
347
+ var X = "src/routes/+page.svelte", Z = "src/locales/es.po", te = "<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>", Q = [{
348
+ reference: X,
349
349
  msgid: "Welcome to SvelteKit",
350
350
  msgstr: "Bienvenido a SvelteKit"
351
351
  }, {
352
- reference: Y,
352
+ reference: X,
353
353
  msgid: "Visit <0>svelte.dev/docs/kit</0> to read the documentation",
354
354
  msgstr: "Visita <0>svelte.dev/docs/kit</0> para leer la documentación"
355
- }], te = {
355
+ }], ne = {
356
356
  reference: "src/lib/components/language-select.svelte",
357
357
  msgid: "Language",
358
358
  msgstr: "Idioma"
359
- }, ne = "msgid \"\"\nmsgstr \"\"\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\"", $ = (e) => e.replace(/\s+/g, "");
360
- function re(e, t) {
361
- if (g.existsSync(_.join(e, X))) return null;
362
- let n = _.join(e, Y);
363
- return !g.existsSync(n) || $(g.readFileSync(n, "utf8")) !== $(Z) ? null : {
364
- path: X,
359
+ }, re = "msgid \"\"\nmsgstr \"\"\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\"", $ = (e) => e.replace(/\s+/g, "");
360
+ function ie(e, t) {
361
+ if (_.existsSync(v.join(e, Z))) return null;
362
+ let n = v.join(e, X);
363
+ return !_.existsSync(n) || $(_.readFileSync(n, "utf8")) !== $(te) ? null : {
364
+ path: Z,
365
365
  language: "text",
366
- content: [ne, ...(t === "plain" ? [...Q, te] : Q).map((e) => [
366
+ content: [re, ...(t === "plain" ? [...Q, ne] : Q).map((e) => [
367
367
  `#: ${e.reference}`,
368
368
  `msgid "${e.msgid}"`,
369
369
  `msgstr "${e.msgstr}"`
@@ -372,46 +372,48 @@ function re(e, t) {
372
372
  };
373
373
  }
374
374
  // src/patterns/enable/i18n/generate.runtime.ts
375
- function ie(e, t) {
376
- let n = h.filter((t) => g.existsSync(_.join(e, t)));
375
+ function ae(e, t) {
376
+ let n = g.filter((t) => _.existsSync(v.join(e, t)));
377
377
  return n.length === 0 ? t : t.map((e) => {
378
378
  if (!e.path.endsWith("wuchale.config.js")) return e;
379
- let t = m(e.content, n);
379
+ let t = h(e.content, n);
380
380
  return t?.changed ? {
381
381
  ...e,
382
382
  content: t.source
383
383
  } : e;
384
384
  });
385
385
  }
386
- async function ae(a) {
386
+ async function oe(a) {
387
387
  let o = e(a), s = [], c = (e) => {
388
388
  e && s.push(e);
389
389
  };
390
390
  o.info("Modifying vite.config");
391
- let d = r(a.root, i) ?? _.join(a.root, i[0]);
392
- c(n(d, C(d))), o.info("Adding #locales to package.json imports");
393
- let f = l(a.root);
394
- c(n(f.filePath, f.outcome)), o.info("Modifying hooks.server.ts");
395
- let p = _.join(a.root, "src", "hooks.server.ts");
396
- c(n(p, O(p))), o.info("Modifying hooks.ts");
397
- let m = _.join(a.root, "src", "hooks.ts");
398
- c(n(m, ee(m))), o.info("Modifying app.html");
399
- let h = _.join(a.root, "src", "app.html");
400
- c(n(h, L(h))), o.info("Modifying root +layout.ts");
401
- let v = _.join(a.root, "src", "routes", "+layout.ts");
402
- c(n(v, u(v))), o.info("Modifying root layout language select");
403
- let y = [
404
- _.join(a.root, "src", "routes", "(public)", "root-layout.svelte"),
405
- _.join(a.root, "src", "routes", "root-layout.svelte"),
406
- _.join(a.root, "src", "routes", "(public)", "+layout.svelte"),
407
- _.join(a.root, "src", "routes", "+layout.svelte")
408
- ], b = t(a), x = y.find((e) => g.existsSync(e)) ?? (b === "plain" ? y[3] : y[0]);
409
- c(n(x, J(x, b))), o.info("Updating .gitignore");
410
- let S = _.join(a.root, ".gitignore");
411
- c(n(S, z(S)));
412
- let w = re(a.root, b);
413
- return w && o.info("Translating the welcome page into Spanish"), {
414
- creates: w ? [w] : [],
391
+ let f = r(a.root, i) ?? v.join(a.root, i[0]);
392
+ c(n(f, w(f))), o.info("Adding #locales to package.json imports");
393
+ let p = l(a.root);
394
+ c(n(p.filePath, p.outcome)), o.info("Modifying hooks.server.ts");
395
+ let m = v.join(a.root, "src", "hooks.server.ts");
396
+ c(n(m, k(m))), o.info("Modifying hooks.ts");
397
+ let h = v.join(a.root, "src", "hooks.ts");
398
+ c(n(h, I(h))), o.info("Modifying app.html");
399
+ let g = v.join(a.root, "src", "app.html");
400
+ c(n(g, z(g))), o.info("Modifying root +layout.ts");
401
+ let y = v.join(a.root, "src", "routes", "+layout.ts");
402
+ c(n(y, u(y))), o.info("Modifying root layout language select");
403
+ let b = [
404
+ v.join(a.root, "src", "routes", "(public)", "root-layout.svelte"),
405
+ v.join(a.root, "src", "routes", "root-layout.svelte"),
406
+ v.join(a.root, "src", "routes", "(public)", "+layout.svelte"),
407
+ v.join(a.root, "src", "routes", "+layout.svelte")
408
+ ], x = t(a), S = b.find((e) => _.existsSync(e)) ?? (x === "plain" ? b[3] : b[0]);
409
+ c(n(S, ee(S, x))), o.info("Updating .gitignore");
410
+ let C = v.join(a.root, ".gitignore");
411
+ c(n(C, V(C))), o.info("Updating .prettierignore");
412
+ let T = v.join(a.root, ".prettierignore");
413
+ c(n(T, d(T)));
414
+ let E = ie(a.root, x);
415
+ return E && o.info("Translating the welcome page into Spanish"), {
416
+ creates: E ? [E] : [],
415
417
  modifies: s,
416
418
  deletes: [],
417
419
  components: [],
@@ -421,6 +423,6 @@ async function ae(a) {
421
423
  collectionDrops: []
422
424
  };
423
425
  }
424
- export { ae as generate, ie as withLibraryTexts };
426
+ export { oe as generate, ae as withLibraryTexts };
425
427
 
426
- //# sourceMappingURL=generate.runtime-DvTbN-no.js.map
428
+ //# sourceMappingURL=generate.runtime-Dfl-07VS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-Dfl-07VS.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","FAILURE_HINT","NOT_FOUND_HINT","NOT_FOUND_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","withInMemoryScript","ensureNamedImport","formatLikeSource","ensureImports","modifyPackageImportsI18n","ensureRootLayoutI18n","modifyPrettierignore","dedent","addHandle","SvelteFile","withWuchaleJsFiles","TRANSLATED_LIB_FILES","fs","path","FAILURE_HINT$4","NOT_FOUND_HINT$3","modifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","el","I18N_HANDLE","FAILURE_HINT$3","HOOKS_SERVER_SNIPPET","ensureNamespaceImport","moduleSpecifier","ns","modifyHooksServerI18n","hooksServerPath","original","composed","handleStmt","startupSnippet","i18nHandleSnippet","DELOCALIZE_HELPER","HOOKS_SNIPPET","FAILURE_HINT$2","NEGOTIATE_ONLY_REROUTE","hasOtherReroute","n","ensureDeLocalizeImports","modifyHooksI18n","hooksPath","rerouteDecl","init","target","s","FAILURE_HINT$1","NOT_FOUND_HINT$2","modifyAppHtml","appHtmlPath","updated","match","NOT_FOUND_HINT$1","modifyGitignore","gitignorePath","block","LANGUAGE_SELECT_SNIPPET","PLAIN_LANGUAGE_SELECT_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","PLAIN_FAILURE_HINT","PLAIN_NOT_FOUND_HINT","addImport","out","source","sf","modifyRootLayoutLanguageSelect","plain","ui","layoutPath","file","PAGE_PATH","CATALOG_PATH","WELCOME_PAGE","PAGE_ENTRIES","PLAIN_SELECT_ENTRY","HEADER","normalize","welcomePageCatalog","root","pagePath","entry","withLibraryTexts","present","creates","edited","generate","logger","options","modifies","pushResult","imports","rootLayoutCandidates","resolveUi","rootLayoutPath","p","prettierignorePath","catalog"],"sources":["../../src/patterns/enable/i18n/modifies/vite-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 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.js';\n import { locales } from '#locales/data.js';\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/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\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.js\", \"getLocale\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"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.js';\n import { locales } from '#locales/data.js';\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.js';\n import { locales } from '#locales/data.js';\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.js\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"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 { modifyPackageImportsI18n } from \"./modifies/package-imports\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyPrettierignore } from \"./modifies/prettierignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\nimport {\n TRANSLATED_LIB_FILES,\n withWuchaleJsFiles,\n} from \"../../../runtime/wuchale-config\";\n\n/**\n * The `wuchale.config.js` create, with the library modules that carry\n * visitor-facing text and already exist in the project (the WhatsApp order\n * message, say) listed for the js adapter. A pattern enabled later adds its\n * own module to the written config.\n */\nexport function withLibraryTexts(root: string, creates: File[]): File[] {\n const present = TRANSLATED_LIB_FILES.filter((file) =>\n fs.existsSync(path.join(root, file)),\n );\n if (present.length === 0) return creates;\n return creates.map((file) => {\n if (!file.path.endsWith(\"wuchale.config.js\")) return file;\n const edited = withWuchaleJsFiles(file.content, present);\n return edited?.changed ? { ...file, content: edited.source } : file;\n });\n}\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(\"Adding #locales to package.json imports\");\n const imports = modifyPackageImportsI18n(options.root);\n pushResult(modifyOutcomeToFile(imports.filePath, imports.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 logger.info(\"Updating .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n modifyPrettierignore(prettierignorePath),\n ),\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,IAAMA,IAAe,oLAUfC,IAAiB;AAWvB,SAAgB0B,EAAiB,GAAuC;CACtE,IAAI,CAACJ,EAAG,WAAWK,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS3B;CAAe;CAOxD,IAAM4B,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBH,CAAc,GAEzDI,IAAU,IACVC,IAAS;CAMb,AAJkBJ,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAMK,EAAE,wBAAwB,MAAM,cAE1C,MACHL,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,CAAC,GACD,IAAU;CAOZ,IAAMM,IAJmBN,EACtB,qBAAqBO,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,cAE/B,CAAA,EAAkB,aAAa,CAAC,GAAG,IAC/CC,IACJH,GAAW,QAAQ,MAAMC,EAAW,0BAC/BD,IACD;CAEN,IAAI,CAACG,GACH,IAAS;MACJ;EACL,IAAMC,IAAcD,EAAU,YAAY,SAAS;EACnD,IAAI,CAACC,GAKH,AAJAD,EAAU,sBAAsB;GAC9B,MAAM;GACN,aAAa;EACf,CAAC,GACD,IAAU;OACL,IAAIC,EAAY,QAAQ,MAAMH,EAAW,oBAC9C,IAAS;OACJ;GACL,IAAMI,IACJD,EACA,eAAe;GAEjB,IAA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