@velastack/patterns 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/_layout-D0OmzCu1.js +47 -0
- package/dist/chunks/_layout-D0OmzCu1.js.map +1 -0
- package/dist/chunks/{collections-B-yQ1qt6.js → collections-B3lAtPlQ.js} +2 -2
- package/dist/chunks/{collections-B-yQ1qt6.js.map → collections-B3lAtPlQ.js.map} +1 -1
- package/dist/chunks/{generate-BoEG6Rb-.js → generate-Va1sxVPG.js} +2 -2
- package/dist/chunks/{generate-BoEG6Rb-.js.map → generate-Va1sxVPG.js.map} +1 -1
- package/dist/chunks/{generate-BCBS08AS.js → generate-tOkjJFUf.js} +2 -2
- package/dist/chunks/{generate-BCBS08AS.js.map → generate-tOkjJFUf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-_VsM0zBS.js → generate.runtime-4Iplvp8f.js} +6 -6
- package/dist/chunks/{generate.runtime-_VsM0zBS.js.map → generate.runtime-4Iplvp8f.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ByASCDoo.js → generate.runtime-B9gdCz4t.js} +3 -3
- package/dist/chunks/{generate.runtime-ByASCDoo.js.map → generate.runtime-B9gdCz4t.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CIuSkWtY.js → generate.runtime-BKb9thdE.js} +91 -131
- package/dist/chunks/generate.runtime-BKb9thdE.js.map +1 -0
- package/dist/chunks/generate.runtime-BdTCMGGB.js +65 -0
- package/dist/chunks/generate.runtime-BdTCMGGB.js.map +1 -0
- package/dist/chunks/{generate.runtime-CRgw-aja.js → generate.runtime-BjULAL3h.js} +47 -46
- package/dist/chunks/generate.runtime-BjULAL3h.js.map +1 -0
- package/dist/chunks/{generate.runtime-C6qZUlN-.js → generate.runtime-BlQ1vx8j.js} +6 -6
- package/dist/chunks/{generate.runtime-C6qZUlN-.js.map → generate.runtime-BlQ1vx8j.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CghBFVEf.js → generate.runtime-BltGUllM.js} +6 -6
- package/dist/chunks/{generate.runtime-CghBFVEf.js.map → generate.runtime-BltGUllM.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CwaPHcYP.js → generate.runtime-BsuyMwoj.js} +6 -6
- package/dist/chunks/{generate.runtime-CwaPHcYP.js.map → generate.runtime-BsuyMwoj.js.map} +1 -1
- package/dist/chunks/{generate.runtime-PjMBpjkG.js → generate.runtime-C-Val7lP.js} +5 -5
- package/dist/chunks/{generate.runtime-PjMBpjkG.js.map → generate.runtime-C-Val7lP.js.map} +1 -1
- package/dist/chunks/generate.runtime-CGkVUKvz.js +106 -0
- package/dist/chunks/generate.runtime-CGkVUKvz.js.map +1 -0
- package/dist/chunks/{generate.runtime-BBOWWrZv.js → generate.runtime-CXXwLatT.js} +5 -5
- package/dist/chunks/{generate.runtime-BBOWWrZv.js.map → generate.runtime-CXXwLatT.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CrrAzNZS.js → generate.runtime-DCvLLO7w.js} +5 -5
- package/dist/chunks/{generate.runtime-CrrAzNZS.js.map → generate.runtime-DCvLLO7w.js.map} +1 -1
- package/dist/chunks/{generate.runtime-WwZt9Mu5.js → generate.runtime-DKJaYtVZ.js} +7 -7
- package/dist/chunks/{generate.runtime-WwZt9Mu5.js.map → generate.runtime-DKJaYtVZ.js.map} +1 -1
- package/dist/chunks/generate.runtime-DWeiewRj.js +145 -0
- package/dist/chunks/generate.runtime-DWeiewRj.js.map +1 -0
- package/dist/chunks/{generate.runtime-CUtOhlNA.js → generate.runtime-DaPNrIyg.js} +3 -3
- package/dist/chunks/{generate.runtime-CUtOhlNA.js.map → generate.runtime-DaPNrIyg.js.map} +1 -1
- package/dist/chunks/generate.runtime-Dc98DCsh.js +256 -0
- package/dist/chunks/generate.runtime-Dc98DCsh.js.map +1 -0
- package/dist/chunks/{generate.runtime-DercL_qN.js → generate.runtime-FMYR64DL.js} +5 -5
- package/dist/chunks/{generate.runtime-DercL_qN.js.map → generate.runtime-FMYR64DL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Biy8wuHU.js → generate.runtime-QmFJI7G1.js} +13 -13
- package/dist/chunks/{generate.runtime-Biy8wuHU.js.map → generate.runtime-QmFJI7G1.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dlokr7A0.js → generate.runtime-SQhCLSah.js} +2 -2
- package/dist/chunks/{generate.runtime-Dlokr7A0.js.map → generate.runtime-SQhCLSah.js.map} +1 -1
- package/dist/chunks/{generate.runtime-UIN_TkYo.js → generate.runtime-Wssys8A0.js} +6 -6
- package/dist/chunks/{generate.runtime-UIN_TkYo.js.map → generate.runtime-Wssys8A0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-nyMB57Tf.js → generate.runtime-fSDNxfGG.js} +2 -2
- package/dist/chunks/{generate.runtime-nyMB57Tf.js.map → generate.runtime-fSDNxfGG.js.map} +1 -1
- package/dist/chunks/{generate.runtime-XpQGIrOx.js → generate.runtime-kH6XaWQz.js} +6 -6
- package/dist/chunks/{generate.runtime-XpQGIrOx.js.map → generate.runtime-kH6XaWQz.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C6RhVu5K.js → generate.runtime-lqPPXQyS.js} +6 -6
- package/dist/chunks/{generate.runtime-C6RhVu5K.js.map → generate.runtime-lqPPXQyS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-JWURZXj-.js → generate.runtime-tAbxWeq-.js} +7 -7
- package/dist/chunks/{generate.runtime-JWURZXj-.js.map → generate.runtime-tAbxWeq-.js.map} +1 -1
- package/dist/chunks/{modify-file-Dgd_PzRG.js → modify-file-Cgu_WeFk.js} +2 -2
- package/dist/chunks/{modify-file-Dgd_PzRG.js.map → modify-file-Cgu_WeFk.js.map} +1 -1
- package/dist/chunks/{shared-cFKFtcgw.js → shared--_BWnGsc.js} +3 -3
- package/dist/chunks/{shared-cFKFtcgw.js.map → shared--_BWnGsc.js.map} +1 -1
- package/dist/chunks/{test-setup-BBb4kcoO.js → test-setup-DjbhQYZC.js} +49 -58
- package/dist/chunks/test-setup-DjbhQYZC.js.map +1 -0
- package/dist/chunks/{ts-morph-helpers-7qF9S2k7.js → ts-morph-helpers-Bf5iuQW8.js} +28 -12
- package/dist/chunks/ts-morph-helpers-Bf5iuQW8.js.map +1 -0
- package/dist/chunks/{ui-X12f0xKA.js → ui-BsG60gQg.js} +2 -2
- package/dist/chunks/{ui-X12f0xKA.js.map → ui-BsG60gQg.js.map} +1 -1
- package/dist/chunks/unmodify-load-W1ePZQHr.js +80 -0
- package/dist/chunks/unmodify-load-W1ePZQHr.js.map +1 -0
- package/dist/chunks/{util-Bq_Mh6IQ.js → util-BLYliuUK.js} +2 -2
- package/dist/chunks/{util-Bq_Mh6IQ.js.map → util-BLYliuUK.js.map} +1 -1
- package/dist/chunks/write-result-BN7Ff0rF.js +451 -0
- package/dist/chunks/write-result-BN7Ff0rF.js.map +1 -0
- package/dist/index.d.ts +77 -7
- package/dist/index.js +630 -542
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/generate.runtime-ArKscTs9.js +0 -65
- package/dist/chunks/generate.runtime-ArKscTs9.js.map +0 -1
- package/dist/chunks/generate.runtime-BpvwX9CL.js +0 -28
- package/dist/chunks/generate.runtime-BpvwX9CL.js.map +0 -1
- package/dist/chunks/generate.runtime-BtL9FPuW.js +0 -60
- package/dist/chunks/generate.runtime-BtL9FPuW.js.map +0 -1
- package/dist/chunks/generate.runtime-CIuSkWtY.js.map +0 -1
- package/dist/chunks/generate.runtime-CRgw-aja.js.map +0 -1
- package/dist/chunks/test-setup-BBb4kcoO.js.map +0 -1
- package/dist/chunks/ts-morph-helpers-7qF9S2k7.js.map +0 -1
- package/dist/chunks/write-result-DgFUKxhP.js +0 -445
- package/dist/chunks/write-result-DgFUKxhP.js.map +0 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { modifyOutcomeToFile as n } from "./modify-file-
|
|
4
|
-
import {
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-Cgu_WeFk.js";
|
|
4
|
+
import { c as r, l as i, r as a } from "./ts-morph-helpers-Bf5iuQW8.js";
|
|
5
5
|
import { a as o, i as s, r as c, t as l } from "./config-target-DOi8kI_f.js";
|
|
6
|
-
import u from "
|
|
7
|
-
import d from "node:
|
|
8
|
-
import
|
|
6
|
+
import { n as u } from "./_layout-D0OmzCu1.js";
|
|
7
|
+
import d from "node:path";
|
|
8
|
+
import f from "node:fs";
|
|
9
|
+
import { Project as p, QuoteKind as m, SyntaxKind as h } from "ts-morph";
|
|
9
10
|
//#region src/patterns/enable/i18n/modifies/vite-config.ts
|
|
10
|
-
var
|
|
11
|
+
var g = [
|
|
11
12
|
"Add the wuchale plugin to your Vite config:",
|
|
12
13
|
"",
|
|
13
14
|
"import { wuchale } from 'wuchale/vite';",
|
|
@@ -15,7 +16,7 @@ var h = [
|
|
|
15
16
|
"export default defineConfig({",
|
|
16
17
|
" plugins: [wuchale(), /* ...existing plugins */],",
|
|
17
18
|
"});"
|
|
18
|
-
].join("\n"),
|
|
19
|
+
].join("\n"), _ = [
|
|
19
20
|
"Create a Vite config with the wuchale plugin:",
|
|
20
21
|
"",
|
|
21
22
|
"import { defineConfig } from 'vite';",
|
|
@@ -25,20 +26,20 @@ var h = [
|
|
|
25
26
|
" plugins: [wuchale()],",
|
|
26
27
|
"});"
|
|
27
28
|
].join("\n");
|
|
28
|
-
function
|
|
29
|
-
if (!
|
|
29
|
+
function v(e) {
|
|
30
|
+
if (!f.existsSync(e)) return {
|
|
30
31
|
status: "not-found",
|
|
31
|
-
message:
|
|
32
|
+
message: _
|
|
32
33
|
};
|
|
33
|
-
let t = new
|
|
34
|
+
let t = new p({
|
|
34
35
|
compilerOptions: { allowJs: !0 },
|
|
35
|
-
manipulationSettings: { quoteKind:
|
|
36
|
+
manipulationSettings: { quoteKind: m.Single }
|
|
36
37
|
}).addSourceFileAtPath(e), n = !1, r = !1;
|
|
37
38
|
t.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "wuchale/vite") || (t.insertImportDeclaration(0, {
|
|
38
39
|
namedImports: ["wuchale"],
|
|
39
40
|
moduleSpecifier: "wuchale/vite"
|
|
40
41
|
}), n = !0);
|
|
41
|
-
let i = t.getDescendantsOfKind(
|
|
42
|
+
let i = t.getDescendantsOfKind(h.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], a = i?.getKind() === h.ObjectLiteralExpression ? i : null;
|
|
42
43
|
if (!a) r = !0;
|
|
43
44
|
else {
|
|
44
45
|
let e = a.getProperty("plugins");
|
|
@@ -46,11 +47,11 @@ function _(e) {
|
|
|
46
47
|
name: "plugins",
|
|
47
48
|
initializer: "[wuchale()]"
|
|
48
49
|
}), n = !0;
|
|
49
|
-
else if (e.getKind() !==
|
|
50
|
+
else if (e.getKind() !== h.PropertyAssignment) r = !0;
|
|
50
51
|
else {
|
|
51
52
|
let t = e.getInitializer();
|
|
52
53
|
if (!t) e.setInitializer("[wuchale()]"), n = !0;
|
|
53
|
-
else if (t.getKind() !==
|
|
54
|
+
else if (t.getKind() !== h.ArrayLiteralExpression) r = !0;
|
|
54
55
|
else {
|
|
55
56
|
let e = t;
|
|
56
57
|
e.getElements().some((e) => e.getText().replace(/\s/g, "") === "wuchale()") || (e.insertElement(0, "wuchale()"), n = !0);
|
|
@@ -59,7 +60,7 @@ function _(e) {
|
|
|
59
60
|
}
|
|
60
61
|
return n && (t.formatText(), t.saveSync()), r ? {
|
|
61
62
|
status: "failed",
|
|
62
|
-
message:
|
|
63
|
+
message: g
|
|
63
64
|
} : {
|
|
64
65
|
status: "success",
|
|
65
66
|
changed: n
|
|
@@ -67,13 +68,13 @@ function _(e) {
|
|
|
67
68
|
}
|
|
68
69
|
//#endregion
|
|
69
70
|
//#region src/patterns/enable/i18n/modifies/svelte-config.ts
|
|
70
|
-
var
|
|
71
|
+
var y = [
|
|
71
72
|
"Add the $locales alias to your config (sveltekit() arg in vite.config, or svelte.config):",
|
|
72
73
|
"",
|
|
73
74
|
"alias: {",
|
|
74
75
|
" $locales: 'src/locales',",
|
|
75
76
|
"},"
|
|
76
|
-
].join("\n"),
|
|
77
|
+
].join("\n"), b = [
|
|
77
78
|
"Add the $locales alias by passing config to the sveltekit() plugin in vite.config.ts:",
|
|
78
79
|
"",
|
|
79
80
|
"import { sveltekit } from '@sveltejs/kit/vite';",
|
|
@@ -83,17 +84,17 @@ var v = [
|
|
|
83
84
|
" plugins: [sveltekit({ alias: { $locales: 'src/locales' } })],",
|
|
84
85
|
"});"
|
|
85
86
|
].join("\n");
|
|
86
|
-
function
|
|
87
|
+
function x(e) {
|
|
87
88
|
return s(e, {
|
|
88
|
-
notFound:
|
|
89
|
-
failed:
|
|
89
|
+
notFound: b,
|
|
90
|
+
failed: y
|
|
90
91
|
}, (e) => {
|
|
91
92
|
let t = e.kitContainer();
|
|
92
93
|
if (!t) return !1;
|
|
93
94
|
let n = c(t, "alias", "{}");
|
|
94
95
|
if (!n) return !1;
|
|
95
96
|
let r = n.getProperty("$locales");
|
|
96
|
-
return r ? r.getKind() ===
|
|
97
|
+
return r ? r.getKind() === h.PropertyAssignment && (r.getInitializer()?.getText()?.replace(/['"`]/g, "") !== "src/locales" && r.setInitializer("'src/locales'"), !0) : (n.addPropertyAssignment({
|
|
97
98
|
name: "$locales",
|
|
98
99
|
initializer: "'src/locales'"
|
|
99
100
|
}), !0);
|
|
@@ -101,7 +102,7 @@ function b(e) {
|
|
|
101
102
|
}
|
|
102
103
|
//#endregion
|
|
103
104
|
//#region src/patterns/enable/i18n/modifies/hooks.server.ts
|
|
104
|
-
var
|
|
105
|
+
var S = e`
|
|
105
106
|
Wrap your exported handle with the wuchale i18n handler:
|
|
106
107
|
|
|
107
108
|
import { sequence } from '@sveltejs/kit/hooks';
|
|
@@ -125,7 +126,7 @@ var x = e`
|
|
|
125
126
|
};
|
|
126
127
|
|
|
127
128
|
export const handle = sequence(handleWuchale, /* your existing handle */);
|
|
128
|
-
`,
|
|
129
|
+
`, C = e`
|
|
129
130
|
Create src/hooks.server.ts with an i18n handle:
|
|
130
131
|
|
|
131
132
|
import { sequence } from '@sveltejs/kit/hooks';
|
|
@@ -150,7 +151,7 @@ var x = e`
|
|
|
150
151
|
|
|
151
152
|
export const handle = handleWuchale;
|
|
152
153
|
`;
|
|
153
|
-
function
|
|
154
|
+
function w(e, t, n) {
|
|
154
155
|
let r = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t);
|
|
155
156
|
if (r) {
|
|
156
157
|
r.getNamedImports().some((e) => e.getName() === n) || r.addNamedImport(n);
|
|
@@ -161,36 +162,36 @@ function C(e, t, n) {
|
|
|
161
162
|
moduleSpecifier: t
|
|
162
163
|
});
|
|
163
164
|
}
|
|
164
|
-
function
|
|
165
|
+
function T(e, t, n) {
|
|
165
166
|
e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t) || e.addImportDeclaration({
|
|
166
167
|
namespaceImport: n,
|
|
167
168
|
moduleSpecifier: t
|
|
168
169
|
});
|
|
169
170
|
}
|
|
170
|
-
function
|
|
171
|
-
if (!
|
|
171
|
+
function E(t) {
|
|
172
|
+
if (!f.existsSync(t)) return {
|
|
172
173
|
status: "not-found",
|
|
173
|
-
message:
|
|
174
|
+
message: C
|
|
174
175
|
};
|
|
175
|
-
let n =
|
|
176
|
+
let n = f.readFileSync(t, "utf8");
|
|
176
177
|
if (n.includes("runWithLocale") || n.includes("loadLocales(")) return {
|
|
177
178
|
status: "success",
|
|
178
179
|
changed: !1
|
|
179
180
|
};
|
|
180
|
-
let r = new
|
|
181
|
+
let r = new p({
|
|
181
182
|
compilerOptions: { allowJs: !0 },
|
|
182
|
-
manipulationSettings: { quoteKind:
|
|
183
|
+
manipulationSettings: { quoteKind: m.Single }
|
|
183
184
|
}).addSourceFileAtPath(t), i = r.getVariableDeclaration("handle");
|
|
184
185
|
if (!i) return {
|
|
185
186
|
status: "failed",
|
|
186
|
-
message:
|
|
187
|
+
message: S
|
|
187
188
|
};
|
|
188
|
-
let a = i.getFirstAncestorByKind(
|
|
189
|
+
let a = i.getFirstAncestorByKind(h.VariableStatement);
|
|
189
190
|
if (!a?.hasExportKeyword()) return {
|
|
190
191
|
status: "failed",
|
|
191
|
-
message:
|
|
192
|
+
message: S
|
|
192
193
|
};
|
|
193
|
-
|
|
194
|
+
w(r, "@sveltejs/kit/hooks", "sequence"), w(r, "wuchale/load-utils/server", "runWithLocale"), w(r, "wuchale/load-utils/server", "loadLocales"), w(r, "$locales/main.url", "getLocale"), w(r, "$locales/data", "locales"), T(r, "$locales/main.loader.server.svelte.js", "main"), T(r, "$locales/js.loader.server.js", "js");
|
|
194
195
|
let o = r.getStatements().findIndex((e) => e === a), s = "handleWuchale", c = e`
|
|
195
196
|
loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
|
|
196
197
|
loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
|
|
@@ -209,24 +210,24 @@ function T(t) {
|
|
|
209
210
|
let u = i.getInitializer();
|
|
210
211
|
if (!u) return {
|
|
211
212
|
status: "failed",
|
|
212
|
-
message:
|
|
213
|
+
message: S
|
|
213
214
|
};
|
|
214
|
-
let
|
|
215
|
-
return
|
|
215
|
+
let d = u.getText();
|
|
216
|
+
return d.includes(s) || d.includes("runWithLocale") ? {
|
|
216
217
|
status: "success",
|
|
217
218
|
changed: !1
|
|
218
|
-
} : (i.setInitializer(`sequence(${s}, ${
|
|
219
|
+
} : (i.setInitializer(`sequence(${s}, ${d})`), r.formatText(), r.saveSync(), {
|
|
219
220
|
status: "success",
|
|
220
221
|
changed: !0
|
|
221
222
|
});
|
|
222
223
|
}
|
|
223
224
|
//#endregion
|
|
224
225
|
//#region src/patterns/enable/i18n/modifies/app-html.ts
|
|
225
|
-
var
|
|
226
|
+
var D = [
|
|
226
227
|
"Add the sveltekit lang placeholder to the <html> tag:",
|
|
227
228
|
"",
|
|
228
229
|
"<html lang=\"%sveltekit.lang%\">"
|
|
229
|
-
].join("\n"),
|
|
230
|
+
].join("\n"), O = [
|
|
230
231
|
"Create src/app.html with a lang placeholder:",
|
|
231
232
|
"",
|
|
232
233
|
"<!doctype html>",
|
|
@@ -240,39 +241,39 @@ var E = [
|
|
|
240
241
|
" </body>",
|
|
241
242
|
"</html>"
|
|
242
243
|
].join("\n");
|
|
243
|
-
function
|
|
244
|
-
if (!
|
|
244
|
+
function k(e) {
|
|
245
|
+
if (!f.existsSync(e)) return {
|
|
245
246
|
status: "not-found",
|
|
246
|
-
message:
|
|
247
|
+
message: O
|
|
247
248
|
};
|
|
248
|
-
let t =
|
|
249
|
+
let t = f.readFileSync(e, "utf8");
|
|
249
250
|
if (t.includes("lang=\"%sveltekit.lang%\"") || t.includes("lang='%sveltekit.lang%'")) return {
|
|
250
251
|
status: "success",
|
|
251
252
|
changed: !1
|
|
252
253
|
};
|
|
253
|
-
let n = t.replace(/<html(\s[^>]*?)?>/i, (e) =>
|
|
254
|
+
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%\""));
|
|
254
255
|
return n === t ? {
|
|
255
256
|
status: "failed",
|
|
256
|
-
message:
|
|
257
|
-
} : (
|
|
257
|
+
message: D
|
|
258
|
+
} : (f.writeFileSync(e, n), {
|
|
258
259
|
status: "success",
|
|
259
260
|
changed: !0
|
|
260
261
|
});
|
|
261
262
|
}
|
|
262
263
|
//#endregion
|
|
263
264
|
//#region src/patterns/enable/i18n/modifies/gitignore.ts
|
|
264
|
-
var
|
|
265
|
+
var A = [
|
|
265
266
|
"Create a .gitignore with the wuchale cache ignored:",
|
|
266
267
|
"",
|
|
267
268
|
"# Wuchale",
|
|
268
269
|
"src/locales/.wuchale"
|
|
269
270
|
].join("\n");
|
|
270
|
-
function
|
|
271
|
-
if (!
|
|
271
|
+
function j(t) {
|
|
272
|
+
if (!f.existsSync(t)) return {
|
|
272
273
|
status: "not-found",
|
|
273
|
-
message:
|
|
274
|
+
message: A
|
|
274
275
|
};
|
|
275
|
-
let n =
|
|
276
|
+
let n = f.readFileSync(t, "utf8");
|
|
276
277
|
if (n.includes("src/locales/.wuchale")) return {
|
|
277
278
|
status: "success",
|
|
278
279
|
changed: !1
|
|
@@ -281,126 +282,85 @@ function A(t) {
|
|
|
281
282
|
# Wuchale
|
|
282
283
|
src/locales/.wuchale
|
|
283
284
|
`, i = n + (n.length > 0 && !n.endsWith("\n") ? "\n" : "") + "\n" + r + "\n";
|
|
284
|
-
return
|
|
285
|
-
status: "success",
|
|
286
|
-
changed: !0
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
//#endregion
|
|
290
|
-
//#region src/patterns/enable/i18n/modifies/+layout.ts
|
|
291
|
-
var j = e`
|
|
292
|
-
import { browser } from '$app/environment';
|
|
293
|
-
import { loadLocale } from 'wuchale/load-utils';
|
|
294
|
-
|
|
295
|
-
import { getLocale } from '$locales/main.url';
|
|
296
|
-
import '$locales/main.loader.svelte';
|
|
297
|
-
import '$locales/js.loader';
|
|
298
|
-
|
|
299
|
-
export const load = async ({ url, data }) => {
|
|
300
|
-
const locale = getLocale(url);
|
|
301
|
-
|
|
302
|
-
if (browser) {
|
|
303
|
-
await loadLocale(locale);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return data;
|
|
307
|
-
};
|
|
308
|
-
`, M = [
|
|
309
|
-
"Merge the wuchale loader into your existing load function in +layout.ts:",
|
|
310
|
-
"",
|
|
311
|
-
j
|
|
312
|
-
].join("\n");
|
|
313
|
-
function N(e) {
|
|
314
|
-
if (d.existsSync(e)) {
|
|
315
|
-
let t = d.readFileSync(e, "utf8");
|
|
316
|
-
if (t.includes("loadLocale") || t.includes("translateUrl")) return {
|
|
317
|
-
status: "success",
|
|
318
|
-
changed: !1
|
|
319
|
-
};
|
|
320
|
-
if (/\bexport\s+(const|function)\s+load\b/.test(t)) return {
|
|
321
|
-
status: "failed",
|
|
322
|
-
message: M
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
return d.mkdirSync(u.dirname(e), { recursive: !0 }), d.writeFileSync(e, j + "\n"), {
|
|
285
|
+
return f.writeFileSync(t, i), {
|
|
326
286
|
status: "success",
|
|
327
287
|
changed: !0
|
|
328
288
|
};
|
|
329
289
|
}
|
|
330
290
|
//#endregion
|
|
331
291
|
//#region src/patterns/enable/i18n/modifies/root-layout.svelte.ts
|
|
332
|
-
var
|
|
292
|
+
var M = "<Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n ", N = e`
|
|
333
293
|
import LanguageSelect from '$lib/components/language-select.svelte';
|
|
334
|
-
`,
|
|
294
|
+
`, P = [
|
|
335
295
|
"Add the language select inside your <Navbar.List> in the root layout.",
|
|
336
296
|
"",
|
|
337
297
|
"Import to add to the <script> tag:",
|
|
338
298
|
"",
|
|
339
|
-
|
|
299
|
+
N,
|
|
340
300
|
"",
|
|
341
301
|
"Markup to add at the end of <Navbar.List>:",
|
|
342
|
-
|
|
343
|
-
].join("\n"),
|
|
302
|
+
M
|
|
303
|
+
].join("\n"), F = [
|
|
344
304
|
"Create a root layout that includes a language select inside <Navbar.List>.",
|
|
345
305
|
"",
|
|
346
306
|
"Import for the <script> tag:",
|
|
347
307
|
"",
|
|
348
|
-
|
|
308
|
+
N,
|
|
349
309
|
"",
|
|
350
310
|
"Markup at the end of <Navbar.List>:",
|
|
351
|
-
|
|
311
|
+
M
|
|
352
312
|
].join("\n");
|
|
353
|
-
function
|
|
354
|
-
if (!
|
|
313
|
+
function I(e) {
|
|
314
|
+
if (!f.existsSync(e)) return {
|
|
355
315
|
status: "not-found",
|
|
356
|
-
message:
|
|
316
|
+
message: F
|
|
357
317
|
};
|
|
358
|
-
let t =
|
|
318
|
+
let t = i.fromPath(e);
|
|
359
319
|
return t.hasElement("Navbar.List") ? t.hasElement("LanguageSelect") ? {
|
|
360
320
|
status: "success",
|
|
361
321
|
changed: !1
|
|
362
322
|
} : (t.modifyScript((e) => {
|
|
363
323
|
let { source: t } = r(e, (e) => {
|
|
364
|
-
|
|
324
|
+
a(e, [{
|
|
365
325
|
defaultImport: "LanguageSelect",
|
|
366
326
|
moduleSpecifier: "$lib/components/language-select.svelte"
|
|
367
327
|
}]);
|
|
368
328
|
});
|
|
369
329
|
return t;
|
|
370
|
-
}), t.insertBeforeClosingTag("Navbar.List",
|
|
330
|
+
}), t.insertBeforeClosingTag("Navbar.List", M), t.writeTo(e), {
|
|
371
331
|
status: "success",
|
|
372
332
|
changed: t.hasChanged()
|
|
373
333
|
}) : {
|
|
374
334
|
status: "failed",
|
|
375
|
-
message:
|
|
335
|
+
message: P
|
|
376
336
|
};
|
|
377
337
|
}
|
|
378
338
|
//#endregion
|
|
379
339
|
//#region src/patterns/enable/i18n/generate.runtime.ts
|
|
380
|
-
async function
|
|
340
|
+
async function L(e) {
|
|
381
341
|
let r = t(e), i = [], a = (e) => {
|
|
382
342
|
e && i.push(e);
|
|
383
343
|
};
|
|
384
344
|
r.info("Modifying vite.config");
|
|
385
|
-
let s = o(e.root, l) ??
|
|
386
|
-
a(n(s,
|
|
387
|
-
let c =
|
|
345
|
+
let s = o(e.root, l) ?? d.join(e.root, l[0]);
|
|
346
|
+
a(n(s, v(s))), r.info("Modifying config for i18n alias");
|
|
347
|
+
let c = x(e.root);
|
|
388
348
|
a(n(c.filePath, c.outcome)), r.info("Modifying hooks.server.ts");
|
|
389
|
-
let
|
|
390
|
-
a(n(
|
|
391
|
-
let
|
|
392
|
-
a(n(
|
|
393
|
-
let
|
|
394
|
-
a(n(
|
|
395
|
-
let
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
],
|
|
401
|
-
a(n(
|
|
402
|
-
let
|
|
403
|
-
return a(n(
|
|
349
|
+
let p = d.join(e.root, "src", "hooks.server.ts");
|
|
350
|
+
a(n(p, E(p))), r.info("Modifying app.html");
|
|
351
|
+
let m = d.join(e.root, "src", "app.html");
|
|
352
|
+
a(n(m, k(m))), r.info("Modifying root +layout.ts");
|
|
353
|
+
let h = d.join(e.root, "src", "routes", "+layout.ts");
|
|
354
|
+
a(n(h, u(h))), r.info("Modifying root layout language select");
|
|
355
|
+
let g = [
|
|
356
|
+
d.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
|
|
357
|
+
d.join(e.root, "src", "routes", "root-layout.svelte"),
|
|
358
|
+
d.join(e.root, "src", "routes", "(public)", "+layout.svelte"),
|
|
359
|
+
d.join(e.root, "src", "routes", "+layout.svelte")
|
|
360
|
+
], _ = g.find((e) => f.existsSync(e)) ?? g[0];
|
|
361
|
+
a(n(_, I(_))), r.info("Updating .gitignore");
|
|
362
|
+
let y = d.join(e.root, ".gitignore");
|
|
363
|
+
return a(n(y, j(y))), {
|
|
404
364
|
creates: [],
|
|
405
365
|
modifies: i,
|
|
406
366
|
deletes: [],
|
|
@@ -412,6 +372,6 @@ async function z(e) {
|
|
|
412
372
|
};
|
|
413
373
|
}
|
|
414
374
|
//#endregion
|
|
415
|
-
export {
|
|
375
|
+
export { L as generate };
|
|
416
376
|
|
|
417
|
-
//# sourceMappingURL=generate.runtime-
|
|
377
|
+
//# sourceMappingURL=generate.runtime-BKb9thdE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-BKb9thdE.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/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.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\";\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 sourceFile.formatText();\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 dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\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\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with an i18n handle:\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 = handleWuchale;\n`;\n\nfunction ensureNamedImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n name: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) {\n const has = existing.getNamedImports().some((ni) => ni.getName() === name);\n if (!has) existing.addNamedImport(name);\n return;\n }\n sourceFile.addImportDeclaration({ namedImports: [name], moduleSpecifier });\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 return { status: \"not-found\", message: NOT_FOUND_HINT };\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 const handleDecl = sourceFile.getVariableDeclaration(\"handle\");\n if (!handleDecl) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const handleStmt = handleDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!handleStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\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 statements = sourceFile.getStatements();\n const handleStmtIndex = statements.findIndex((s) => s === handleStmt);\n const i18nHandleName = \"handleWuchale\";\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 ${i18nHandleName} = 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 if (handleStmtIndex >= 0) {\n sourceFile.insertStatements(\n handleStmtIndex,\n `\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`,\n );\n } else {\n sourceFile.addStatements(`\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`);\n }\n\n const init = handleDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const initText = init.getText();\n if (initText.includes(i18nHandleName) || initText.includes(\"runWithLocale\")) {\n return { status: \"success\", changed: false };\n }\n\n handleDecl.setInitializer(`sequence(${i18nHandleName}, ${initText})`);\n sourceFile.formatText();\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\";\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 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\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\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 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, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\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 { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying 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 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 rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n rootLayoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath),\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 return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAIA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgB,EAAiB,GAAuC;CACtE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAOxD,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAc,GAEzD,IAAU,IACV,IAAS;CAMb,AAJkB,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,cAE1C,MACH,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,CA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C,IAAM,IAAc,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU;CAG7D,AAFA,EAAW,EAAoB,GAAa,EAAc,CAAW,CAAC,CAAC,GAEvE,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAa,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY;CAGxE,AAFA,EAAW,EAAoB,GAAY,EAAqB,CAAU,CAAC,CAAC,GAE5E,EAAO,KAAK,uCAAuC;CACnD,IAAM,IAAuB;EAC3B,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,oBAAoB;EACzE,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,oBAAoB;EAC7D,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,gBAAgB;EACrE,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAC3D,GACM,IACJ,EAAqB,MAAM,MAAM,EAAG,WAAW,CAAC,CAAC,KACjD,EAAqB;CAQvB,AAPA,EACE,EACE,GACA,EAA+B,CAAc,CAC/C,CACF,GAEA,EAAO,KAAK,qBAAqB;CACjC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,YAAY;CAK1D,OAJA,EACE,EAAoB,GAAe,EAAgB,CAAa,CAAC,CACnE,GAEO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
+
import { t } from "./shared--_BWnGsc.js";
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-Cgu_WeFk.js";
|
|
4
|
+
import { c as r, i, l as a, n as o } from "./ts-morph-helpers-Bf5iuQW8.js";
|
|
5
|
+
import { t as s } from "./unmodify-load-W1ePZQHr.js";
|
|
6
|
+
import c from "node:path";
|
|
7
|
+
import l from "node:fs";
|
|
8
|
+
//#region src/patterns/disable/notifications/modifies/modify-app-layout.ts
|
|
9
|
+
function u(e) {
|
|
10
|
+
if (!l.existsSync(e)) return {
|
|
11
|
+
status: "success",
|
|
12
|
+
changed: !1
|
|
13
|
+
};
|
|
14
|
+
let t = l.readFileSync(e, "utf8");
|
|
15
|
+
if (!t.includes("NotificationsBell")) return {
|
|
16
|
+
status: "success",
|
|
17
|
+
changed: !1
|
|
18
|
+
};
|
|
19
|
+
let n = a.fromPath(e);
|
|
20
|
+
n.modifyScript((e) => {
|
|
21
|
+
let { source: t } = r(e, (e) => {
|
|
22
|
+
i(e, "$lib/components/notifications-bell.svelte"), o(e);
|
|
23
|
+
});
|
|
24
|
+
return t;
|
|
25
|
+
});
|
|
26
|
+
let s = n.toString();
|
|
27
|
+
return s = s.replace(/\n*[ \t]*<div class="ml-auto px-4">\s*<NotificationsBell\s*\/>\s*<\/div>[ \t]*/g, ""), s = s.replace(/[ \t]*<NotificationsBell\s*\/>[ \t]*\r?\n?/g, ""), l.writeFileSync(e, s, "utf8"), {
|
|
28
|
+
status: "success",
|
|
29
|
+
changed: s !== t
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/patterns/disable/notifications/modifies/+layout.server.ts
|
|
34
|
+
function d(e) {
|
|
35
|
+
return s(e, {
|
|
36
|
+
variables: ["notificationsList", "notifications"],
|
|
37
|
+
dependsKeys: ["app:notifications"],
|
|
38
|
+
returnProps: ["notifications"]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/patterns/disable/notifications/generate.runtime.ts
|
|
43
|
+
async function f(r) {
|
|
44
|
+
let i = e(r), a = [], o = (e) => {
|
|
45
|
+
e && a.push(e);
|
|
46
|
+
};
|
|
47
|
+
i.info("Reverting (app) +layout.svelte");
|
|
48
|
+
let s = c.join(r.root, "src", "routes", "(app)", "+layout.svelte");
|
|
49
|
+
o(n(s, u(s))), i.info("Reverting (app) +layout.server.ts");
|
|
50
|
+
let l = c.join(r.root, "src", "routes", "(app)", "+layout.server.ts");
|
|
51
|
+
return o(n(l, d(l))), {
|
|
52
|
+
creates: [],
|
|
53
|
+
modifies: a,
|
|
54
|
+
deletes: [],
|
|
55
|
+
components: [],
|
|
56
|
+
packages: [],
|
|
57
|
+
collections: [],
|
|
58
|
+
collectionPatches: [],
|
|
59
|
+
collectionDrops: await t(["notifications"], r)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { f as generate };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=generate.runtime-BdTCMGGB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-BdTCMGGB.js","names":[],"sources":["../../src/patterns/disable/notifications/modifies/modify-app-layout.ts","../../src/patterns/disable/notifications/modifies/+layout.server.ts","../../src/patterns/disable/notifications/generate.runtime.ts"],"sourcesContent":["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 bell (and the wrapper enable-notifications put it in) out of the header. */\nexport function unmodifyAppLayout(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(\"NotificationsBell\")) {\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/notifications-bell.svelte\",\n );\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n let updated = file.toString();\n updated = updated.replace(\n /\\n*[ \\t]*<div class=\"ml-auto px-4\">\\s*<NotificationsBell\\s*\\/>\\s*<\\/div>[ \\t]*/g,\n \"\",\n );\n updated = updated.replace(/[ \\t]*<NotificationsBell\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: updated !== original };\n}\n","import type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\n\n/** Take the unread-notifications query back out of the (app) layout's load. */\nexport function unmodifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n return removeFromLoad(layoutServerPath, {\n variables: [\"notificationsList\", \"notifications\"],\n dependsKeys: [\"app:notifications\"],\n returnProps: [\"notifications\"],\n });\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { unmodifyAppLayout } from \"./modifies/modify-app-layout\";\nimport { unmodifyLayoutServer } from \"./modifies/+layout.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, unmodifyAppLayout(appLayoutPath)),\n );\n\n logger.info(\"Reverting (app) +layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n unmodifyLayoutServer(appLayoutServerPath),\n ),\n );\n\n // The timeAgo helper enable-notifications added to $lib/utils stays: it is\n // generic, and other code may have started using it.\n\n const collectionDrops = await planDropsForCollections(\n [\"notifications\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,EAAkB,GAAmC;CACnE,IAAI,CAAC,EAAG,WAAW,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAW,EAAG,aAAa,GAAY,MAAM;CACnD,IAAI,CAAC,EAAS,SAAS,mBAAmB,GACxC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAO,EAAW,SAAS,CAAU;CAC3C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQ,MAAQ,EAAmB,IAAS,MAAO;GAKzD,AAJA,EACE,GACA,2CACF,GACA,EAA4B,CAAE;EAChC,CAAC;EACD,OAAO;CACT,CAAC;CAED,IAAI,IAAU,EAAK,SAAS;CAQ5B,OAPA,IAAU,EAAQ,QAChB,mFACA,EACF,GACA,IAAU,EAAQ,QAAQ,+CAA+C,EAAE,GAE3E,EAAG,cAAc,GAAY,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAAS,MAAY;CAAS;AAC5D;;;ACrCA,SAAgB,EAAqB,GAAyC;CAC5E,OAAO,EAAe,GAAkB;EACtC,WAAW,CAAC,qBAAqB,eAAe;EAChD,aAAa,CAAC,mBAAmB;EACjC,aAAa,CAAC,eAAe;CAC/B,CAAC;AACH;;;ACFA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAmB,CAAC,GACpB,KAAc,MAAsB;EACxC,AAAI,KAAM,EAAS,KAAK,CAAI;CAC9B;CAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAM,IAAgB,EAAK,KACzB,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAKA,AAJA,EACE,EAAoB,GAAe,EAAkB,CAAa,CAAC,CACrE,GAEA,EAAO,KAAK,mCAAmC;CAC/C,IAAM,IAAsB,EA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