@velastack/patterns 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +44 -2
  2. package/dist/chunks/_layout-kkgN0IF7.js +62 -0
  3. package/dist/chunks/_layout-kkgN0IF7.js.map +1 -0
  4. package/dist/chunks/{collections-CrOvS2E7.js → collections-Dz2fvKnz.js} +2 -2
  5. package/dist/chunks/{collections-CrOvS2E7.js.map → collections-Dz2fvKnz.js.map} +1 -1
  6. package/dist/chunks/{compose-handle-B-CkDcQD.js → compose-handle-D_Rz3Fzo.js} +10 -4
  7. package/dist/chunks/compose-handle-D_Rz3Fzo.js.map +1 -0
  8. package/dist/chunks/{config-target-Bln26FJe.js → config-target-Dx3w6WSk.js} +59 -70
  9. package/dist/chunks/config-target-Dx3w6WSk.js.map +1 -0
  10. package/dist/chunks/constants-BjyMU5s8.js +6 -0
  11. package/dist/chunks/constants-BjyMU5s8.js.map +1 -0
  12. package/dist/chunks/dispatch-CXOXPLFk.js +6 -0
  13. package/dist/chunks/dispatch-CXOXPLFk.js.map +1 -0
  14. package/dist/chunks/env-vars-C1NUX-bf.js +268 -0
  15. package/dist/chunks/env-vars-C1NUX-bf.js.map +1 -0
  16. package/dist/chunks/env-vars-Cr4lbMD_.js +21 -0
  17. package/dist/chunks/env-vars-Cr4lbMD_.js.map +1 -0
  18. package/dist/chunks/env-vars-De0Xs0L2.js +20 -0
  19. package/dist/chunks/env-vars-De0Xs0L2.js.map +1 -0
  20. package/dist/chunks/env-vars-file-B_6esJW3.js +34 -0
  21. package/dist/chunks/env-vars-file-B_6esJW3.js.map +1 -0
  22. package/dist/chunks/env-vars-mnRA0hOe.js +19 -0
  23. package/dist/chunks/env-vars-mnRA0hOe.js.map +1 -0
  24. package/dist/chunks/generate-BW3l5Fxw.js +252 -0
  25. package/dist/chunks/{generate-Ca_6FlPi.js.map → generate-BW3l5Fxw.js.map} +1 -1
  26. package/dist/chunks/{generate-CyuY2Ci7.js → generate-DeaBlnK6.js} +25 -24
  27. package/dist/chunks/generate-DeaBlnK6.js.map +1 -0
  28. package/dist/chunks/generate-DetW_gbr.js +68 -0
  29. package/dist/chunks/generate-DetW_gbr.js.map +1 -0
  30. package/dist/chunks/{generate-DwADTUob.js → generate-Gcc8iRkZ.js} +9 -6
  31. package/dist/chunks/{generate-DwADTUob.js.map → generate-Gcc8iRkZ.js.map} +1 -1
  32. package/dist/chunks/{generate-DQeWOEPY.js → generate-WMJo3QGZ.js} +9 -6
  33. package/dist/chunks/generate-WMJo3QGZ.js.map +1 -0
  34. package/dist/chunks/generate.runtime-1-91UmM8.js +85 -0
  35. package/dist/chunks/generate.runtime-1-91UmM8.js.map +1 -0
  36. package/dist/chunks/generate.runtime-6FXJM8hT.js +67 -0
  37. package/dist/chunks/generate.runtime-6FXJM8hT.js.map +1 -0
  38. package/dist/chunks/generate.runtime-B1jVAnDI.js +155 -0
  39. package/dist/chunks/generate.runtime-B1jVAnDI.js.map +1 -0
  40. package/dist/chunks/generate.runtime-BA3tDKnn.js +147 -0
  41. package/dist/chunks/generate.runtime-BA3tDKnn.js.map +1 -0
  42. package/dist/chunks/{generate.runtime-4FDxnvCl.js → generate.runtime-BO778G0r.js} +5 -5
  43. package/dist/chunks/{generate.runtime-4FDxnvCl.js.map → generate.runtime-BO778G0r.js.map} +1 -1
  44. package/dist/chunks/{generate.runtime-D1DNAY6k.js → generate.runtime-BXkZob1O.js} +8 -8
  45. package/dist/chunks/generate.runtime-BXkZob1O.js.map +1 -0
  46. package/dist/chunks/{generate.runtime-Um77JfwC.js → generate.runtime-B_UVGa3q.js} +7 -7
  47. package/dist/chunks/{generate.runtime-Um77JfwC.js.map → generate.runtime-B_UVGa3q.js.map} +1 -1
  48. package/dist/chunks/{generate.runtime-FdZw277n.js → generate.runtime-C6bSvGMb.js} +108 -142
  49. package/dist/chunks/generate.runtime-C6bSvGMb.js.map +1 -0
  50. package/dist/chunks/generate.runtime-C8zJRNYG.js +124 -0
  51. package/dist/chunks/generate.runtime-C8zJRNYG.js.map +1 -0
  52. package/dist/chunks/{generate.runtime-BKiJvE8I.js → generate.runtime-CA7Ofjlx.js} +104 -100
  53. package/dist/chunks/generate.runtime-CA7Ofjlx.js.map +1 -0
  54. package/dist/chunks/generate.runtime-CCr1lvo4.js +43 -0
  55. package/dist/chunks/generate.runtime-CCr1lvo4.js.map +1 -0
  56. package/dist/chunks/generate.runtime-CYagyR5c.js +326 -0
  57. package/dist/chunks/generate.runtime-CYagyR5c.js.map +1 -0
  58. package/dist/chunks/{generate.runtime-n9AFWtPp.js → generate.runtime-Ce_rwzNa.js} +4 -4
  59. package/dist/chunks/{generate.runtime-n9AFWtPp.js.map → generate.runtime-Ce_rwzNa.js.map} +1 -1
  60. package/dist/chunks/{generate.runtime-cQGLxuZM.js → generate.runtime-CexC1Oky.js} +4 -4
  61. package/dist/chunks/{generate.runtime-cQGLxuZM.js.map → generate.runtime-CexC1Oky.js.map} +1 -1
  62. package/dist/chunks/{generate.runtime-AYQVW1S-.js → generate.runtime-CnPraLKv.js} +35 -31
  63. package/dist/chunks/generate.runtime-CnPraLKv.js.map +1 -0
  64. package/dist/chunks/generate.runtime-CslAvllQ.js +112 -0
  65. package/dist/chunks/generate.runtime-CslAvllQ.js.map +1 -0
  66. package/dist/chunks/{generate.runtime-onBnOiS7.js → generate.runtime-CuNhY5hn.js} +10 -10
  67. package/dist/chunks/generate.runtime-CuNhY5hn.js.map +1 -0
  68. package/dist/chunks/{generate.runtime-B45MvtYm.js → generate.runtime-DD51OSuL.js} +14 -14
  69. package/dist/chunks/generate.runtime-DD51OSuL.js.map +1 -0
  70. package/dist/chunks/generate.runtime-DHBRyMAq.js +65 -0
  71. package/dist/chunks/generate.runtime-DHBRyMAq.js.map +1 -0
  72. package/dist/chunks/generate.runtime-DV3WmZtb.js +35 -0
  73. package/dist/chunks/generate.runtime-DV3WmZtb.js.map +1 -0
  74. package/dist/chunks/generate.runtime-D_sQOeQa.js +164 -0
  75. package/dist/chunks/generate.runtime-D_sQOeQa.js.map +1 -0
  76. package/dist/chunks/{generate.runtime-ofdnLtxS.js → generate.runtime-DqD3PW-W.js} +3 -3
  77. package/dist/chunks/{generate.runtime-ofdnLtxS.js.map → generate.runtime-DqD3PW-W.js.map} +1 -1
  78. package/dist/chunks/{generate.runtime-VgVwRiiN.js → generate.runtime-Dtgw9IQO.js} +8 -8
  79. package/dist/chunks/generate.runtime-Dtgw9IQO.js.map +1 -0
  80. package/dist/chunks/{generate.runtime-CN5c2xH8.js → generate.runtime-IlBCcXvv.js} +14 -14
  81. package/dist/chunks/generate.runtime-IlBCcXvv.js.map +1 -0
  82. package/dist/chunks/{generate.runtime-BSRFv4cJ.js → generate.runtime-cwvAoKoH.js} +3 -3
  83. package/dist/chunks/{generate.runtime-BSRFv4cJ.js.map → generate.runtime-cwvAoKoH.js.map} +1 -1
  84. package/dist/chunks/{generate.runtime-DG-3G00z.js → generate.runtime-kvxmTlQb.js} +3 -3
  85. package/dist/chunks/{generate.runtime-DG-3G00z.js.map → generate.runtime-kvxmTlQb.js.map} +1 -1
  86. package/dist/chunks/generate.runtime-pVLzzpUM.js +122 -0
  87. package/dist/chunks/generate.runtime-pVLzzpUM.js.map +1 -0
  88. package/dist/chunks/{generate.runtime-BFOXm2DD.js → generate.runtime-zJpEufTc.js} +10 -10
  89. package/dist/chunks/generate.runtime-zJpEufTc.js.map +1 -0
  90. package/dist/chunks/lib-specifier-Cngo1zF_.js +33 -0
  91. package/dist/chunks/lib-specifier-Cngo1zF_.js.map +1 -0
  92. package/dist/chunks/{modify-file-Dwfv0dCI.js → modify-file-BlDeeurK.js} +3 -3
  93. package/dist/chunks/{modify-file-Dwfv0dCI.js.map → modify-file-BlDeeurK.js.map} +1 -1
  94. package/dist/chunks/{modify-svelte-config-remote-BUU_EaDf.js → modify-svelte-config-remote-p0TfVzxm.js} +8 -10
  95. package/dist/chunks/modify-svelte-config-remote-p0TfVzxm.js.map +1 -0
  96. package/dist/chunks/nav-user-BRIHOOpG.js +6 -0
  97. package/dist/chunks/nav-user-BRIHOOpG.js.map +1 -0
  98. package/dist/chunks/package-imports-Bbw3iMPg.js +173 -0
  99. package/dist/chunks/package-imports-Bbw3iMPg.js.map +1 -0
  100. package/dist/chunks/{pocketbase-BkhUywtb.js → pocketbase-Dry6ry17.js} +2 -2
  101. package/dist/chunks/{pocketbase-BkhUywtb.js.map → pocketbase-Dry6ry17.js.map} +1 -1
  102. package/dist/chunks/{providers-BL9vJP_9.js → providers-BHR6-XZ7.js} +11 -4
  103. package/dist/chunks/providers-BHR6-XZ7.js.map +1 -0
  104. package/dist/chunks/{shared-C8GtNxpm.js → shared-CZC4d7Uj.js} +2 -2
  105. package/dist/chunks/{shared-C8GtNxpm.js.map → shared-CZC4d7Uj.js.map} +1 -1
  106. package/dist/chunks/{site-BdMX8qrH.js → site-BwCA18Sv.js} +2 -2
  107. package/dist/chunks/{site-BdMX8qrH.js.map → site-BwCA18Sv.js.map} +1 -1
  108. package/dist/chunks/table-core-AjBpYi-y.js +127 -0
  109. package/dist/chunks/table-core-AjBpYi-y.js.map +1 -0
  110. package/dist/chunks/{test-setup-DHEFKEHE.js → test-setup-DEmWd9Ul.js} +76 -67
  111. package/dist/chunks/test-setup-DEmWd9Ul.js.map +1 -0
  112. package/dist/chunks/{ts-morph-helpers-CeduA--o.js → ts-morph-helpers-CDW4lhox.js} +77 -63
  113. package/dist/chunks/ts-morph-helpers-CDW4lhox.js.map +1 -0
  114. package/dist/chunks/ui-DD4NltyN.js.map +1 -1
  115. package/dist/chunks/{ui-TlEuI2Sz.js → ui-X698F10c.js} +47 -47
  116. package/dist/chunks/{ui-TlEuI2Sz.js.map → ui-X698F10c.js.map} +1 -1
  117. package/dist/chunks/{unmodify-load-jfdcVZ_a.js → unmodify-load-CyGzC1Hu.js} +2 -2
  118. package/dist/chunks/{unmodify-load-jfdcVZ_a.js.map → unmodify-load-CyGzC1Hu.js.map} +1 -1
  119. package/dist/chunks/write-result-B68lvI57.js +511 -0
  120. package/dist/chunks/write-result-B68lvI57.js.map +1 -0
  121. package/dist/index.d.ts +224 -1
  122. package/dist/index.js +2121 -2064
  123. package/dist/index.js.map +1 -1
  124. package/package.json +7 -7
  125. package/dist/chunks/_layout-B7ujvjnA.js +0 -55
  126. package/dist/chunks/_layout-B7ujvjnA.js.map +0 -1
  127. package/dist/chunks/compose-handle-B-CkDcQD.js.map +0 -1
  128. package/dist/chunks/config-target-Bln26FJe.js.map +0 -1
  129. package/dist/chunks/constants-BYkd9jeJ.js +0 -6
  130. package/dist/chunks/constants-BYkd9jeJ.js.map +0 -1
  131. package/dist/chunks/dispatch-BRnt8PcW.js +0 -6
  132. package/dist/chunks/dispatch-BRnt8PcW.js.map +0 -1
  133. package/dist/chunks/generate-6snrlnpA.js +0 -64
  134. package/dist/chunks/generate-6snrlnpA.js.map +0 -1
  135. package/dist/chunks/generate-Ca_6FlPi.js +0 -252
  136. package/dist/chunks/generate-CyuY2Ci7.js.map +0 -1
  137. package/dist/chunks/generate-DQeWOEPY.js.map +0 -1
  138. package/dist/chunks/generate.runtime-AYQVW1S-.js.map +0 -1
  139. package/dist/chunks/generate.runtime-B2aFFaac.js +0 -117
  140. package/dist/chunks/generate.runtime-B2aFFaac.js.map +0 -1
  141. package/dist/chunks/generate.runtime-B45MvtYm.js.map +0 -1
  142. package/dist/chunks/generate.runtime-BFOXm2DD.js.map +0 -1
  143. package/dist/chunks/generate.runtime-BHkFmI2Y.js +0 -146
  144. package/dist/chunks/generate.runtime-BHkFmI2Y.js.map +0 -1
  145. package/dist/chunks/generate.runtime-BKiJvE8I.js.map +0 -1
  146. package/dist/chunks/generate.runtime-BUqsF3AF.js +0 -123
  147. package/dist/chunks/generate.runtime-BUqsF3AF.js.map +0 -1
  148. package/dist/chunks/generate.runtime-BsaSyTnU.js +0 -82
  149. package/dist/chunks/generate.runtime-BsaSyTnU.js.map +0 -1
  150. package/dist/chunks/generate.runtime-CMnvmeVt.js +0 -111
  151. package/dist/chunks/generate.runtime-CMnvmeVt.js.map +0 -1
  152. package/dist/chunks/generate.runtime-CN5c2xH8.js.map +0 -1
  153. package/dist/chunks/generate.runtime-CgoSrP55.js +0 -146
  154. package/dist/chunks/generate.runtime-CgoSrP55.js.map +0 -1
  155. package/dist/chunks/generate.runtime-D1DNAY6k.js.map +0 -1
  156. package/dist/chunks/generate.runtime-DQwSY6Nc.js +0 -38
  157. package/dist/chunks/generate.runtime-DQwSY6Nc.js.map +0 -1
  158. package/dist/chunks/generate.runtime-D_yqWLcI.js +0 -66
  159. package/dist/chunks/generate.runtime-D_yqWLcI.js.map +0 -1
  160. package/dist/chunks/generate.runtime-Drmahmdl.js +0 -313
  161. package/dist/chunks/generate.runtime-Drmahmdl.js.map +0 -1
  162. package/dist/chunks/generate.runtime-FdZw277n.js.map +0 -1
  163. package/dist/chunks/generate.runtime-Lh1cW9Tz.js +0 -94
  164. package/dist/chunks/generate.runtime-Lh1cW9Tz.js.map +0 -1
  165. package/dist/chunks/generate.runtime-QGHToXRY.js +0 -32
  166. package/dist/chunks/generate.runtime-QGHToXRY.js.map +0 -1
  167. package/dist/chunks/generate.runtime-VgVwRiiN.js.map +0 -1
  168. package/dist/chunks/generate.runtime-YyIVd4oy.js +0 -61
  169. package/dist/chunks/generate.runtime-YyIVd4oy.js.map +0 -1
  170. package/dist/chunks/generate.runtime-onBnOiS7.js.map +0 -1
  171. package/dist/chunks/modify-svelte-config-remote-BUU_EaDf.js.map +0 -1
  172. package/dist/chunks/nav-user-BYI-h8Od.js +0 -6
  173. package/dist/chunks/nav-user-BYI-h8Od.js.map +0 -1
  174. package/dist/chunks/providers-BL9vJP_9.js.map +0 -1
  175. package/dist/chunks/table-core-G9Shld4F.js +0 -126
  176. package/dist/chunks/table-core-G9Shld4F.js.map +0 -1
  177. package/dist/chunks/test-setup-DHEFKEHE.js.map +0 -1
  178. package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +0 -1
  179. package/dist/chunks/write-result-Djy0SZXX.js +0 -376
  180. package/dist/chunks/write-result-Djy0SZXX.js.map +0 -1
