@velastack/patterns 0.8.0 → 0.10.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.
- package/dist/chunks/_page-B6yd6_Vl.js +6 -0
- package/dist/chunks/_page-B6yd6_Vl.js.map +1 -0
- package/dist/chunks/{collections-BrEA7a62.js → collections-DZOuRpvS.js} +6 -1
- package/dist/chunks/collections-DZOuRpvS.js.map +1 -0
- package/dist/chunks/{generate-BZ741GPx.js → currency.server-Bb2Ndutg.js} +6 -3
- package/dist/chunks/{generate-BZ741GPx.js.map → currency.server-Bb2Ndutg.js.map} +1 -1
- package/dist/chunks/{generate-6JS05dWK.js → generate-B-cqjI-U.js} +62 -55
- package/dist/chunks/generate-B-cqjI-U.js.map +1 -0
- package/dist/chunks/generate-BrOPb9tW.js +175 -0
- package/dist/chunks/generate-BrOPb9tW.js.map +1 -0
- package/dist/chunks/{generate.runtime-BOl3LpPB.js → generate.runtime-BnqS_Zq8.js} +84 -158
- package/dist/chunks/generate.runtime-BnqS_Zq8.js.map +1 -0
- package/dist/chunks/{generate.runtime-KrQk7mqG.js → generate.runtime-DG9Lp3vR.js} +39 -37
- package/dist/chunks/generate.runtime-DG9Lp3vR.js.map +1 -0
- package/dist/chunks/generate.runtime-DuDcKDUl.js +162 -0
- package/dist/chunks/generate.runtime-DuDcKDUl.js.map +1 -0
- package/dist/chunks/{generate.runtime-Dt3Edp8-.js → generate.runtime-J2lLMjDn.js} +97 -126
- package/dist/chunks/generate.runtime-J2lLMjDn.js.map +1 -0
- package/dist/chunks/generate.runtime-nyJ6v56q.js +64 -0
- package/dist/chunks/generate.runtime-nyJ6v56q.js.map +1 -0
- package/dist/chunks/load-function-Dmkhg1pQ.js +79 -0
- package/dist/chunks/load-function-Dmkhg1pQ.js.map +1 -0
- package/dist/chunks/modify-nav-user-iUpv2lm-.js +53 -0
- package/dist/chunks/modify-nav-user-iUpv2lm-.js.map +1 -0
- package/dist/chunks/root-layout.svelte-CUVbnlX-.js +302 -0
- package/dist/chunks/root-layout.svelte-CUVbnlX-.js.map +1 -0
- package/dist/index.d.ts +156 -2
- package/dist/index.js +1972 -1807
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/collections-BrEA7a62.js.map +0 -1
- package/dist/chunks/generate-6JS05dWK.js.map +0 -1
- package/dist/chunks/generate.runtime-BOl3LpPB.js.map +0 -1
- package/dist/chunks/generate.runtime-Dt3Edp8-.js.map +0 -1
- package/dist/chunks/generate.runtime-KrQk7mqG.js.map +0 -1
- package/dist/chunks/root-layout.svelte-CsJ2QJYi.js +0 -93
- package/dist/chunks/root-layout.svelte-CsJ2QJYi.js.map +0 -1
|
@@ -5,11 +5,12 @@ import { _ as r, o as i, r as a } from "./ts-morph-helpers-CHI9wAil.js";
|
|
|
5
5
|
import { r as o } from "./modify-file-B4uJzOEj.js";
|
|
6
6
|
import { t as s } from "./svelte-file-Dv5-bl79.js";
|
|
7
7
|
import { a as c, t as l } from "./config-target-BgyFkbFL.js";
|
|
8
|
-
import u from "
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
import { a as u, c as d, i as f, l as p, n as m, o as h, r as g, s as _, t as v } from "./load-function-Dmkhg1pQ.js";
|
|
9
|
+
import y from "node:fs";
|
|
10
|
+
import b from "node:path";
|
|
11
|
+
import { Node as x, Project as S, QuoteKind as C, SyntaxKind as w } from "ts-morph";
|
|
11
12
|
//#region src/patterns/enable/cms/modifies/vite-config.ts
|
|
12
|
-
var
|
|
13
|
+
var T = [
|
|
13
14
|
"Add the CMS plugin to your Vite config, ahead of sveltekit():",
|
|
14
15
|
"",
|
|
15
16
|
"import { cms } from '@velastack/cms/vite';",
|
|
@@ -17,7 +18,7 @@ var g = [
|
|
|
17
18
|
"export default defineConfig({",
|
|
18
19
|
" plugins: [cms(), sveltekit(), /* ...existing plugins */],",
|
|
19
20
|
"});"
|
|
20
|
-
].join("\n"),
|
|
21
|
+
].join("\n"), E = [
|
|
21
22
|
"Create a Vite config with the CMS plugin ahead of sveltekit():",
|
|
22
23
|
"",
|
|
23
24
|
"import { defineConfig } from 'vite';",
|
|
@@ -28,24 +29,24 @@ var g = [
|
|
|
28
29
|
" plugins: [cms(), sveltekit()],",
|
|
29
30
|
"});"
|
|
30
31
|
].join("\n");
|
|
31
|
-
function
|
|
32
|
+
function D(e) {
|
|
32
33
|
return e.replace(/\s/g, "");
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
+
function O(e, t = "") {
|
|
35
36
|
let n = `cms(${t})`;
|
|
36
|
-
if (!
|
|
37
|
+
if (!y.existsSync(e)) return {
|
|
37
38
|
status: "not-found",
|
|
38
|
-
message:
|
|
39
|
+
message: E
|
|
39
40
|
};
|
|
40
|
-
let r = new
|
|
41
|
+
let r = new S({
|
|
41
42
|
compilerOptions: { allowJs: !0 },
|
|
42
|
-
manipulationSettings: { quoteKind:
|
|
43
|
+
manipulationSettings: { quoteKind: C.Single }
|
|
43
44
|
}).addSourceFileAtPath(e), a = !1, o = !1;
|
|
44
45
|
r.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "@velastack/cms/vite") || (r.insertImportDeclaration(0, {
|
|
45
46
|
namedImports: ["cms"],
|
|
46
47
|
moduleSpecifier: "@velastack/cms/vite"
|
|
47
48
|
}), a = !0);
|
|
48
|
-
let s = r.getDescendantsOfKind(
|
|
49
|
+
let s = r.getDescendantsOfKind(w.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], c = s?.getKind() === w.ObjectLiteralExpression ? s : null;
|
|
49
50
|
if (!c) o = !0;
|
|
50
51
|
else {
|
|
51
52
|
let e = c.getProperty("plugins");
|
|
@@ -53,15 +54,15 @@ function y(e, t = "") {
|
|
|
53
54
|
name: "plugins",
|
|
54
55
|
initializer: `[${n}]`
|
|
55
56
|
}), a = !0;
|
|
56
|
-
else if (e.getKind() !==
|
|
57
|
+
else if (e.getKind() !== w.PropertyAssignment) o = !0;
|
|
57
58
|
else {
|
|
58
59
|
let t = e.getInitializer();
|
|
59
60
|
if (!t) e.setInitializer(`[${n}]`), a = !0;
|
|
60
|
-
else if (t.getKind() !==
|
|
61
|
+
else if (t.getKind() !== w.ArrayLiteralExpression) o = !0;
|
|
61
62
|
else {
|
|
62
63
|
let e = t, r = e.getElements();
|
|
63
|
-
if (!r.some((e) =>
|
|
64
|
-
let t = r.findIndex((e) =>
|
|
64
|
+
if (!r.some((e) => D(e.getText()).startsWith("cms("))) {
|
|
65
|
+
let t = r.findIndex((e) => D(e.getText()).startsWith("sveltekit("));
|
|
65
66
|
e.insertElement(t === -1 ? 0 : t, n), a = !0;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -69,97 +70,22 @@ function y(e, t = "") {
|
|
|
69
70
|
}
|
|
70
71
|
return a && (i(r), r.saveSync()), o ? {
|
|
71
72
|
status: "failed",
|
|
72
|
-
message:
|
|
73
|
+
message: T
|
|
73
74
|
} : {
|
|
74
75
|
status: "success",
|
|
75
76
|
changed: a
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
//#endregion
|
|
79
|
-
//#region src/patterns/enable/cms/modifies/load-function.ts
|
|
80
|
-
function b() {
|
|
81
|
-
return new p({
|
|
82
|
-
compilerOptions: { allowJs: !0 },
|
|
83
|
-
manipulationSettings: { quoteKind: m.Single }
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function x(e, t, n) {
|
|
87
|
-
let r = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t);
|
|
88
|
-
if (!r) e.addImportDeclaration({
|
|
89
|
-
namedImports: n,
|
|
90
|
-
moduleSpecifier: t
|
|
91
|
-
});
|
|
92
|
-
else for (let e of n) r.getNamedImports().some((t) => t.getName() === e) || r.addNamedImport(e);
|
|
93
|
-
}
|
|
94
|
-
function S(e, t) {
|
|
95
|
-
t.namedImports?.length && x(e, t.moduleSpecifier, t.namedImports), !e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t.moduleSpecifier) && e.addImportDeclaration({
|
|
96
|
-
moduleSpecifier: t.moduleSpecifier,
|
|
97
|
-
defaultImport: t.defaultImport,
|
|
98
|
-
namespaceImport: t.namespaceImport
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function C(e) {
|
|
102
|
-
if (f.isArrowFunction(e) || f.isFunctionExpression(e)) return e;
|
|
103
|
-
if (f.isParenthesizedExpression(e) || f.isAsExpression(e) || f.isSatisfiesExpression(e)) return C(e.getExpression());
|
|
104
|
-
if (f.isCallExpression(e)) for (let t of e.getArguments()) {
|
|
105
|
-
let e = C(t);
|
|
106
|
-
if (e) return e;
|
|
107
|
-
}
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
function w(e) {
|
|
111
|
-
let t = e.getFunction("load");
|
|
112
|
-
if (t) return t.isExported() ? t : null;
|
|
113
|
-
let n = e.getVariableDeclaration("load");
|
|
114
|
-
if (!n || !n.getVariableStatement()?.isExported()) return null;
|
|
115
|
-
let r = n.getInitializer();
|
|
116
|
-
return r ? C(r) : null;
|
|
117
|
-
}
|
|
118
|
-
function T(e) {
|
|
119
|
-
return f.isArrowFunction(e) || f.isFunctionExpression(e) || f.isFunctionDeclaration(e) || f.isMethodDeclaration(e);
|
|
120
|
-
}
|
|
121
|
-
function E(e, t) {
|
|
122
|
-
let n = t.getStatements(), r = n[n.length - 1];
|
|
123
|
-
return !r || !f.isReturnStatement(r) || t.getDescendantsOfKind(h.ReturnStatement).filter((t) => t.getFirstAncestor(T) === e).length !== 1 ? null : r;
|
|
124
|
-
}
|
|
125
|
-
function D(e) {
|
|
126
|
-
let t = e.getExpression();
|
|
127
|
-
for (; t && f.isParenthesizedExpression(t);) t = t.getExpression();
|
|
128
|
-
return !t || !f.isObjectLiteralExpression(t) ? null : t;
|
|
129
|
-
}
|
|
130
|
-
function O(e, t) {
|
|
131
|
-
return e.getProperties().some((e) => f.isPropertyAssignment(e) || f.isShorthandPropertyAssignment(e) ? e.getName() === t : !1);
|
|
132
|
-
}
|
|
133
|
-
function k(e, t) {
|
|
134
|
-
return e.getProperties().some((e) => f.isSpreadAssignment(e) && e.getExpression().getText() === t);
|
|
135
|
-
}
|
|
136
|
-
function A(e) {
|
|
137
|
-
let t = e.getParameters();
|
|
138
|
-
if (t.length === 0) return { kind: "none" };
|
|
139
|
-
if (t.length > 1) return { kind: "unsupported" };
|
|
140
|
-
let n = t[0];
|
|
141
|
-
if (n.getInitializer() || n.isRestParameter()) return { kind: "unsupported" };
|
|
142
|
-
let r = n.getNameNode();
|
|
143
|
-
return f.isIdentifier(r) ? {
|
|
144
|
-
kind: "identifier",
|
|
145
|
-
name: r.getText(),
|
|
146
|
-
param: n
|
|
147
|
-
} : f.isObjectBindingPattern(r) ? {
|
|
148
|
-
kind: "binding",
|
|
149
|
-
pattern: r,
|
|
150
|
-
param: n
|
|
151
|
-
} : { kind: "unsupported" };
|
|
152
|
-
}
|
|
153
|
-
//#endregion
|
|
154
80
|
//#region src/patterns/enable/cms/modifies/layout.server.ts
|
|
155
|
-
var
|
|
81
|
+
var k = { expression: () => "'en'" }, A = {
|
|
156
82
|
expression: (e) => `getLocale(${e}.url)`,
|
|
157
83
|
imports: [{
|
|
158
84
|
namedImports: ["getLocale"],
|
|
159
85
|
moduleSpecifier: "#locales/main.url.js"
|
|
160
86
|
}]
|
|
161
87
|
};
|
|
162
|
-
function
|
|
88
|
+
function j(t, n) {
|
|
163
89
|
return e`
|
|
164
90
|
const { cms, notFound, gone, redirectTo } = await loadCms(${t}, { locale: ${n} });
|
|
165
91
|
if (redirectTo) redirect(308, redirectTo);
|
|
@@ -167,17 +93,17 @@ function N(t, n) {
|
|
|
167
93
|
if (notFound) error(404, 'Not found');
|
|
168
94
|
`;
|
|
169
95
|
}
|
|
170
|
-
function
|
|
96
|
+
function M(e) {
|
|
171
97
|
let t = [];
|
|
172
98
|
return e.defaultImport && t.push(e.defaultImport), e.namespaceImport && t.push(`* as ${e.namespaceImport}`), e.namedImports?.length && t.push(`{ ${e.namedImports.join(", ")} }`), `import ${t.join(", ")} from '${e.moduleSpecifier}';`;
|
|
173
99
|
}
|
|
174
|
-
function
|
|
100
|
+
function N(t) {
|
|
175
101
|
let n = [
|
|
176
102
|
"import { error, redirect } from '@sveltejs/kit';",
|
|
177
103
|
"import { loadCms } from '#lib/cms.js';",
|
|
178
|
-
...(t.imports ?? []).map(
|
|
104
|
+
...(t.imports ?? []).map(M),
|
|
179
105
|
"import type { LayoutServerLoad } from './$types';"
|
|
180
|
-
].join("\n"), r =
|
|
106
|
+
].join("\n"), r = j("event", t.expression("event")).split("\n").join("\n ");
|
|
181
107
|
return e`
|
|
182
108
|
${n}
|
|
183
109
|
|
|
@@ -188,57 +114,57 @@ function F(t) {
|
|
|
188
114
|
};
|
|
189
115
|
`.concat("\n");
|
|
190
116
|
}
|
|
191
|
-
var
|
|
117
|
+
var P = [
|
|
192
118
|
"Call loadCms from the root +layout.server.ts load and return `cms`:",
|
|
193
119
|
"",
|
|
194
|
-
|
|
120
|
+
N(k).trimEnd(),
|
|
195
121
|
"",
|
|
196
122
|
"loadCms needs the whole event, so a destructured parameter has to become",
|
|
197
123
|
"`event` with the destructuring moved into the body."
|
|
198
124
|
].join("\n");
|
|
199
|
-
function
|
|
200
|
-
if (!
|
|
125
|
+
function F(e, t = k) {
|
|
126
|
+
if (!y.existsSync(e)) return y.mkdirSync(b.dirname(e), { recursive: !0 }), y.writeFileSync(e, N(t)), {
|
|
201
127
|
status: "success",
|
|
202
128
|
changed: !0
|
|
203
129
|
};
|
|
204
|
-
if (
|
|
130
|
+
if (y.readFileSync(e, "utf8").includes("loadCms(")) return {
|
|
205
131
|
status: "success",
|
|
206
132
|
changed: !1
|
|
207
133
|
};
|
|
208
|
-
let n =
|
|
134
|
+
let n = d().addSourceFileAtPath(e), r = f(n);
|
|
209
135
|
if (!r) return {
|
|
210
136
|
status: "failed",
|
|
211
|
-
message:
|
|
137
|
+
message: P
|
|
212
138
|
};
|
|
213
139
|
let a = r.getBody();
|
|
214
|
-
if (!a || !
|
|
140
|
+
if (!a || !x.isBlock(a)) return {
|
|
215
141
|
status: "failed",
|
|
216
|
-
message:
|
|
142
|
+
message: P
|
|
217
143
|
};
|
|
218
|
-
let o =
|
|
144
|
+
let o = _(r);
|
|
219
145
|
if (o.kind === "unsupported") return {
|
|
220
146
|
status: "failed",
|
|
221
|
-
message:
|
|
147
|
+
message: P
|
|
222
148
|
};
|
|
223
|
-
let s =
|
|
149
|
+
let s = g(r, a), c = s && p(s);
|
|
224
150
|
if (!s || !c) return {
|
|
225
151
|
status: "failed",
|
|
226
|
-
message:
|
|
152
|
+
message: P
|
|
227
153
|
};
|
|
228
154
|
let l = o.kind === "identifier" ? o.name : "event";
|
|
229
|
-
if (!
|
|
230
|
-
let e = c.getProperties().findIndex((e) =>
|
|
155
|
+
if (!u(c, "cms")) {
|
|
156
|
+
let e = c.getProperties().findIndex((e) => x.isSpreadAssignment(e));
|
|
231
157
|
e === -1 ? c.addShorthandPropertyAssignment({ name: "cms" }) : c.insertShorthandPropertyAssignment(e, { name: "cms" });
|
|
232
158
|
}
|
|
233
|
-
let
|
|
234
|
-
if (a.insertStatements(
|
|
159
|
+
let h = a.getStatementsWithComments().indexOf(s);
|
|
160
|
+
if (a.insertStatements(h, `\n${j(l, t.expression(l))}\n`), o.kind === "binding") {
|
|
235
161
|
let e = o.pattern.getText();
|
|
236
162
|
a.insertStatements(0, `const ${e} = ${l};`);
|
|
237
163
|
let t = o.param.getTypeNode()?.getText();
|
|
238
164
|
o.param.replaceWithText(t ? `${l}: ${t}` : l);
|
|
239
165
|
} else o.kind === "none" && r.addParameter({ name: l });
|
|
240
|
-
r.isAsync() || r.setIsAsync(!0),
|
|
241
|
-
for (let e of t.imports ?? [])
|
|
166
|
+
r.isAsync() || r.setIsAsync(!0), m(n, "@sveltejs/kit", ["error", "redirect"]), m(n, "#lib/cms.js", ["loadCms"]);
|
|
167
|
+
for (let e of t.imports ?? []) v(n, e);
|
|
242
168
|
return i(n), n.saveSync(), {
|
|
243
169
|
status: "success",
|
|
244
170
|
changed: !0
|
|
@@ -246,7 +172,7 @@ function L(e, t = j) {
|
|
|
246
172
|
}
|
|
247
173
|
//#endregion
|
|
248
174
|
//#region src/patterns/enable/cms/modifies/layout.ts
|
|
249
|
-
var
|
|
175
|
+
var I = e`
|
|
250
176
|
Forward the server load's data through the root +layout.ts, so \`cms\` reaches
|
|
251
177
|
the page:
|
|
252
178
|
|
|
@@ -255,42 +181,42 @@ var R = e`
|
|
|
255
181
|
return { ...data, /* existing keys */ };
|
|
256
182
|
};
|
|
257
183
|
`;
|
|
258
|
-
function
|
|
259
|
-
if (!
|
|
184
|
+
function L(e) {
|
|
185
|
+
if (!y.existsSync(e)) return {
|
|
260
186
|
status: "success",
|
|
261
187
|
changed: !1
|
|
262
188
|
};
|
|
263
|
-
let t =
|
|
189
|
+
let t = d().addSourceFileAtPath(e), n = f(t);
|
|
264
190
|
if (!n) return {
|
|
265
191
|
status: "success",
|
|
266
192
|
changed: !1
|
|
267
193
|
};
|
|
268
194
|
let r = n.getBody();
|
|
269
|
-
if (!r || !
|
|
195
|
+
if (!r || !x.isBlock(r)) return {
|
|
270
196
|
status: "failed",
|
|
271
|
-
message:
|
|
197
|
+
message: I
|
|
272
198
|
};
|
|
273
|
-
let a =
|
|
199
|
+
let a = _(n);
|
|
274
200
|
if (a.kind === "unsupported") return {
|
|
275
201
|
status: "failed",
|
|
276
|
-
message:
|
|
202
|
+
message: I
|
|
277
203
|
};
|
|
278
|
-
let o =
|
|
204
|
+
let o = g(n, r);
|
|
279
205
|
if (!o) return {
|
|
280
206
|
status: "failed",
|
|
281
|
-
message:
|
|
207
|
+
message: I
|
|
282
208
|
};
|
|
283
209
|
let s = a.kind === "identifier" ? `${a.name}.data` : "data", c = o.getExpression();
|
|
284
210
|
if (c && c.getText() === s) return {
|
|
285
211
|
status: "success",
|
|
286
212
|
changed: !1
|
|
287
213
|
};
|
|
288
|
-
let l =
|
|
214
|
+
let l = p(o);
|
|
289
215
|
if (!l) return {
|
|
290
216
|
status: "failed",
|
|
291
|
-
message:
|
|
217
|
+
message: I
|
|
292
218
|
};
|
|
293
|
-
if (
|
|
219
|
+
if (h(l, s)) return {
|
|
294
220
|
status: "success",
|
|
295
221
|
changed: !1
|
|
296
222
|
};
|
|
@@ -307,31 +233,31 @@ function z(e) {
|
|
|
307
233
|
}
|
|
308
234
|
//#endregion
|
|
309
235
|
//#region src/patterns/enable/cms/modifies/layout.svelte.ts
|
|
310
|
-
var
|
|
236
|
+
var R = e`
|
|
311
237
|
import { AdminBar } from '@velastack/cms';
|
|
312
|
-
`,
|
|
238
|
+
`, z = "\n<AdminBar />\n", B = [
|
|
313
239
|
"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.",
|
|
314
240
|
"",
|
|
315
241
|
"Import for the <script> tag:",
|
|
316
242
|
"",
|
|
317
|
-
|
|
243
|
+
R,
|
|
318
244
|
"",
|
|
319
245
|
"Markup to add at the top level of the layout, above {@render children()}:",
|
|
320
|
-
|
|
321
|
-
].join("\n"),
|
|
246
|
+
z.trim()
|
|
247
|
+
].join("\n"), V = [
|
|
322
248
|
"Mount <AdminBar /> in the root src/routes/+layout.svelte.",
|
|
323
249
|
"",
|
|
324
250
|
"Import for a <script lang=\"ts\"> tag:",
|
|
325
251
|
"",
|
|
326
|
-
|
|
252
|
+
R,
|
|
327
253
|
"",
|
|
328
254
|
"Markup to add at the top level of the layout, above {@render children()}:",
|
|
329
|
-
|
|
255
|
+
z.trim()
|
|
330
256
|
].join("\n");
|
|
331
|
-
function
|
|
332
|
-
if (!
|
|
257
|
+
function H(e) {
|
|
258
|
+
if (!y.existsSync(e)) return {
|
|
333
259
|
status: "not-found",
|
|
334
|
-
message:
|
|
260
|
+
message: B
|
|
335
261
|
};
|
|
336
262
|
let t = s.fromPath(e);
|
|
337
263
|
return t.hasElement("AdminBar") ? {
|
|
@@ -345,42 +271,42 @@ function W(e) {
|
|
|
345
271
|
}]);
|
|
346
272
|
});
|
|
347
273
|
return t;
|
|
348
|
-
}), t.insertBeforeChildren(
|
|
274
|
+
}), t.insertBeforeChildren(z) || t.appendMarkup(z), t.writeTo(e), {
|
|
349
275
|
status: "success",
|
|
350
276
|
changed: t.hasChanged()
|
|
351
277
|
}) : {
|
|
352
278
|
status: "failed",
|
|
353
|
-
message:
|
|
279
|
+
message: V
|
|
354
280
|
};
|
|
355
281
|
}
|
|
356
282
|
//#endregion
|
|
357
283
|
//#region src/patterns/enable/cms/generate.runtime.ts
|
|
358
|
-
function
|
|
359
|
-
let t =
|
|
360
|
-
if (!
|
|
361
|
-
let n =
|
|
284
|
+
function U(e) {
|
|
285
|
+
let t = b.join(e, "wuchale.config.js");
|
|
286
|
+
if (!y.existsSync(t)) return null;
|
|
287
|
+
let n = y.readFileSync(t, "utf8").match(/locales:\s*\[([^\]]*)\]/);
|
|
362
288
|
if (!n) return null;
|
|
363
289
|
let r = [...n[1].matchAll(/['"]([^'"]+)['"]/g)].map((e) => e[1]);
|
|
364
290
|
return r.length > 0 ? r : null;
|
|
365
291
|
}
|
|
366
|
-
function
|
|
292
|
+
function W(e, t) {
|
|
367
293
|
if (e.local) return "";
|
|
368
294
|
let n = t.map((e) => `'${e}'`).join(", ");
|
|
369
295
|
return `{ endpoint: '${e.endpoint}', locales: [${n}] }`;
|
|
370
296
|
}
|
|
371
|
-
async function
|
|
297
|
+
async function G(e) {
|
|
372
298
|
let r = t(e), i = [], a = n(e), s = e.features.i18n, u = (e) => {
|
|
373
299
|
e && i.push(e);
|
|
374
300
|
};
|
|
375
301
|
r.info("Modifying vite.config");
|
|
376
|
-
let
|
|
377
|
-
u(o(
|
|
378
|
-
let
|
|
379
|
-
u(o(
|
|
380
|
-
let
|
|
381
|
-
u(o(
|
|
382
|
-
let
|
|
383
|
-
return u(o(
|
|
302
|
+
let d = c(e.root, l) ?? b.join(e.root, l[0]), f = s && U(e.root) || ["en"];
|
|
303
|
+
u(o(d, O(d, W(a, f)))), r.info("Modifying src/routes/+layout.server.ts");
|
|
304
|
+
let p = b.join(e.root, "src", "routes", "+layout.server.ts");
|
|
305
|
+
u(o(p, F(p, s ? A : k))), r.info("Modifying src/routes/+layout.ts");
|
|
306
|
+
let m = b.join(e.root, "src", "routes", "+layout.ts");
|
|
307
|
+
u(o(m, L(m))), r.info("Modifying src/routes/+layout.svelte");
|
|
308
|
+
let h = b.join(e.root, "src", "routes", "+layout.svelte");
|
|
309
|
+
return u(o(h, H(h))), {
|
|
384
310
|
creates: [],
|
|
385
311
|
modifies: i,
|
|
386
312
|
deletes: [],
|
|
@@ -392,6 +318,6 @@ async function q(e) {
|
|
|
392
318
|
};
|
|
393
319
|
}
|
|
394
320
|
//#endregion
|
|
395
|
-
export {
|
|
321
|
+
export { G as generate };
|
|
396
322
|
|
|
397
|
-
//# sourceMappingURL=generate.runtime-
|
|
323
|
+
//# sourceMappingURL=generate.runtime-BnqS_Zq8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-BnqS_Zq8.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","dedent","getLogger","withInMemoryScript","formatLikeSource","ensureImports","modifyOutcomeToFile","SvelteFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","hasProperty","newProject","findLoadFunction","returnedObject","ensureNamedImports","hasSpreadOf","findFinalReturn","inspectEventParameter","ensureImportSpec","fs","path","FAILURE_HINT$3","NOT_FOUND_HINT$1","elementName","text","modifyViteConfig","call","pluginArgs","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","elements","el","sveltekitIndex","DEFAULT_LOCALE","WUCHALE_LOCALE","eventName","cmsSnippet","locale","importLine","parts","spec","createdLayoutServer","imports","snippet","FAILURE_HINT$2","modifyLayoutServer","layoutServerPath","fn","body","Node","event","returned","object","spreadIndex","property","returnIndex","destructuring","typeText","FAILURE_HINT$1","modifyLayoutUniversal","layoutPath","dataExpression","expression","element","IMPORT_SNIPPET","MARKUP_SNIPPET","NOT_FOUND_HINT","FAILURE_HINT","modifyLayoutSvelte","file","out","source","sf","readWuchaleLocales","configPath","root","match","locales","m","vitePluginArgs","mode","list","generate","logger","options","modifies","resolveMode","i18n","pushResult","layoutUniversalPath","layoutSveltePath"],"sources":["../../src/patterns/enable/cms/modifies/vite-config.ts","../../src/patterns/enable/cms/modifies/layout.server.ts","../../src/patterns/enable/cms/modifies/layout.ts","../../src/patterns/enable/cms/modifies/layout.svelte.ts","../../src/patterns/enable/cms/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the CMS plugin to your Vite config, ahead of sveltekit():\",\n \"\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the CMS plugin ahead of sveltekit():\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit()],\",\n \"});\",\n].join(\"\\n\");\n\nfunction elementName(text: string): string {\n return text.replace(/\\s/g, \"\");\n}\n\n/**\n * Registers `cms(...)` from `@velastack/cms/vite` in the Vite plugin list, just\n * ahead of `sveltekit()`. Only the plugin array is touched, so the inline\n * `sveltekit({ ... })` shape the templates use is left alone.\n */\nexport function modifyViteConfig(\n viteConfigPath: string,\n pluginArgs = \"\",\n): ModifyOutcome {\n const call = `cms(${pluginArgs})`;\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() === \"@velastack/cms/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"cms\"],\n moduleSpecifier: \"@velastack/cms/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 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: `[${call}]`,\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (pluginsProp as PropertyAssignment).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as PropertyAssignment).setInitializer(`[${call}]`);\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as ArrayLiteralExpression;\n const elements = arr.getElements();\n const hasCms = elements.some((el) =>\n elementName(el.getText()).startsWith(\"cms(\"),\n );\n\n if (!hasCms) {\n const sveltekitIndex = elements.findIndex((el) =>\n elementName(el.getText()).startsWith(\"sveltekit(\"),\n );\n arr.insertElement(sveltekitIndex === -1 ? 0 : sveltekitIndex, call);\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n ensureImportSpec,\n ensureNamedImports,\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport interface LayoutServerLocale {\n /**\n * Expression passed as `locale` to `loadCms`, given the name of the load's\n * event parameter: `() => \"'en'\"` or `(event) => \\`getLocale(${event}.url)\\``.\n */\n expression: (eventName: string) => string;\n /** Imports the expression depends on. */\n imports?: ImportSpec[];\n}\n\n/** A single-locale site: the literal default locale. */\nexport const DEFAULT_LOCALE: LayoutServerLocale = {\n expression: () => \"'en'\",\n};\n\n/** A wuchale site: the locale enable-i18n's reroute already resolved from the URL. */\nexport const WUCHALE_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `getLocale(${eventName}.url)`,\n imports: [\n { namedImports: [\"getLocale\"], moduleSpecifier: \"#locales/main.url.js\" },\n ],\n};\n\nfunction cmsSnippet(eventName: string, locale: string): string {\n return dedent`\n const { cms, notFound, gone, redirectTo } = await loadCms(${eventName}, { locale: ${locale} });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n `;\n}\n\nfunction importLine(spec: ImportSpec): string {\n const parts: string[] = [];\n if (spec.defaultImport) parts.push(spec.defaultImport);\n if (spec.namespaceImport) parts.push(`* as ${spec.namespaceImport}`);\n if (spec.namedImports?.length)\n parts.push(`{ ${spec.namedImports.join(\", \")} }`);\n return `import ${parts.join(\", \")} from '${spec.moduleSpecifier}';`;\n}\n\n/**\n * A root `+layout.server.ts` written from scratch, for a project that has\n * none — the static template keeps its layout load universal.\n */\nexport function createdLayoutServer(locale: LayoutServerLocale): string {\n const imports = [\n \"import { error, redirect } from '@sveltejs/kit';\",\n \"import { loadCms } from '#lib/cms.js';\",\n ...(locale.imports ?? []).map(importLine),\n \"import type { LayoutServerLoad } from './$types';\",\n ].join(\"\\n\");\n const snippet = cmsSnippet(\"event\", locale.expression(\"event\"))\n .split(\"\\n\")\n .join(\"\\n\\t\");\n\n return dedent`\n ${imports}\n\n export const load: LayoutServerLoad = async (event) => {\n \t${snippet}\n\n \treturn { cms };\n };\n `.concat(\"\\n\");\n}\n\nconst FAILURE_HINT = [\n \"Call loadCms from the root +layout.server.ts load and return `cms`:\",\n \"\",\n createdLayoutServer(DEFAULT_LOCALE).trimEnd(),\n \"\",\n \"loadCms needs the whole event, so a destructured parameter has to become\",\n \"`event` with the destructuring moved into the body.\",\n].join(\"\\n\");\n\n/**\n * Wires `loadCms` into the root `+layout.server.ts`, creating the file when\n * the project has none:\n *\n * - `loadCms` needs the whole request event, so a destructured parameter is\n * renamed to `event` and the destructuring becomes the first statement.\n * - The tombstone triple (`redirectTo`, `gone`, `notFound`) is handled just\n * before the return.\n * - `cms` is added to the returned object, ahead of any spread so nothing\n * later can shadow it.\n *\n * Anything else — no exported `load`, an expression-bodied arrow, several\n * returns, a non-literal return — is reported as `failed` with the snippet to\n * paste, and the file is left exactly as it was.\n */\nexport function modifyLayoutServer(\n layoutServerPath: string,\n locale: LayoutServerLocale = DEFAULT_LOCALE,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, createdLayoutServer(locale));\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"loadCms(\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n\n // --- Inspect everything before touching anything. ---\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"failed\", message: FAILURE_HINT };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n const object = returned && returnedObject(returned);\n if (!returned || !object) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const eventName = event.kind === \"identifier\" ? event.name : \"event\";\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n if (!hasProperty(object, \"cms\")) {\n const spreadIndex = object\n .getProperties()\n .findIndex((property) => Node.isSpreadAssignment(property));\n if (spreadIndex === -1) {\n object.addShorthandPropertyAssignment({ name: \"cms\" });\n } else {\n object.insertShorthandPropertyAssignment(spreadIndex, { name: \"cms\" });\n }\n }\n\n // insertStatements counts comment lines, which getStatements() skips.\n const returnIndex = body.getStatementsWithComments().indexOf(returned);\n body.insertStatements(\n returnIndex,\n `\\n${cmsSnippet(eventName, locale.expression(eventName))}\\n`,\n );\n\n if (event.kind === \"binding\") {\n const destructuring = event.pattern.getText();\n body.insertStatements(0, `const ${destructuring} = ${eventName};`);\n const typeText = event.param.getTypeNode()?.getText();\n event.param.replaceWithText(\n typeText ? `${eventName}: ${typeText}` : eventName,\n );\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: eventName });\n }\n\n if (!fn.isAsync()) fn.setIsAsync(true);\n\n ensureNamedImports(sourceFile, \"@sveltejs/kit\", [\"error\", \"redirect\"]);\n ensureNamedImports(sourceFile, \"#lib/cms.js\", [\"loadCms\"]);\n for (const spec of locale.imports ?? []) {\n ensureImportSpec(sourceFile, spec);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasSpreadOf,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Forward the server load's data through the root +layout.ts, so \\`cms\\` reaches\n the page:\n\n export const load = async ({ url, data }) => {\n // ...existing code...\n return { ...data, /* existing keys */ };\n };\n`;\n\n/**\n * Make a universal root \\`+layout.ts\\` forward its server load's data.\n *\n * SvelteKit hands a universal load the server load's result as \\`data\\`, and\n * only what the universal load returns reaches the page. A layout that\n * returns its own object without spreading \\`data\\` — the static template\n * does — would drop \\`cms\\` on the floor once \\`+layout.server.ts\\` exists.\n *\n * No file, or a file without a \\`load\\`, needs nothing: server data flows\n * through on its own.\n */\nexport function modifyLayoutUniversal(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutPath);\n\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"success\", changed: false };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n if (!returned) return { status: \"failed\", message: FAILURE_HINT };\n\n const dataExpression =\n event.kind === \"identifier\" ? `${event.name}.data` : \"data\";\n\n // `return data;` already forwards everything.\n const expression = returned.getExpression();\n if (expression && expression.getText() === dataExpression) {\n return { status: \"success\", changed: false };\n }\n\n const object = returnedObject(returned);\n if (!object) return { status: \"failed\", message: FAILURE_HINT };\n if (hasSpreadOf(object, dataExpression)) {\n return { status: \"success\", changed: false };\n }\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n // First, so the layout's own keys still win over anything the server sent.\n object.insertSpreadAssignment(0, { expression: dataExpression });\n\n if (event.kind === \"binding\") {\n const hasData = event.pattern\n .getElements()\n .some((element) => element.getName() === \"data\");\n if (!hasData) {\n const text = event.pattern.getText();\n event.pattern.replaceWithText(text.replace(/^\\{\\s*/, \"{ data, \"));\n }\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ data }\" });\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\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 IMPORT_SNIPPET = dedent`\n import { AdminBar } from '@velastack/cms';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<AdminBar />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <AdminBar /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<AdminBar />` at the top level of the root layout, ahead of\n * `{@render children()}` so the bar is in the DOM before the page content.\n * Falls back to appending when the layout has no render tag or slot.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"AdminBar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { namedImports: [\"AdminBar\"], moduleSpecifier: \"@velastack/cms\" },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\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 { resolveMode, type CmsMode } from \"./generate\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport {\n DEFAULT_LOCALE,\n WUCHALE_LOCALE,\n modifyLayoutServer,\n} from \"./modifies/layout.server\";\nimport { modifyLayoutUniversal } from \"./modifies/layout\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\n/** The locale list from `wuchale.config.js`, or null when it cannot be read. */\nexport function readWuchaleLocales(root: string): string[] | null {\n const configPath = path.join(root, \"wuchale.config.js\");\n if (!fs.existsSync(configPath)) return null;\n const match = fs\n .readFileSync(configPath, \"utf8\")\n .match(/locales:\\s*\\[([^\\]]*)\\]/);\n if (!match) return null;\n const locales = [...match[1].matchAll(/['\"]([^'\"]+)['\"]/g)].map((m) => m[1]);\n return locales.length > 0 ? locales : null;\n}\n\n/**\n * Arguments for the `cms()` Vite plugin.\n *\n * A hosted CMS needs the endpoint and locales at build time so media can be\n * downloaded into the prerendered site. An app hosting the backend itself\n * needs nothing: the media steps are no-ops without an endpoint.\n */\nexport function vitePluginArgs(mode: CmsMode, locales: string[]): string {\n if (mode.local) return \"\";\n const list = locales.map((locale) => `'${locale}'`).join(\", \");\n return `{ endpoint: '${mode.endpoint}', locales: [${list}] }`;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const mode = resolveMode(options);\n const i18n = options.features.i18n;\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 const locales = (i18n && readWuchaleLocales(options.root)) || [\"en\"];\n pushResult(\n modifyOutcomeToFile(\n viteConfigPath,\n modifyViteConfig(viteConfigPath, vitePluginArgs(mode, locales)),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n const locale = i18n ? WUCHALE_LOCALE : DEFAULT_LOCALE;\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServer(layoutServerPath, locale),\n ),\n );\n\n // A universal root layout has to pass the server load's data along, or\n // `cms` never reaches the page. The static template has one.\n logger.info(\"Modifying src/routes/+layout.ts\");\n const layoutUniversalPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutUniversalPath,\n modifyLayoutUniversal(layoutUniversalPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutSveltePath, modifyLayoutSvelte(layoutSveltePath)),\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":";;;;;;;;;;;;AAYA,IAAMA,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAC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