@@ -1,313 +0,0 @@
1
- import { t as e } from "./dedent-Gq6Krl4n.js";
2
- import { n as t } from "./logger-CQONztPm.js";
3
- import { _ as n, c as r, d as i, h as a, m as o, n as s, o as c, s as l, u } from "./ts-morph-helpers-CeduA--o.js";
4
- import { modifyOutcomeToFile as d, revertOutcomeToFile as f } from "./modify-file-Dwfv0dCI.js";
5
- import { t as p } from "./svelte-file-B3RfgVdt.js";
6
- import { n as m } from "./compose-handle-B-CkDcQD.js";
7
- import { a as h, i as g, t as _ } from "./config-target-Bln26FJe.js";
8
- import { t as v } from "./_layout-B7ujvjnA.js";
9
- import y from "node:fs";
10
- import b from "node:path";
11
- import { Project as x, QuoteKind as S, SyntaxKind as C } from "ts-morph";
12
- //#region src/patterns/disable/i18n/modifies/gitignore.ts
13
- function w(e) {
14
- if (!y.existsSync(e)) return {
15
- status: "success",
16
- changed: !1
17
- };
18
- let t = y.readFileSync(e, "utf8");
19
- if (!t.includes("src/locales/.wuchale")) return {
20
- status: "success",
21
- changed: !1
22
- };
23
- let n = t.split("\n"), r = [];
24
- for (let e = 0; e < n.length; e++) {
25
- let t = n[e];
26
- if (t === "# Wuchale") {
27
- let t = e + 1, r = !1;
28
- for (; t < n.length && n[t].trim() !== "";) n[t] === "src/locales/.wuchale" && (r = !0), t++;
29
- if (r) {
30
- e = t;
31
- continue;
32
- }
33
- }
34
- t !== "src/locales/.wuchale" && r.push(t);
35
- }
36
- let i = r.join("\n");
37
- return i = i.replace(/\n{3,}/g, "\n\n"), i === t ? {
38
- status: "success",
39
- changed: !1
40
- } : (y.writeFileSync(e, i), {
41
- status: "success",
42
- changed: !0
43
- });
44
- }
45
- //#endregion
46
- //#region src/patterns/disable/i18n/modifies/vite-config.ts
47
- function T(e) {
48
- if (!y.existsSync(e)) return {
49
- status: "success",
50
- changed: !1
51
- };
52
- let t = y.readFileSync(e, "utf8");
53
- if (!t.includes("wuchale")) return {
54
- status: "success",
55
- changed: !1
56
- };
57
- let n = new x({
58
- compilerOptions: { allowJs: !0 },
59
- manipulationSettings: { quoteKind: S.Single }
60
- }).addSourceFileAtPath(e);
61
- for (;;) {
62
- let e = !1;
63
- for (let t of n.getDescendantsOfKind(C.ArrayLiteralExpression)) {
64
- let n = t.getElements().findIndex((e) => e.getText().replace(/\s/g, "") === "wuchale()");
65
- if (n >= 0) {
66
- t.removeElement(n), e = !0;
67
- break;
68
- }
69
- }
70
- if (!e) break;
71
- }
72
- return u(n, "wuchale/vite"), c(n), n.saveSync(), {
73
- status: "success",
74
- changed: n.getFullText() !== t
75
- };
76
- }
77
- //#endregion
78
- //#region src/patterns/disable/i18n/modifies/svelte-config.ts
79
- var E = {
80
- notFound: "No SvelteKit config to revert.",
81
- failed: "Remove the $locales alias from the kit config by hand."
82
- };
83
- function D(e) {
84
- let t = g(e, E, (e) => {
85
- let t = e.kitContainer();
86
- if (!t) return !0;
87
- let n = t.getProperty("alias");
88
- if (!n || n.getKind() !== C.PropertyAssignment) return !0;
89
- let r = n.getInitializer();
90
- if (!r || r.getKind() !== C.ObjectLiteralExpression) return !0;
91
- let i = r.asKindOrThrow(C.ObjectLiteralExpression), a = i.getProperties().find((e) => e.getText().replace(/['"]/g, "").startsWith("$locales"));
92
- return !a || (a.remove(), i.getProperties().length === 0 && n.remove(), !0);
93
- });
94
- return t.outcome.status === "not-found" ? {
95
- ...t,
96
- outcome: {
97
- status: "success",
98
- changed: !1
99
- }
100
- } : t;
101
- }
102
- //#endregion
103
- //#region src/patterns/disable/i18n/modifies/hooks.server.ts
104
- var O = "handleWuchale", k = e`
105
- Take handleWuchale out of the exported handle in src/hooks.server.ts, then
106
- remove its declaration, the loadLocales(...) calls and the wuchale and
107
- $locales imports.
108
- `, A = [
109
- "wuchale/load-utils/server",
110
- "$locales/main.url",
111
- "$locales/data",
112
- "$locales/main.loader.server.svelte.js",
113
- "$locales/js.loader.server.js"
114
- ];
115
- function j(e) {
116
- if (!y.existsSync(e)) return {
117
- status: "success",
118
- changed: !1
119
- };
120
- let t = y.readFileSync(e, "utf8");
121
- if (!t.includes(O) && !t.includes("loadLocales(")) return {
122
- status: "success",
123
- changed: !1
124
- };
125
- let n = new x({
126
- compilerOptions: { allowJs: !0 },
127
- manipulationSettings: { quoteKind: S.Single }
128
- }).addSourceFileAtPath(e);
129
- for (;;) {
130
- let e = n.getStatements().find((e) => e.getKind() === C.ExpressionStatement && /^loadLocales\s*\(/.test(e.getText()));
131
- if (!e) break;
132
- e.remove();
133
- }
134
- if (m(n, O).status === "unsupported") return {
135
- status: "failed",
136
- message: k
137
- };
138
- a(n, O);
139
- for (let e of A) u(n, e);
140
- return i(n, "@sveltejs/kit/hooks", "sequence"), i(n, "@sveltejs/kit", "Handle"), c(n), s(n), n.saveSync(), {
141
- status: "success",
142
- changed: n.getFullText() !== t
143
- };
144
- }
145
- //#endregion
146
- //#region src/patterns/disable/i18n/modifies/hooks.ts
147
- var M = "rerouteDeLocalize", N = e`
148
- Take rerouteDeLocalize out of the exported reroute in src/hooks.ts, then
149
- remove its declaration and the wuchale and $locales imports.
150
- `, P = [
151
- "wuchale/url",
152
- "$locales/main.url",
153
- "$locales/data"
154
- ], F = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*rerouteDeLocalize\(\s*url\.pathname\s*\)$/, I = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*rerouteDeLocalize\(\s*negotiateReroute\(\s*url\.pathname\s*\)\s*\)$/;
155
- function L(e) {
156
- if (!y.existsSync(e)) return {
157
- status: "success",
158
- changed: !1
159
- };
160
- let t = y.readFileSync(e, "utf8");
161
- if (!t.includes(M)) return {
162
- status: "success",
163
- changed: !1
164
- };
165
- let n = new x({
166
- compilerOptions: { allowJs: !0 },
167
- manipulationSettings: { quoteKind: S.Single }
168
- }).addSourceFileAtPath(e), i = n.getVariableDeclaration(M)?.getFirstAncestorByKind(C.VariableStatement), o = n.getVariableDeclaration("reroute"), u = o?.getInitializer()?.getText() ?? "", d = I.test(u), f = d || F.test(u) ? o?.getFirstAncestorByKind(C.VariableStatement) : void 0;
169
- return n.getStatements().filter((e) => e !== i && e !== f && e.getText().includes(M)).length > 0 ? {
170
- status: "failed",
171
- message: N
172
- } : (d ? o?.setInitializer("({ url }) => negotiateReroute(url.pathname)") : f && a(n, "reroute"), a(n, M), r(n, P), l(n) ? (y.writeFileSync(e, "", "utf8"), {
173
- status: "success",
174
- changed: !0
175
- }) : (c(n), s(n), n.saveSync(), {
176
- status: "success",
177
- changed: n.getFullText() !== t
178
- }));
179
- }
180
- //#endregion
181
- //#region src/patterns/disable/i18n/modifies/app-html.ts
182
- function R(e) {
183
- if (!y.existsSync(e)) return {
184
- status: "success",
185
- changed: !1
186
- };
187
- let t = y.readFileSync(e, "utf8"), n = t.replace(/lang\s*=\s*(?:"%sveltekit\.lang%"|'%sveltekit\.lang%')/g, "lang=\"en\"");
188
- return n === t ? {
189
- status: "success",
190
- changed: !1
191
- } : (y.writeFileSync(e, n, "utf8"), {
192
- status: "success",
193
- changed: !0
194
- });
195
- }
196
- //#endregion
197
- //#region src/patterns/disable/i18n/modifies/+layout.ts
198
- var z = e`
199
- src/routes/+layout.ts still loads wuchale locales. Remove these from it:
200
-
201
- import { browser } from '$app/environment';
202
- import { loadLocale } from 'wuchale/load-utils';
203
- import { getLocale } from '$locales/main.url';
204
- import '$locales/main.loader.svelte';
205
- import '$locales/js.loader';
206
-
207
- and the loadLocale(...) call inside load().
208
- `, B = ["$locales/main.loader.svelte", "$locales/js.loader"], V = [
209
- "$app/environment",
210
- "wuchale/load-utils",
211
- "$locales/main.url"
212
- ];
213
- function H(e) {
214
- return e.replace(/["']/g, "'").replace(/\s+/g, "");
215
- }
216
- function U(e) {
217
- if (!y.existsSync(e)) return {
218
- status: "success",
219
- changed: !1
220
- };
221
- let t = y.readFileSync(e, "utf8");
222
- if (!t.includes("loadLocale") && !t.includes("$locales")) return {
223
- status: "success",
224
- changed: !1
225
- };
226
- let n = new x({
227
- compilerOptions: { allowJs: !0 },
228
- manipulationSettings: { quoteKind: S.Single }
229
- }).addSourceFileAtPath(e), i = n.getVariableStatements().find((e) => e.getDeclarations().some((e) => e.getName() === "load")) ?? n.getFunction("load");
230
- if (i) {
231
- if (H(i.getText()) !== H(v)) return {
232
- status: "failed",
233
- message: z
234
- };
235
- o(n, i);
236
- }
237
- for (let e of B) u(n, e);
238
- return r(n, V), l(n) ? (y.writeFileSync(e, "", "utf8"), {
239
- status: "success",
240
- changed: !0
241
- }) : (c(n), s(n), n.saveSync(), {
242
- status: "success",
243
- changed: n.getFullText() !== t
244
- });
245
- }
246
- //#endregion
247
- //#region src/patterns/disable/i18n/modifies/root-layout.svelte.ts
248
- function W(e) {
249
- if (!y.existsSync(e)) return {
250
- status: "success",
251
- changed: !1
252
- };
253
- let t = y.readFileSync(e, "utf8");
254
- if (!t.includes("LanguageSelect")) return {
255
- status: "success",
256
- changed: !1
257
- };
258
- let r = p.fromPath(e);
259
- r.modifyScript((e) => {
260
- let { source: t } = n(e, (e) => {
261
- u(e, "$lib/components/language-select.svelte"), s(e);
262
- });
263
- return t;
264
- });
265
- let i = r.toString();
266
- return i = i.replace(/[ \t]*<Navbar\.Item>\s*<LanguageSelect\s*\/>\s*<\/Navbar\.Item>[ \t]*\r?\n?/g, ""), i = i.replace(/[ \t]*<LanguageSelect\s*\/>[ \t]*\r?\n?/g, ""), y.writeFileSync(e, i, "utf8"), {
267
- status: "success",
268
- changed: i !== t
269
- };
270
- }
271
- //#endregion
272
- //#region src/patterns/disable/i18n/generate.runtime.ts
273
- async function G(e) {
274
- let n = t(e), r = [], i = [], a = (e) => {
275
- e && r.push(e);
276
- };
277
- n.info("Reverting vite.config");
278
- let o = h(e.root, _) ?? b.join(e.root, _[0]);
279
- a(d(o, T(o))), n.info("Reverting the $locales alias");
280
- let s = D(e.root);
281
- a(d(s.filePath, s.outcome)), n.info("Reverting hooks.server.ts");
282
- let c = b.join(e.root, "src", "hooks.server.ts"), l = f(c, j(c));
283
- a(l.modify), l.delete && i.push(l.delete), n.info("Reverting hooks.ts");
284
- let u = b.join(e.root, "src", "hooks.ts"), p = f(u, L(u));
285
- a(p.modify), p.delete && i.push(p.delete), n.info("Reverting app.html");
286
- let m = b.join(e.root, "src", "app.html");
287
- a(d(m, R(m))), n.info("Reverting root +layout.ts");
288
- let g = b.join(e.root, "src", "routes", "+layout.ts"), v = f(g, U(g));
289
- a(v.modify), v.delete && i.push(v.delete), n.info("Reverting root layout language select");
290
- let x = [
291
- b.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
292
- b.join(e.root, "src", "routes", "root-layout.svelte"),
293
- b.join(e.root, "src", "routes", "(public)", "+layout.svelte"),
294
- b.join(e.root, "src", "routes", "+layout.svelte")
295
- ];
296
- for (let e of x) y.existsSync(e) && a(d(e, W(e)));
297
- n.info("Reverting .gitignore");
298
- let S = b.join(e.root, ".gitignore");
299
- return a(d(S, w(S))), {
300
- creates: [],
301
- modifies: r,
302
- deletes: i,
303
- components: [],
304
- packages: [],
305
- collections: [],
306
- collectionPatches: [],
307
- collectionDrops: []
308
- };
309
- }
310
- //#endregion
311
- export { G as generate };
312
-
313
- //# sourceMappingURL=generate.runtime-Drmahmdl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.runtime-Drmahmdl.js","names":[],"sources":["../../src/patterns/disable/i18n/modifies/gitignore.ts","../../src/patterns/disable/i18n/modifies/vite-config.ts","../../src/patterns/disable/i18n/modifies/svelte-config.ts","../../src/patterns/disable/i18n/modifies/hooks.server.ts","../../src/patterns/disable/i18n/modifies/hooks.ts","../../src/patterns/disable/i18n/modifies/app-html.ts","../../src/patterns/disable/i18n/modifies/+layout.ts","../../src/patterns/disable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/disable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\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 lines = original.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === \"# Wuchale\") {\n let j = i + 1;\n let hasWuchale = false;\n while (j < lines.length && lines[j].trim() !== \"\") {\n if (lines[j] === \"src/locales/.wuchale\") {\n hasWuchale = true;\n }\n j++;\n }\n if (hasWuchale) {\n i = j;\n continue;\n }\n }\n if (line === \"src/locales/.wuchale\") continue;\n out.push(line);\n }\n\n let updated = out.join(\"\\n\");\n updated = updated.replace(/\\n{3,}/g, \"\\n\\n\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n removeImportByModuleSpecifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** Remove `wuchale()` from the Vite plugins and its import. */\nexport function unmodifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(viteConfigPath, \"utf8\");\n if (!original.includes(\"wuchale\")) {\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(viteConfigPath);\n\n // One removal at a time: manipulating the tree invalidates sibling nodes.\n for (;;) {\n let removed = false;\n for (const arr of sourceFile.getDescendantsOfKind(\n SyntaxKind.ArrayLiteralExpression,\n )) {\n const index = arr\n .getElements()\n .findIndex((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n if (index >= 0) {\n arr.removeElement(index);\n removed = true;\n break;\n }\n }\n if (!removed) break;\n }\n\n removeImportByModuleSpecifier(sourceFile, \"wuchale/vite\");\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import { SyntaxKind, type PropertyAssignment } from \"ts-morph\";\nimport {\n modifyConfig,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst HINTS = {\n notFound: \"No SvelteKit config to revert.\",\n failed: \"Remove the $locales alias from the kit config by hand.\",\n};\n\n/** Remove the `$locales` alias; drop `alias` too once it is empty. */\nexport function unmodifySvelteConfig(root: string): ConfigModifyResult {\n const result = modifyConfig(root, HINTS, (target) => {\n const kit = target.kitContainer();\n if (!kit) return true;\n\n const aliasProp = kit.getProperty(\"alias\");\n if (!aliasProp || aliasProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return true;\n }\n const aliasObj = (aliasProp as PropertyAssignment).getInitializer();\n if (\n !aliasObj ||\n aliasObj.getKind() !== SyntaxKind.ObjectLiteralExpression\n ) {\n return true;\n }\n const obj = aliasObj.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const locales = obj\n .getProperties()\n .find((p) => p.getText().replace(/['\"]/g, \"\").startsWith(\"$locales\"));\n if (!locales) return true;\n\n locales.remove();\n if (obj.getProperties().length === 0) {\n aliasProp.remove();\n }\n return true;\n });\n\n // Nothing to revert in a project without a config.\n if (result.outcome.status === \"not-found\") {\n return { ...result, outcome: { status: \"success\", changed: false } };\n }\n return result;\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n removeNamedImportIfUnused,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\nconst FAILURE_HINT = dedent`\n Take handleWuchale out of the exported handle in src/hooks.server.ts, then\n remove its declaration, the loadLocales(...) calls and the wuchale and\n $locales imports.\n`;\n\nconst I18N_MODULES = [\n \"wuchale/load-utils/server\",\n \"$locales/main.url\",\n \"$locales/data\",\n \"$locales/main.loader.server.svelte.js\",\n \"$locales/js.loader.server.js\",\n];\n\n/**\n * Undo `modifyHooksServerI18n`: drop the locale bootstrap, the wuchale handle\n * and its imports, and unwrap `sequence(handleWuchale, ...)`. A file that\n * enable-i18n created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerI18n(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (!original.includes(I18N_HANDLE) && !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 // loadLocales(...) bootstrap calls, one at a time (removal invalidates siblings).\n for (;;) {\n const stmt = sourceFile\n .getStatements()\n .find(\n (s) =>\n s.getKind() === SyntaxKind.ExpressionStatement &&\n /^loadLocales\\s*\\(/.test(s.getText()),\n );\n if (!stmt) break;\n stmt.remove();\n }\n\n // `export const handle = handleWuchale` goes altogether; a sequence loses\n // the argument, or unwraps to the handle it composed with.\n const removed = removeHandle(sourceFile, I18N_HANDLE);\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, I18N_HANDLE);\n for (const moduleSpecifier of I18N_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n removeNamedImportIfUnused(sourceFile, \"@sveltejs/kit\", \"Handle\");\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 dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeTopLevelStatementByIdentifier,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = \"rerouteDeLocalize\";\n\nconst FAILURE_HINT = dedent`\n Take rerouteDeLocalize out of the exported reroute in src/hooks.ts, then\n remove its declaration and the wuchale and $locales imports.\n`;\n\nconst I18N_MODULES = [\"wuchale/url\", \"$locales/main.url\", \"$locales/data\"];\n\n/** The two reroutes `modifyHooksI18n` writes: on its own, and composed. */\nconst I18N_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*url\\.pathname\\s*\\)$/;\nconst COMPOSED_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*rerouteDeLocalize\\(\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)\\s*\\)$/;\n\n/**\n * Undo `modifyHooksI18n`: drop the de-localizer and its imports, leaving the\n * negotiation reroute it may have been composed with. A file that enable-i18n\n * created comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (!original.includes(DELOCALIZE_HELPER)) {\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 helperStatement = sourceFile\n .getVariableDeclaration(DELOCALIZE_HELPER)\n ?.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n const initText = rerouteDecl?.getInitializer()?.getText() ?? \"\";\n const composed = COMPOSED_REROUTE.test(initText);\n const rerouteStatement =\n composed || I18N_ONLY_REROUTE.test(initText)\n ? rerouteDecl?.getFirstAncestorByKind(SyntaxKind.VariableStatement)\n : undefined;\n\n // Anything else reading the de-localizer is code enable-i18n did not write,\n // so undoing it is the developer's call.\n const otherReaders = sourceFile\n .getStatements()\n .filter(\n (s) =>\n s !== helperStatement &&\n s !== rerouteStatement &&\n s.getText().includes(DELOCALIZE_HELPER),\n );\n if (otherReaders.length > 0) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n if (composed) {\n // content-negotiation's reroute is underneath; it stays.\n rerouteDecl?.setInitializer(\"({ url }) => negotiateReroute(url.pathname)\");\n } else if (rerouteStatement) {\n removeTopLevelStatementByIdentifier(sourceFile, \"reroute\");\n }\n\n removeTopLevelStatementByIdentifier(sourceFile, DELOCALIZE_HELPER);\n pruneUnusedImports(sourceFile, I18N_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty hooks.ts into a\n // delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(hooksPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\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 type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Put a real language back. `%sveltekit.lang%` is not a SvelteKit\n * placeholder; only the wuchale hook replaced it, so without that hook it\n * would be served literally.\n */\nexport function unmodifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n const updated = original.replace(\n /lang\\s*=\\s*(?:\"%sveltekit\\.lang%\"|'%sveltekit\\.lang%')/g,\n 'lang=\"en\"',\n );\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(appHtmlPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type Statement } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { LOAD_STATEMENT } from \"../../../enable/i18n/modifies/+layout\";\nimport {\n ensureBlankLineAfterImports,\n isEffectivelyEmpty,\n pruneUnusedImports,\n removeImportByModuleSpecifier,\n removeStatementWithComments,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.ts still loads wuchale locales. Remove these from it:\n\n import { browser } from '$app/environment';\n import { loadLocale } from 'wuchale/load-utils';\n import { getLocale } from '$locales/main.url';\n import '$locales/main.loader.svelte';\n import '$locales/js.loader';\n\n and the loadLocale(...) call inside load().\n`;\n\nconst SIDE_EFFECT_MODULES = [\n \"$locales/main.loader.svelte\",\n \"$locales/js.loader\",\n];\nconst BINDING_MODULES = [\n \"$app/environment\",\n \"wuchale/load-utils\",\n \"$locales/main.url\",\n];\n\nfunction normalize(source: string): string {\n return source.replace(/[\"']/g, \"'\").replace(/\\s+/g, \"\");\n}\n\n/**\n * Undo `ensureRootLayoutI18n`: drop the wuchale load and its imports, leaving\n * whatever else the file holds. A file enable-i18n wrote whole comes out\n * empty, for the caller to delete.\n */\nexport function unmodifyRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(\"loadLocale\") && !original.includes(\"$locales\")) {\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(layoutPath);\n\n const loadStatement: Statement | undefined =\n sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"load\")) ??\n sourceFile.getFunction(\"load\");\n\n if (loadStatement) {\n // A load that grew code of its own needs a hand; only the one enable-i18n\n // wrote is safe to take out wholesale.\n if (normalize(loadStatement.getText()) !== normalize(LOAD_STATEMENT)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n removeStatementWithComments(sourceFile, loadStatement);\n }\n\n for (const moduleSpecifier of SIDE_EFFECT_MODULES) {\n removeImportByModuleSpecifier(sourceFile, moduleSpecifier);\n }\n pruneUnusedImports(sourceFile, BINDING_MODULES);\n\n if (isEffectivelyEmpty(sourceFile)) {\n // Emptied rather than removed: the runtime turns an empty +layout.ts into\n // a delete entry, so the removal is written and reported like any other.\n fs.writeFileSync(layoutPath, \"\", \"utf8\");\n return { status: \"success\", changed: true };\n }\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 { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Take the language select (and the nav item enable-i18n wrapped it in) back out. */\nexport function unmodifyRootLayoutLanguageSelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(\n sf,\n \"$lib/components/language-select.svelte\",\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n let updated = file.toString();\n updated = updated.replace(\n /[ \\t]*<Navbar\\.Item>\\s*<LanguageSelect\\s*\\/>\\s*<\\/Navbar\\.Item>[ \\t]*\\r?\\n?/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<LanguageSelect\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\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 {\n modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { unmodifyGitignore } from \"./modifies/gitignore\";\nimport { unmodifyViteConfig } from \"./modifies/vite-config\";\nimport { unmodifySvelteConfig } from \"./modifies/svelte-config\";\nimport { unmodifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { unmodifyHooksI18n } from \"./modifies/hooks\";\nimport { unmodifyAppHtml } from \"./modifies/app-html\";\nimport { unmodifyRootLayoutI18n } from \"./modifies/+layout\";\nimport { unmodifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting 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, unmodifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Reverting the $locales alias\");\n const alias = unmodifySvelteConfig(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.outcome));\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n // enable-i18n may have created it; emptied, it goes.\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerI18n(hooksServerPath),\n );\n pushResult(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n logger.info(\"Reverting hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n // The de-localizing reroute may be all it holds; emptied, it goes.\n const hooksRevert = revertOutcomeToFile(\n hooksPath,\n unmodifyHooksI18n(hooksPath),\n );\n pushResult(hooksRevert.modify);\n if (hooksRevert.delete) deletes.push(hooksRevert.delete);\n\n logger.info(\"Reverting app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, unmodifyAppHtml(appHtmlPath)));\n\n logger.info(\"Reverting root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n // enable-i18n may have written the whole file; emptied, it goes.\n const layoutRevert = revertOutcomeToFile(\n layoutPath,\n unmodifyRootLayoutI18n(layoutPath),\n );\n pushResult(layoutRevert.modify);\n if (layoutRevert.delete) deletes.push(layoutRevert.delete);\n\n logger.info(\"Reverting 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 for (const candidate of rootLayoutCandidates) {\n if (!fs.existsSync(candidate)) continue;\n pushResult(\n modifyOutcomeToFile(\n candidate,\n unmodifyRootLayoutLanguageSelect(candidate),\n ),\n );\n }\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, unmodifyGitignore(gitignorePath)),\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":";;;;;;;;;;;;AAGA,SAAgB,EAAkB,GAAsC;CACtE,IAAI,CAAC,EAAG,WAAW,CAAa,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAW,EAAG,aAAa,GAAe,MAAM;CACtD,IAAI,CAAC,EAAS,SAAS,sBAAsB,GAC3C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAQ,EAAS,MAAM,IAAI,GAC3B,IAAgB,CAAC;CACvB,KAAK,IAAI,IAAI,GAAG,IAAI,EAAM,QAAQ,KAAK;EACrC,IAAM,IAAO,EAAM;EACnB,IAAI,MAAS,aAAa;GACxB,IAAI,IAAI,IAAI,GACR,IAAa;GACjB,OAAO,IAAI,EAAM,UAAU,EAAM,EAAE,CAAC,KAAK,MAAM,KAI7C,AAHI,EAAM,OAAO,2BACf,IAAa,KAEf;GAEF,IAAI,GAAY;IACd,IAAI;IACJ;GACF;EACF;EACI,MAAS,0BACb,EAAI,KAAK,CAAI;CACf;CAEA,IAAI,IAAU,EAAI,KAAK,IAAI;CAQ3B,OAPA,IAAU,EAAQ,QAAQ,WAAW,MAAM,GAEvC,MAAY,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7C,EAAG,cAAc,GAAe,CAAO,GAChC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;ACnCA,SAAgB,EAAmB,GAAuC;CACxE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAW,EAAG,aAAa,GAAgB,MAAM;CACvD,IAAI,CAAC,EAAS,SAAS,SAAS,GAC9B,OAAO;EAA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AAO,KAAK,sBAAsB;CAClC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,YAAY;CAK1D,OAJA,EACE,EAAoB,GAAe,EAAkB,CAAa,CAAC,CACrE,GAEO;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1 +0,0 @@
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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E,GACA,EAA+B,GAAgB,CAAE,CACnD,CACF,GAEA,EAAO,KAAK,qBAAqB;CACjC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,YAAY;CAC1D,EACE,EAAoB,GAAe,EAAgB,CAAa,CAAC,CACnE;CAEA,IAAM,IAAU,GAAmB,EAAQ,MAAM,CAAE;CAGnD,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"}
@@ -1,94 +0,0 @@
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
@@ -1 +0,0 @@
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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CAC1C;CAMA,AALI,MACF,EAAO,KAAK,2BAA2B,GACvC,EAAS,KAAK,CAAe,IAG/B,EAAO,KAAK,sBAAsB;CAClC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,YAAY,GACpD,IAAgB,EACpB,GACA,EAAgB,CAAa,CAC/B;CACA,AAAI,KAAe,EAAS,KAAK,CAAa;CAK9C,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,QAAQ,UAAU;CAChE,IAAI,EAAG,WAAW,CAAa,GAAG;EAChC,EAAO,KAAK,yBAAyB;EACrC,IAAM,IAAgB,EACpB,GACA,EAAgB,CAAa,CAC/B;EACA,AAAI,KAAe,EAAS,KAAK,CAAa;CAChD,OAEE,AADA,EAAO,KAAK,wBAAwB,GACpC,EAAO,iBAAiB,CAAY;CAQtC,OALK,EAAgB,EAAQ,IAAI,MAC/B,EAAO,KAAK,2BAA2B,GACvC,EAAO,oBAAoB,CAAa,IAGnC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,32 +0,0 @@
1
- import { o as e } from "./generate-Ca_6FlPi.js";
2
- import { n as t } from "./logger-CQONztPm.js";
3
- import { n } from "./shared-C8GtNxpm.js";
4
- import { n as r, t as i } from "./generate-DwADTUob.js";
5
- import { n as a } from "./env-BPfk1VAw.js";
6
- import { envRevertOutcomeToFile as o } from "./modify-file-Dwfv0dCI.js";
7
- import s from "node:fs";
8
- import c from "node:path";
9
- //#region src/patterns/disable/ai/generate.runtime.ts
10
- async function l(l) {
11
- let u = t(l), d = [], f = [], p = e(l);
12
- for (let e of r(l)) {
13
- let t = `${e}/+page.svelte`;
14
- e !== p && s.existsSync(c.join(l.root, t)) && f.push(n(t));
15
- }
16
- u.info("Removing the AI provider's API key from .env");
17
- let m = c.join(l.root, ".env"), h = o(m, a(m, i()));
18
- return h.modify && d.push(h.modify), h.delete && f.push(h.delete), {
19
- creates: [],
20
- modifies: d,
21
- deletes: f,
22
- components: [],
23
- packages: [],
24
- collections: [],
25
- collectionPatches: [],
26
- collectionDrops: []
27
- };
28
- }
29
- //#endregion
30
- export { l as generate };
31
-
32
- //# sourceMappingURL=generate.runtime-QGHToXRY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.runtime-QGHToXRY.js","names":[],"sources":["../../src/patterns/disable/ai/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyEnvRemove } from \"../../../runtime/env\";\nimport { envRevertOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { demoDir } from \"../../enable/ai/generate\";\nimport { allEnvEdits, demoDirs } from \"./generate\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n // The base result names the page in the current default group; a page\n // generated before auth was enabled sits in the other one.\n const current = demoDir(options);\n for (const dir of demoDirs(options)) {\n const page = `${dir}/+page.svelte`;\n if (dir !== current && fs.existsSync(path.join(options.root, page))) {\n deletes.push(toDeleteEntry(page));\n }\n }\n\n logger.info(\"Removing the AI provider's API key from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n if (env.modify) modifies.push(env.modify);\n if (env.delete) deletes.push(env.delete);\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":";;;;;;;;;AAUA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAmB,CAAC,GACpB,IAAkB,CAAC,GAInB,IAAU,EAAQ,CAAO;CAC/B,KAAK,IAAM,KAAO,EAAS,CAAO,GAAG;EACnC,IAAM,IAAO,GAAG,EAAI;EACpB,AAAI,MAAQ,KAAW,EAAG,WAAW,EAAK,KAAK,EAAQ,MAAM,CAAI,CAAC,KAChE,EAAQ,KAAK,EAAc,CAAI,CAAC;CAEpC;CAEA,EAAO,KAAK,8CAA8C;CAC1D,IAAM,IAAU,EAAK,KAAK,EAAQ,MAAM,MAAM,GACxC,IAAM,EACV,GACA,EAAgB,GAAS,EAAY,CAAC,CACxC;CAIA,OAHI,EAAI,UAAQ,EAAS,KAAK,EAAI,MAAM,GACpC,EAAI,UAAQ,EAAQ,KAAK,EAAI,MAAM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}