@velastack/patterns 0.0.37 → 0.0.39
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/_server-B3Rzajf2.js +6 -0
- package/dist/chunks/_server-B3Rzajf2.js.map +1 -0
- package/dist/chunks/{collections-DQbbH7sz.js → collections-CUtXB8_s.js} +2 -2
- package/dist/chunks/{collections-DQbbH7sz.js.map → collections-CUtXB8_s.js.map} +1 -1
- package/dist/chunks/{env-CU-NtvJ7.js → env-CDsRI_A5.js} +1 -1
- package/dist/chunks/{env-CU-NtvJ7.js.map → env-CDsRI_A5.js.map} +1 -1
- package/dist/chunks/{env.preview-7Cc9KCgc.js → env.preview-Ds0NigL8.js} +1 -1
- package/dist/chunks/{env.preview-7Cc9KCgc.js.map → env.preview-Ds0NigL8.js.map} +1 -1
- package/dist/chunks/{env.runtime-l1ssTZog.js → env.runtime-BGmr1gQZ.js} +1 -1
- package/dist/chunks/{env.runtime-l1ssTZog.js.map → env.runtime-BGmr1gQZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D5ZkXanM.js → generate.runtime-BQTf0jam.js} +4 -4
- package/dist/chunks/{generate.runtime-D5ZkXanM.js.map → generate.runtime-BQTf0jam.js.map} +1 -1
- package/dist/chunks/generate.runtime-BS7zL9wC.js +211 -0
- package/dist/chunks/generate.runtime-BS7zL9wC.js.map +1 -0
- package/dist/chunks/{generate.runtime-BK3U_cCw.js → generate.runtime-B_NxLFKW.js} +2 -2
- package/dist/chunks/{generate.runtime-BK3U_cCw.js.map → generate.runtime-B_NxLFKW.js.map} +1 -1
- package/dist/chunks/generate.runtime-BfDfDNO9.js +197 -0
- package/dist/chunks/generate.runtime-BfDfDNO9.js.map +1 -0
- package/dist/chunks/{generate.runtime-D5I9Pe1O.js → generate.runtime-Bk9nFjoW.js} +4 -4
- package/dist/chunks/{generate.runtime-D5I9Pe1O.js.map → generate.runtime-Bk9nFjoW.js.map} +1 -1
- package/dist/chunks/generate.runtime-BwbTS71o.js +309 -0
- package/dist/chunks/generate.runtime-BwbTS71o.js.map +1 -0
- package/dist/chunks/{generate.runtime-CN5PiWOK.js → generate.runtime-C2Ev291A.js} +3 -3
- package/dist/chunks/{generate.runtime-CN5PiWOK.js.map → generate.runtime-C2Ev291A.js.map} +1 -1
- package/dist/chunks/{generate.runtime-GmszNklA.js → generate.runtime-C8Wbgx77.js} +2 -2
- package/dist/chunks/{generate.runtime-GmszNklA.js.map → generate.runtime-C8Wbgx77.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DedHJlsZ.js → generate.runtime-CJg6JI4m.js} +6 -6
- package/dist/chunks/{generate.runtime-DedHJlsZ.js.map → generate.runtime-CJg6JI4m.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DG7GcbJr.js → generate.runtime-CXorM210.js} +3 -3
- package/dist/chunks/{generate.runtime-DG7GcbJr.js.map → generate.runtime-CXorM210.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Df6qRZMP.js → generate.runtime-ClIJQ2E0.js} +7 -7
- package/dist/chunks/{generate.runtime-Df6qRZMP.js.map → generate.runtime-ClIJQ2E0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DRx_VMuc.js → generate.runtime-CojXsWmJ.js} +5 -5
- package/dist/chunks/{generate.runtime-DRx_VMuc.js.map → generate.runtime-CojXsWmJ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Ci13Xrz_.js → generate.runtime-CqEWaQXx.js} +4 -4
- package/dist/chunks/{generate.runtime-Ci13Xrz_.js.map → generate.runtime-CqEWaQXx.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Vvjaa4sc.js → generate.runtime-CsFOIAEO.js} +3 -3
- package/dist/chunks/{generate.runtime-Vvjaa4sc.js.map → generate.runtime-CsFOIAEO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-GoC73zRO.js → generate.runtime-DgoCWziW.js} +4 -4
- package/dist/chunks/{generate.runtime-GoC73zRO.js.map → generate.runtime-DgoCWziW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-fifS2KJv.js → generate.runtime-DlJPYj_8.js} +3 -3
- package/dist/chunks/{generate.runtime-fifS2KJv.js.map → generate.runtime-DlJPYj_8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B3ygXsYo.js → generate.runtime-KwhuvW-W.js} +5 -5
- package/dist/chunks/{generate.runtime-B3ygXsYo.js.map → generate.runtime-KwhuvW-W.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DFW9vKsO.js → generate.runtime-MNNdJitS.js} +2 -2
- package/dist/chunks/{generate.runtime-DFW9vKsO.js.map → generate.runtime-MNNdJitS.js.map} +1 -1
- package/dist/chunks/{modify-file-Bi-4GRwL.js → modify-file-DGBe3ycw.js} +1 -1
- package/dist/chunks/{modify-file-Bi-4GRwL.js.map → modify-file-DGBe3ycw.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-BcZVx_jI.js → modify-svelte-config-remote-C-Wl2nk1.js} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-BcZVx_jI.js.map → modify-svelte-config-remote-C-Wl2nk1.js.map} +1 -1
- package/dist/chunks/nav-user-Jp5yYtw5.js +6 -0
- package/dist/chunks/nav-user-Jp5yYtw5.js.map +1 -0
- package/dist/chunks/{pocketbase-4_89gk_J.js → pocketbase-CEhGbssT.js} +1 -1
- package/dist/chunks/{pocketbase-4_89gk_J.js.map → pocketbase-CEhGbssT.js.map} +1 -1
- package/dist/chunks/{pocketbase-BiRWz-OQ.js → pocketbase-D5p0NSdu.js} +1 -1
- package/dist/chunks/{pocketbase-BiRWz-OQ.js.map → pocketbase-D5p0NSdu.js.map} +1 -1
- package/dist/chunks/{shared--goBUhsB.js → shared-Bt7uM3CK.js} +2 -2
- package/dist/chunks/{shared--goBUhsB.js.map → shared-Bt7uM3CK.js.map} +1 -1
- package/dist/chunks/{ts-morph-helpers-B0oxeDUU.js → ts-morph-helpers-DjpZhZ7I.js} +10 -1
- package/dist/chunks/ts-morph-helpers-DjpZhZ7I.js.map +1 -0
- package/dist/chunks/{write-result-BuZpAeOf.js → write-result-DQYWzSqE.js} +2 -2
- package/dist/chunks/{write-result-BuZpAeOf.js.map → write-result-DQYWzSqE.js.map} +1 -1
- package/dist/index.d.ts +199 -31
- package/dist/index.js +1661 -1236
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/ts-morph-helpers-B0oxeDUU.js.map +0 -1
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
|
+
import { n as t } from "./logger-BpgCb-ZG.js";
|
|
3
|
+
import { a as n, c as r, i, n as a, o, r as s, s as c, t as l } from "./_server-B3Rzajf2.js";
|
|
4
|
+
import { modifyOutcomeToFile as u } from "./modify-file-DGBe3ycw.js";
|
|
5
|
+
import { a as d, n as f, o as p } from "./ts-morph-helpers-DjpZhZ7I.js";
|
|
6
|
+
import m from "node:fs";
|
|
7
|
+
import h from "node:path";
|
|
8
|
+
import { SyntaxKind as g } from "ts-morph";
|
|
9
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-stripe-hooks.ts
|
|
10
|
+
var _ = e`
|
|
11
|
+
cronAdd("stripe-subscriptions", "*/2 * * * *", () => {
|
|
12
|
+
const utils = require(\`\${__hooks}/utils.js\`);
|
|
13
|
+
utils.triggerJob("/api/stripe/sync/subscriptions");
|
|
14
|
+
});
|
|
15
|
+
`, v = [
|
|
16
|
+
"Append the stripe-subscriptions cron to data/hooks/stripe.pb.js:",
|
|
17
|
+
"",
|
|
18
|
+
_
|
|
19
|
+
].join("\n"), y = [
|
|
20
|
+
"Enable payments first — data/hooks/stripe.pb.js is created by enable-payments.",
|
|
21
|
+
"",
|
|
22
|
+
"Once present, append:",
|
|
23
|
+
"",
|
|
24
|
+
_
|
|
25
|
+
].join("\n");
|
|
26
|
+
function b(e) {
|
|
27
|
+
if (!m.existsSync(e)) return {
|
|
28
|
+
status: "not-found",
|
|
29
|
+
message: y
|
|
30
|
+
};
|
|
31
|
+
let t = m.readFileSync(e, "utf8");
|
|
32
|
+
if (t.includes("stripe-subscriptions")) return {
|
|
33
|
+
status: "success",
|
|
34
|
+
changed: !1
|
|
35
|
+
};
|
|
36
|
+
if (!t.includes("cronAdd(")) return {
|
|
37
|
+
status: "failed",
|
|
38
|
+
message: v
|
|
39
|
+
};
|
|
40
|
+
let n = `${t}${t.endsWith("\n") ? "" : "\n"}\n${_}\n`;
|
|
41
|
+
return m.writeFileSync(e, n, "utf8"), {
|
|
42
|
+
status: "success",
|
|
43
|
+
changed: !0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-webhook-server.ts
|
|
48
|
+
var x = e`
|
|
49
|
+
Wire the subscription event handlers into src/routes/webhooks/stripe/+server.ts:
|
|
50
|
+
|
|
51
|
+
Add imports:
|
|
52
|
+
import { handleSubscriptionCreated } from "./handlers/subscription/created";
|
|
53
|
+
import { handleSubscriptionUpdated } from "./handlers/subscription/updated";
|
|
54
|
+
import { handleSubscriptionDeleted } from "./handlers/subscription/deleted";
|
|
55
|
+
|
|
56
|
+
Add switch cases inside the event.type switch:
|
|
57
|
+
case "customer.subscription.created":
|
|
58
|
+
await handleSubscriptionCreated(event.data.object, locals);
|
|
59
|
+
break;
|
|
60
|
+
case "customer.subscription.updated":
|
|
61
|
+
await handleSubscriptionUpdated(event.data.object, locals);
|
|
62
|
+
break;
|
|
63
|
+
case "customer.subscription.deleted":
|
|
64
|
+
await handleSubscriptionDeleted(event.data.object, locals);
|
|
65
|
+
break;
|
|
66
|
+
`, S = "Enable payments first — src/routes/webhooks/stripe/+server.ts is created by enable-payments.", C = e`
|
|
67
|
+
case "customer.subscription.created":
|
|
68
|
+
await handleSubscriptionCreated(event.data.object, locals);
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case "customer.subscription.updated":
|
|
72
|
+
await handleSubscriptionUpdated(event.data.object, locals);
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case "customer.subscription.deleted":
|
|
76
|
+
await handleSubscriptionDeleted(event.data.object, locals);
|
|
77
|
+
break;
|
|
78
|
+
`;
|
|
79
|
+
function w(e) {
|
|
80
|
+
if (!m.existsSync(e)) return {
|
|
81
|
+
status: "not-found",
|
|
82
|
+
message: S
|
|
83
|
+
};
|
|
84
|
+
let t = m.readFileSync(e, "utf8");
|
|
85
|
+
if (t.includes("handleSubscriptionCreated")) return {
|
|
86
|
+
status: "success",
|
|
87
|
+
changed: !1
|
|
88
|
+
};
|
|
89
|
+
let n = !1, { source: r } = d(t, (e) => {
|
|
90
|
+
f(e, [
|
|
91
|
+
{
|
|
92
|
+
namedImports: ["handleSubscriptionCreated"],
|
|
93
|
+
moduleSpecifier: "./handlers/subscription/created"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
namedImports: ["handleSubscriptionUpdated"],
|
|
97
|
+
moduleSpecifier: "./handlers/subscription/updated"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
namedImports: ["handleSubscriptionDeleted"],
|
|
101
|
+
moduleSpecifier: "./handlers/subscription/deleted"
|
|
102
|
+
}
|
|
103
|
+
]);
|
|
104
|
+
let t = e.getDescendantsOfKind(g.SwitchStatement).find((e) => e.getExpression().getText().includes("event.type"));
|
|
105
|
+
if (!t) return;
|
|
106
|
+
let r = t.getCaseBlock().getClauses(), i = r.find((e) => e.getKind() === g.DefaultClause), a = `${C}\n\n`;
|
|
107
|
+
if (i) i.replaceWithText(a + i.getText());
|
|
108
|
+
else if (r.length > 0) {
|
|
109
|
+
let e = r[r.length - 1];
|
|
110
|
+
e.replaceWithText(e.getText() + `\n\n${C}`);
|
|
111
|
+
} else return;
|
|
112
|
+
e.formatText(), n = !0;
|
|
113
|
+
});
|
|
114
|
+
return n ? (m.writeFileSync(e, r, "utf8"), {
|
|
115
|
+
status: "success",
|
|
116
|
+
changed: !0
|
|
117
|
+
}) : {
|
|
118
|
+
status: "failed",
|
|
119
|
+
message: x
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-by-template.ts
|
|
124
|
+
function T(e, t, n, r) {
|
|
125
|
+
if (!m.existsSync(e)) return {
|
|
126
|
+
status: "not-found",
|
|
127
|
+
message: r
|
|
128
|
+
};
|
|
129
|
+
let i = m.readFileSync(e, "utf8");
|
|
130
|
+
if (i.includes(n)) return {
|
|
131
|
+
status: "success",
|
|
132
|
+
changed: !1
|
|
133
|
+
};
|
|
134
|
+
let a = t.replace(/^[ \t]*\/\/[ \t]*\[!code highlight:\d+\][ \t]*\r?\n/gm, "").replace(/^[ \t]*<!--[ \t]*\[!code highlight:\d+\][ \t]*-->[ \t]*\r?\n/gm, "");
|
|
135
|
+
return i === a ? {
|
|
136
|
+
status: "success",
|
|
137
|
+
changed: !1
|
|
138
|
+
} : (m.writeFileSync(e, a, "utf8"), {
|
|
139
|
+
status: "success",
|
|
140
|
+
changed: !0
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-app-layout-server.ts
|
|
145
|
+
var E = ["Create src/routes/(app)/+layout.server.ts before enabling subscriptions.", "Enable auth first — the (app) layout is provided by the velastack-auth baseline."].join("\n");
|
|
146
|
+
function D(e, t) {
|
|
147
|
+
return T(e, t, "loadActiveSubscription", E);
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-app-layout-svelte.ts
|
|
151
|
+
var O = [
|
|
152
|
+
"Pass the subscription prop to <AppSidebar> in src/routes/(app)/+layout.svelte:",
|
|
153
|
+
"",
|
|
154
|
+
"<AppSidebar user={data.user} meta={data.meta} subscription={data.subscription} />"
|
|
155
|
+
].join("\n"), k = ["Create src/routes/(app)/+layout.svelte with an <AppSidebar /> that receives the subscription prop."].join("\n");
|
|
156
|
+
function A(e) {
|
|
157
|
+
if (!m.existsSync(e)) return {
|
|
158
|
+
status: "not-found",
|
|
159
|
+
message: k
|
|
160
|
+
};
|
|
161
|
+
let t = p.fromPath(e);
|
|
162
|
+
return t.hasElement("AppSidebar") ? t.hasAttribute("AppSidebar", "subscription") ? {
|
|
163
|
+
status: "success",
|
|
164
|
+
changed: !1
|
|
165
|
+
} : t.appendToAttributes("AppSidebar", " subscription={data.subscription}") ? (t.writeTo(e), {
|
|
166
|
+
status: "success",
|
|
167
|
+
changed: t.hasChanged()
|
|
168
|
+
}) : {
|
|
169
|
+
status: "failed",
|
|
170
|
+
message: O
|
|
171
|
+
} : {
|
|
172
|
+
status: "failed",
|
|
173
|
+
message: O
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-app-sidebar.ts
|
|
178
|
+
var j = "{ id: string; productName: string | null } | null", M = [
|
|
179
|
+
"Update src/lib/components/app-sidebar.svelte to forward a subscription prop:",
|
|
180
|
+
"",
|
|
181
|
+
"1. Add `subscription = null` to the destructured $props() call.",
|
|
182
|
+
`2. Add \`subscription?: ${j}\` to the props type.`,
|
|
183
|
+
"3. Pass `{subscription}` to <NavUser>."
|
|
184
|
+
].join("\n"), N = ["Create src/lib/components/app-sidebar.svelte before enabling subscriptions."].join("\n");
|
|
185
|
+
function P(e) {
|
|
186
|
+
let t = !1, { source: n } = d(e, (e) => {
|
|
187
|
+
for (let n of e.getVariableDeclarations()) {
|
|
188
|
+
let e = n.getInitializer();
|
|
189
|
+
if (!e || e.getText() !== "$props()") continue;
|
|
190
|
+
let r = n.getNameNode();
|
|
191
|
+
if (r.getKind() !== g.ObjectBindingPattern) continue;
|
|
192
|
+
let i = r.asKindOrThrow(g.ObjectBindingPattern), a = i.getElements();
|
|
193
|
+
if (a.some((e) => e.getName() === "subscription")) return;
|
|
194
|
+
let o = n.getTypeNode();
|
|
195
|
+
if (o?.getKind() === g.IntersectionType) {
|
|
196
|
+
let e = o.asKindOrThrow(g.IntersectionType);
|
|
197
|
+
for (let t of e.getTypeNodes()) {
|
|
198
|
+
if (t.getKind() !== g.TypeLiteral) continue;
|
|
199
|
+
let e = t.asKindOrThrow(g.TypeLiteral), n = e.getProperties().map((e) => e.getText().replace(/[;,]\s*$/, ""));
|
|
200
|
+
if (!n.some((e) => /^\s*subscription\??\s*:/.test(e))) {
|
|
201
|
+
n.push(`subscription?: ${j}`), e.replaceWithText(`{ ${n.join("; ")}; }`);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let s = a.map((e) => e.getText()), c = a.findIndex((e) => e.getDotDotDotToken() || e.getInitializer());
|
|
207
|
+
c === -1 && (c = s.length), s.splice(c, 0, "subscription = null"), i.replaceWithText(`{ ${s.join(", ")} }`), t = !0;
|
|
208
|
+
}
|
|
209
|
+
e.formatText();
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
source: n,
|
|
213
|
+
wasAdded: t
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function F(e) {
|
|
217
|
+
if (!m.existsSync(e)) return {
|
|
218
|
+
status: "not-found",
|
|
219
|
+
message: N
|
|
220
|
+
};
|
|
221
|
+
let t = m.readFileSync(e, "utf8");
|
|
222
|
+
if (t.includes("subscription?: {") || t.includes("subscription={subscription}") || t.includes("{subscription}")) return {
|
|
223
|
+
status: "success",
|
|
224
|
+
changed: !1
|
|
225
|
+
};
|
|
226
|
+
let n = new p(t);
|
|
227
|
+
if (!n.hasElement("NavUser")) return {
|
|
228
|
+
status: "failed",
|
|
229
|
+
message: M
|
|
230
|
+
};
|
|
231
|
+
let r = n.modifyScript((e) => P(e).source), i = n.hasAttribute("NavUser", "subscription") ? !1 : n.appendToAttributes("NavUser", " {subscription}");
|
|
232
|
+
return !r && !i ? {
|
|
233
|
+
status: "failed",
|
|
234
|
+
message: M
|
|
235
|
+
} : (n.writeTo(e), {
|
|
236
|
+
status: "success",
|
|
237
|
+
changed: n.hasChanged()
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-nav-user.ts
|
|
242
|
+
var I = ["src/lib/components/nav-user.svelte is missing.", "Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user."].join("\n");
|
|
243
|
+
function L(e, t) {
|
|
244
|
+
return T(e, t, "planLabel", I);
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-billing-page-server.ts
|
|
248
|
+
var R = ["src/routes/(app)/billing/+page.server.ts is missing.", "Enable payments first — subscriptions extends the billing page with plan management."].join("\n");
|
|
249
|
+
function z(e, t) {
|
|
250
|
+
return T(e, t, "selectPlan", R);
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/patterns/enable/subscriptions/modifies/modify-billing-page-svelte.ts
|
|
254
|
+
var B = ["src/routes/(app)/billing/+page.svelte is missing.", "Enable payments first — subscriptions extends the billing page with plan management."].join("\n");
|
|
255
|
+
function V(e, t) {
|
|
256
|
+
return T(e, t, "availablePlans", B);
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/patterns/enable/subscriptions/generate.runtime.ts
|
|
260
|
+
var H = /* @__PURE__ */ Object.assign({
|
|
261
|
+
"./preview-modifies/data/hooks/stripe.pb.js": r,
|
|
262
|
+
"./preview-modifies/src/lib/components/app-sidebar.svelte": c,
|
|
263
|
+
"./preview-modifies/src/lib/components/nav-user.svelte": o,
|
|
264
|
+
"./preview-modifies/src/routes/(app)/+layout.server.ts": n,
|
|
265
|
+
"./preview-modifies/src/routes/(app)/+layout.svelte": i,
|
|
266
|
+
"./preview-modifies/src/routes/(app)/billing/+page.server.ts": s,
|
|
267
|
+
"./preview-modifies/src/routes/(app)/billing/+page.svelte": a,
|
|
268
|
+
"./preview-modifies/src/routes/webhooks/stripe/+server.ts": l
|
|
269
|
+
});
|
|
270
|
+
function U(e) {
|
|
271
|
+
let t = H[`./preview-modifies/${e}`];
|
|
272
|
+
if (t === void 0) throw Error(`Missing template for ${e} in subscriptions preview-modifies`);
|
|
273
|
+
return t;
|
|
274
|
+
}
|
|
275
|
+
async function W(e) {
|
|
276
|
+
let n = t(e), r = [], i = (e) => {
|
|
277
|
+
e && r.push(e);
|
|
278
|
+
};
|
|
279
|
+
n.info("Modifying data/hooks/stripe.pb.js");
|
|
280
|
+
let a = h.join(e.root, "data", "hooks", "stripe.pb.js");
|
|
281
|
+
i(u(a, b(a))), n.info("Modifying webhooks/stripe/+server.ts");
|
|
282
|
+
let o = h.join(e.root, "src", "routes", "webhooks", "stripe", "+server.ts");
|
|
283
|
+
i(u(o, w(o))), n.info("Modifying (app)/+layout.server.ts");
|
|
284
|
+
let s = h.join(e.root, "src", "routes", "(app)", "+layout.server.ts");
|
|
285
|
+
i(u(s, D(s, U("src/routes/(app)/+layout.server.ts")))), n.info("Modifying (app)/+layout.svelte");
|
|
286
|
+
let c = h.join(e.root, "src", "routes", "(app)", "+layout.svelte");
|
|
287
|
+
i(u(c, A(c))), n.info("Modifying app-sidebar.svelte");
|
|
288
|
+
let l = h.join(e.root, "src", "lib", "components", "app-sidebar.svelte");
|
|
289
|
+
i(u(l, F(l))), n.info("Modifying nav-user.svelte");
|
|
290
|
+
let d = h.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
291
|
+
i(u(d, L(d, U("src/lib/components/nav-user.svelte")))), n.info("Modifying billing/+page.server.ts");
|
|
292
|
+
let f = h.join(e.root, "src", "routes", "(app)", "billing", "+page.server.ts");
|
|
293
|
+
i(u(f, z(f, U("src/routes/(app)/billing/+page.server.ts")))), n.info("Modifying billing/+page.svelte");
|
|
294
|
+
let p = h.join(e.root, "src", "routes", "(app)", "billing", "+page.svelte");
|
|
295
|
+
return i(u(p, V(p, U("src/routes/(app)/billing/+page.svelte")))), {
|
|
296
|
+
creates: [],
|
|
297
|
+
modifies: r,
|
|
298
|
+
deletes: [],
|
|
299
|
+
components: [],
|
|
300
|
+
packages: [],
|
|
301
|
+
collections: [],
|
|
302
|
+
collectionPatches: [],
|
|
303
|
+
collectionDrops: []
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
307
|
+
export { W as generate };
|
|
308
|
+
|
|
309
|
+
//# sourceMappingURL=generate.runtime-BwbTS71o.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-BwbTS71o.js","names":[],"sources":["../../src/patterns/enable/subscriptions/modifies/modify-stripe-hooks.ts","../../src/patterns/enable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-by-template.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/enable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/enable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/enable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst CRON_SNIPPET = dedent`\n cronAdd(\"stripe-subscriptions\", \"*/2 * * * *\", () => {\n const utils = require(\\`\\${__hooks}/utils.js\\`);\n utils.triggerJob(\"/api/stripe/sync/subscriptions\");\n });\n`;\n\nconst FAILURE_HINT = [\n \"Append the stripe-subscriptions cron to data/hooks/stripe.pb.js:\",\n \"\",\n CRON_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Enable payments first — data/hooks/stripe.pb.js is created by enable-payments.\",\n \"\",\n \"Once present, append:\",\n \"\",\n CRON_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyStripeHooks(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (current.includes(\"stripe-subscriptions\")) {\n return { status: \"success\", changed: false };\n }\n if (!current.includes(\"cronAdd(\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const trailing = current.endsWith(\"\\n\") ? \"\" : \"\\n\";\n const next = `${current}${trailing}\\n${CRON_SNIPPET}\\n`;\n fs.writeFileSync(filePath, next, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Wire the subscription event handlers into src/routes/webhooks/stripe/+server.ts:\n\n Add imports:\n import { handleSubscriptionCreated } from \"./handlers/subscription/created\";\n import { handleSubscriptionUpdated } from \"./handlers/subscription/updated\";\n import { handleSubscriptionDeleted } from \"./handlers/subscription/deleted\";\n\n Add switch cases inside the event.type switch:\n case \"customer.subscription.created\":\n await handleSubscriptionCreated(event.data.object, locals);\n break;\n case \"customer.subscription.updated\":\n await handleSubscriptionUpdated(event.data.object, locals);\n break;\n case \"customer.subscription.deleted\":\n await handleSubscriptionDeleted(event.data.object, locals);\n break;\n`;\n\nconst NOT_FOUND_HINT =\n \"Enable payments first — src/routes/webhooks/stripe/+server.ts is created by enable-payments.\";\n\nconst SUBSCRIPTION_CASES_SNIPPET = dedent`\n case \"customer.subscription.created\":\n await handleSubscriptionCreated(event.data.object, locals);\n break;\n\n case \"customer.subscription.updated\":\n await handleSubscriptionUpdated(event.data.object, locals);\n break;\n\n case \"customer.subscription.deleted\":\n await handleSubscriptionDeleted(event.data.object, locals);\n break;\n`;\n\nexport function modifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n if (original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n let addedCases = false;\n const { source } = withInMemoryScript(original, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"handleSubscriptionCreated\"],\n moduleSpecifier: \"./handlers/subscription/created\",\n },\n {\n namedImports: [\"handleSubscriptionUpdated\"],\n moduleSpecifier: \"./handlers/subscription/updated\",\n },\n {\n namedImports: [\"handleSubscriptionDeleted\"],\n moduleSpecifier: \"./handlers/subscription/deleted\",\n },\n ]);\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n const clauses = caseBlock.getClauses();\n const defaultClause = clauses.find(\n (c) => c.getKind() === SyntaxKind.DefaultClause,\n );\n\n // Prepend subscription cases in front of the default clause, or append\n // before the closing brace of the case block if there's no default.\n const prefix = `${SUBSCRIPTION_CASES_SNIPPET}\\n\\n`;\n if (defaultClause) {\n defaultClause.replaceWithText(prefix + defaultClause.getText());\n } else if (clauses.length > 0) {\n const last = clauses[clauses.length - 1];\n last.replaceWithText(last.getText() + `\\n\\n${SUBSCRIPTION_CASES_SNIPPET}`);\n } else {\n return;\n }\n\n sf.formatText();\n addedCases = true;\n });\n\n if (!addedCases) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(filePath, source, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Overwrites a file with the given template content, guarded by an idempotency\n * marker: if the current file already contains the marker, the modify is a\n * no-op. Used for complex rewrites where surgical AST changes aren't worth it\n * (e.g. pages that are largely replaced).\n *\n * Strips leading `// [!code highlight:N]` and `<!-- [!code highlight:N] -->`\n * lines so the same content can be shared with preview-modifies, which uses\n * those comments for documentation highlighting.\n */\nexport function modifyByTemplate(\n filePath: string,\n template: string,\n idempotencyMarker: string,\n notFoundHint: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: notFoundHint };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (current.includes(idempotencyMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(/^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm, \"\");\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.server.ts before enabling subscriptions.\",\n \"Enable auth first — the (app) layout is provided by the velastack-auth baseline.\",\n].join(\"\\n\");\n\nexport function modifyAppLayoutServer(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"loadActiveSubscription\",\n NOT_FOUND_HINT,\n );\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Pass the subscription prop to <AppSidebar> in src/routes/(app)/+layout.svelte:\",\n \"\",\n \"<AppSidebar user={data.user} meta={data.meta} subscription={data.subscription} />\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.svelte with an <AppSidebar /> that receives the subscription prop.\",\n].join(\"\\n\");\n\nexport function modifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const appended = file.appendToAttributes(\n \"AppSidebar\",\n \" subscription={data.subscription}\",\n );\n if (!appended) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst SUBSCRIPTION_TYPE = \"{ id: string; productName: string | null } | null\";\n\nconst FAILURE_HINT = [\n \"Update src/lib/components/app-sidebar.svelte to forward a subscription prop:\",\n \"\",\n \"1. Add `subscription = null` to the destructured $props() call.\",\n `2. Add \\`subscription?: ${SUBSCRIPTION_TYPE}\\` to the props type.`,\n \"3. Pass `{subscription}` to <NavUser>.\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/lib/components/app-sidebar.svelte before enabling subscriptions.\",\n].join(\"\\n\");\n\nfunction updateScript(source: string): {\n source: string;\n wasAdded: boolean;\n} {\n let wasAdded = false;\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n if (elements.some((e) => e.getName() === \"subscription\")) {\n // Already has subscription prop — no-op.\n return;\n }\n\n // Insert subscription?: ... into the props type literal if present.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n if (propTexts.some((t) => /^\\s*subscription\\??\\s*:/.test(t))) {\n continue;\n }\n propTexts.push(`subscription?: ${SUBSCRIPTION_TYPE}`);\n lit.replaceWithText(`{ ${propTexts.join(\"; \")}; }`);\n break;\n }\n }\n\n // Insert `subscription = null` before the first rest/default-only element.\n const elementTexts = elements.map((e) => e.getText());\n let insertIdx = elements.findIndex(\n (e) => e.getDotDotDotToken() || e.getInitializer(),\n );\n if (insertIdx === -1) insertIdx = elementTexts.length;\n elementTexts.splice(insertIdx, 0, \"subscription = null\");\n pattern.replaceWithText(`{ ${elementTexts.join(\", \")} }`);\n wasAdded = true;\n }\n sf.formatText();\n });\n return { source: out, wasAdded };\n}\n\nexport function modifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n if (\n original.includes(\"subscription?: {\") ||\n original.includes(\"subscription={subscription}\") ||\n original.includes(\"{subscription}\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n if (!file.hasElement(\"NavUser\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const scriptChanged = file.modifyScript(\n (src) => updateScript(src).source,\n );\n\n const templateChanged = !file.hasAttribute(\"NavUser\", \"subscription\")\n ? file.appendToAttributes(\"NavUser\", \" {subscription}\")\n : false;\n\n if (!scriptChanged && !templateChanged) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/lib/components/nav-user.svelte is missing.\",\n \"Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user.\",\n].join(\"\\n\");\n\nexport function modifyNavUser(\n filePath: string,\n template: string,\n): ModifyOutcome {\n // `planLabel` is unique to subscriptions — safe idempotency marker.\n return modifyByTemplate(filePath, template, \"planLabel\", NOT_FOUND_HINT);\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/routes/(app)/billing/+page.server.ts is missing.\",\n \"Enable payments first — subscriptions extends the billing page with plan management.\",\n].join(\"\\n\");\n\nexport function modifyBillingPageServer(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"selectPlan\",\n NOT_FOUND_HINT,\n );\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/routes/(app)/billing/+page.svelte is missing.\",\n \"Enable payments first — subscriptions extends the billing page with plan management.\",\n].join(\"\\n\");\n\nexport function modifyBillingPageSvelte(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"availablePlans\",\n NOT_FOUND_HINT,\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 { modifyStripeHooks } from \"./modifies/modify-stripe-hooks\";\nimport { modifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { modifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { modifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { modifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { modifyNavUser } from \"./modifies/modify-nav-user\";\nimport { modifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { modifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Share the final-state files between preview (rendered as-is) and runtime\n// (used as overwrite templates for modifies that amount to full rewrites).\nconst previewRaw = import.meta.glob<string>(\"./preview-modifies/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nfunction template(relativePath: string): string {\n const key = `./preview-modifies/${relativePath}`;\n const content = previewRaw[key];\n if (content === undefined) {\n throw new Error(\n `Missing template for ${relativePath} in subscriptions preview-modifies`,\n );\n }\n return content;\n}\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(\"Modifying data/hooks/stripe.pb.js\");\n const stripeHooksPath = path.join(\n options.root,\n \"data\",\n \"hooks\",\n \"stripe.pb.js\",\n );\n pushResult(\n modifyOutcomeToFile(stripeHooksPath, modifyStripeHooks(stripeHooksPath)),\n );\n\n logger.info(\"Modifying webhooks/stripe/+server.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"+server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n modifyWebhookServer(webhookServerPath),\n ),\n );\n\n logger.info(\"Modifying (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 modifyAppLayoutServer(\n appLayoutServerPath,\n template(\"src/routes/(app)/+layout.server.ts\"),\n ),\n ),\n );\n\n logger.info(\"Modifying (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n modifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Modifying app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, modifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Modifying nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n navUserPath,\n modifyNavUser(\n navUserPath,\n template(\"src/lib/components/nav-user.svelte\"),\n ),\n ),\n );\n\n logger.info(\"Modifying billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n modifyBillingPageServer(\n billingPageServerPath,\n template(\"src/routes/(app)/billing/+page.server.ts\"),\n ),\n ),\n );\n\n logger.info(\"Modifying billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n modifyBillingPageSvelte(\n billingPageSveltePath,\n template(\"src/routes/(app)/billing/+page.svelte\"),\n ),\n ),\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,CAAM;;;;;GAOrB,IAAe;CACnB;CACA;CACA;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAkB,GAAiC;AACjE,KAAI,CAAC,EAAG,WAAW,EAAS,CAC1B,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAEzD,IAAM,IAAU,EAAG,aAAa,GAAU,OAAO;AACjD,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AAKD,CAJA,EACE,EAAoB,GAAgB,EAAiB,EAAe,CAAC,CACtE,EAED,EAAO,KAAK,4BAA4B;CACxC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,kBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,qCAAqC,CAC/C,CACF,CACF,EAED,EAAO,KAAK,oCAAoC;CAChD,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,kBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,2CAA2C,CACrD,CACF,CACF,EAED,EAAO,KAAK,iCAAiC;CAC7C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,eACD;AAWD,QAVA,EACE,EACE,GACA,EACE,GACA,EAAS,wCAAwC,CAClD,CACF,CACF,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAA;EAClB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
2
|
import { n as t } from "./logger-BpgCb-ZG.js";
|
|
3
|
-
import { modifyOutcomeToFile as n } from "./modify-file-
|
|
4
|
-
import { a as r, n as i, o as a } from "./ts-morph-helpers-
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-DGBe3ycw.js";
|
|
4
|
+
import { a as r, n as i, o as a } from "./ts-morph-helpers-DjpZhZ7I.js";
|
|
5
5
|
import o from "node:fs";
|
|
6
6
|
import s from "node:path";
|
|
7
7
|
import { Project as c, QuoteKind as l, SyntaxKind as u } from "ts-morph";
|
|
@@ -488,4 +488,4 @@ async function L(e) {
|
|
|
488
488
|
//#endregion
|
|
489
489
|
export { L as generate };
|
|
490
490
|
|
|
491
|
-
//# sourceMappingURL=generate.runtime-
|
|
491
|
+
//# sourceMappingURL=generate.runtime-C2Ev291A.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-CN5PiWOK.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/+layout.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 fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ObjectLiteralExpression,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your Svelte config:\",\n \"\",\n \"kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Svelte config with the $locales alias:\",\n \"\",\n \"/** @type {import('@sveltejs/kit').Config} */\",\n \"const config = {\",\n \" kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \" },\",\n \"};\",\n \"\",\n \"export default config;\",\n].join(\"\\n\");\n\nfunction getOrCreateObjectLiteralProperty(\n obj: ObjectLiteralExpression,\n name: string,\n initializer: string,\n): ObjectLiteralExpression | null {\n const prop = obj.getProperty(name);\n if (!prop) {\n obj.addPropertyAssignment({ name, initializer });\n const added = obj.getProperty(name);\n if (!added || added.getKind() !== SyntaxKind.PropertyAssignment)\n return null;\n const init = (\n added as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!init || init.getKind() !== SyntaxKind.ObjectLiteralExpression)\n return null;\n return init as ObjectLiteralExpression;\n }\n\n if (prop.getKind() !== SyntaxKind.PropertyAssignment) return null;\n const init = (prop as import(\"ts-morph\").PropertyAssignment).getInitializer();\n if (!init) return null;\n if (init.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n (prop as import(\"ts-morph\").PropertyAssignment).setInitializer(initializer);\n const init2 = (\n prop as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n return init2 && init2.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (init2 as ObjectLiteralExpression)\n : null;\n }\n\n return init as ObjectLiteralExpression;\n}\n\nexport function modifySvelteConfig(svelteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(svelteConfigPath)) {\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(svelteConfigPath);\n\n const defaultExport = sourceFile.getExportAssignment(\n (ea) => !ea.isExportEquals(),\n );\n const exportedExpr = defaultExport?.getExpression();\n\n let configObj: ObjectLiteralExpression | null = null;\n if (exportedExpr?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = exportedExpr as ObjectLiteralExpression;\n } else if (exportedExpr?.getKind() === SyntaxKind.Identifier) {\n const ident = exportedExpr.getText();\n const varDecl = sourceFile.getVariableDeclaration(ident);\n const init = varDecl?.getInitializer();\n if (init?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = init as ObjectLiteralExpression;\n }\n }\n\n if (!configObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const kitObj = getOrCreateObjectLiteralProperty(configObj, \"kit\", \"{}\");\n if (!kitObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const aliasObj = getOrCreateObjectLiteralProperty(kitObj, \"alias\", \"{}\");\n if (!aliasObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const existingLocales = aliasObj.getProperty(\"$locales\");\n if (!existingLocales) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (existingLocales.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const init = (\n existingLocales as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current === \"src/locales\") return { status: \"success\", changed: false };\n\n (existingLocales as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"'src/locales'\",\n );\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\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.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, 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.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, 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.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, 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 if (/lang\\s*=/.test(match)) {\n return match;\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 path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LOAD_SNIPPET = dedent`\n import { browser } from '$app/environment';\n import { loadLocale } from 'wuchale/load-utils';\n\n import { getLocale } from '$locales/main.url';\n import '$locales/main.loader.svelte';\n import '$locales/js.loader';\n\n export const load = async ({ url, data }) => {\n const locale = getLocale(url);\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return data;\n };\n`;\n\nconst FAILURE_HINT = [\n \"Merge the wuchale loader into your existing load function in +layout.ts:\",\n \"\",\n LOAD_SNIPPET,\n].join(\"\\n\");\n\nexport function ensureRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (fs.existsSync(layoutPath)) {\n const existing = fs.readFileSync(layoutPath, \"utf8\");\n if (existing.includes(\"loadLocale\") || existing.includes(\"translateUrl\")) {\n return { status: \"success\", changed: false };\n }\n\n if (/\\bexport\\s+(const|function)\\s+load\\b/.test(existing)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n }\n\n fs.mkdirSync(path.dirname(layoutPath), { recursive: true });\n fs.writeFileSync(layoutPath, LOAD_SNIPPET + \"\\n\");\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 { 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\nfunction findFirstExistingFile(root: string, candidates: string[]): string {\n for (const relPath of candidates) {\n const absPath = path.join(root, relPath);\n if (fs.existsSync(absPath)) {\n return absPath;\n }\n }\n return path.join(root, candidates[0]);\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath = findFirstExistingFile(options.root, [\n \"vite.config.ts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n \"vite.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Modifying svelte.config\");\n const svelteConfigPath = findFirstExistingFile(options.root, [\n \"svelte.config.ts\",\n \"svelte.config.js\",\n \"svelte.config.mjs\",\n \"svelte.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(svelteConfigPath, modifySvelteConfig(svelteConfigPath)),\n );\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;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAiB,GAAuC;AACtE,KAAI,CAAC,EAAG,WAAW,EAAe,CAChC,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAOzD,IAAM,IAJU,IAAI,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,IAAM;EAClC,sBAAsB,EAAE,WAAW,EAAU,QAAQ;EACtD,CAAC,CACyB,oBA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B;EAC3B,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,qBAAqB;EAC1E,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,qBAAqB;EAC9D,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,iBAAiB;EACtE,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,iBAAiB;EAC3D,EACK,IACJ,EAAqB,MAAM,MAAM,EAAG,WAAW,EAAE,CAAC,IAClD,EAAqB;AAQvB,CAPA,EACE,EACE,GACA,EAA+B,EAAe,CAC/C,CACF,EAED,EAAO,KAAK,sBAAsB;CAClC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,aAAa;AAK3D,QAJA,EACE,EAAoB,GAAe,EAAgB,EAAc,CAAC,CACnE,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-C2Ev291A.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/+layout.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 fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ObjectLiteralExpression,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your Svelte config:\",\n \"\",\n \"kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Svelte config with the $locales alias:\",\n \"\",\n \"/** @type {import('@sveltejs/kit').Config} */\",\n \"const config = {\",\n \" kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \" },\",\n \"};\",\n \"\",\n \"export default config;\",\n].join(\"\\n\");\n\nfunction getOrCreateObjectLiteralProperty(\n obj: ObjectLiteralExpression,\n name: string,\n initializer: string,\n): ObjectLiteralExpression | null {\n const prop = obj.getProperty(name);\n if (!prop) {\n obj.addPropertyAssignment({ name, initializer });\n const added = obj.getProperty(name);\n if (!added || added.getKind() !== SyntaxKind.PropertyAssignment)\n return null;\n const init = (\n added as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!init || init.getKind() !== SyntaxKind.ObjectLiteralExpression)\n return null;\n return init as ObjectLiteralExpression;\n }\n\n if (prop.getKind() !== SyntaxKind.PropertyAssignment) return null;\n const init = (prop as import(\"ts-morph\").PropertyAssignment).getInitializer();\n if (!init) return null;\n if (init.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n (prop as import(\"ts-morph\").PropertyAssignment).setInitializer(initializer);\n const init2 = (\n prop as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n return init2 && init2.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (init2 as ObjectLiteralExpression)\n : null;\n }\n\n return init as ObjectLiteralExpression;\n}\n\nexport function modifySvelteConfig(svelteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(svelteConfigPath)) {\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(svelteConfigPath);\n\n const defaultExport = sourceFile.getExportAssignment(\n (ea) => !ea.isExportEquals(),\n );\n const exportedExpr = defaultExport?.getExpression();\n\n let configObj: ObjectLiteralExpression | null = null;\n if (exportedExpr?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = exportedExpr as ObjectLiteralExpression;\n } else if (exportedExpr?.getKind() === SyntaxKind.Identifier) {\n const ident = exportedExpr.getText();\n const varDecl = sourceFile.getVariableDeclaration(ident);\n const init = varDecl?.getInitializer();\n if (init?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = init as ObjectLiteralExpression;\n }\n }\n\n if (!configObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const kitObj = getOrCreateObjectLiteralProperty(configObj, \"kit\", \"{}\");\n if (!kitObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const aliasObj = getOrCreateObjectLiteralProperty(kitObj, \"alias\", \"{}\");\n if (!aliasObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const existingLocales = aliasObj.getProperty(\"$locales\");\n if (!existingLocales) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (existingLocales.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const init = (\n existingLocales as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current === \"src/locales\") return { status: \"success\", changed: false };\n\n (existingLocales as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"'src/locales'\",\n );\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\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.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, 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.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, 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.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, 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 if (/lang\\s*=/.test(match)) {\n return match;\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 path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LOAD_SNIPPET = dedent`\n import { browser } from '$app/environment';\n import { loadLocale } from 'wuchale/load-utils';\n\n import { getLocale } from '$locales/main.url';\n import '$locales/main.loader.svelte';\n import '$locales/js.loader';\n\n export const load = async ({ url, data }) => {\n const locale = getLocale(url);\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return data;\n };\n`;\n\nconst FAILURE_HINT = [\n \"Merge the wuchale loader into your existing load function in +layout.ts:\",\n \"\",\n LOAD_SNIPPET,\n].join(\"\\n\");\n\nexport function ensureRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (fs.existsSync(layoutPath)) {\n const existing = fs.readFileSync(layoutPath, \"utf8\");\n if (existing.includes(\"loadLocale\") || existing.includes(\"translateUrl\")) {\n return { status: \"success\", changed: false };\n }\n\n if (/\\bexport\\s+(const|function)\\s+load\\b/.test(existing)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n }\n\n fs.mkdirSync(path.dirname(layoutPath), { recursive: true });\n fs.writeFileSync(layoutPath, LOAD_SNIPPET + \"\\n\");\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 { 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\nfunction findFirstExistingFile(root: string, candidates: string[]): string {\n for (const relPath of candidates) {\n const absPath = path.join(root, relPath);\n if (fs.existsSync(absPath)) {\n return absPath;\n }\n }\n return path.join(root, candidates[0]);\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath = findFirstExistingFile(options.root, [\n \"vite.config.ts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n \"vite.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Modifying svelte.config\");\n const svelteConfigPath = findFirstExistingFile(options.root, [\n \"svelte.config.ts\",\n \"svelte.config.js\",\n \"svelte.config.mjs\",\n \"svelte.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(svelteConfigPath, modifySvelteConfig(svelteConfigPath)),\n );\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;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAiB,GAAuC;AACtE,KAAI,CAAC,EAAG,WAAW,EAAe,CAChC,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAOzD,IAAM,IAJU,IAAI,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,IAAM;EAClC,sBAAsB,EAAE,WAAW,EAAU,QAAQ;EACtD,CAAC,CACyB,oBAAoB,EAAe,EAE1D,IAAU,IACV,IAAS;AAMb,CAJkB,EACf,uBAAuB,CACvB,MAAM,MAAM,EAAE,yBAAyB,KAAK,eAAe,KAG5D,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,UAAU;EACzB,iBAAiB;EAClB,CAAC,EACF,IAAU;CAOZ,IAAM,IAJmB,EACtB,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,eAAe,EAE5B,cAAc,GAAG,IAC/C,IACJ,GAAW,SAAS,KAAK,EAAW,0BAC/B,IACD;AAEN,KAAI,CAAC,EACH,KAAS;MACJ;EACL,IAAM,IAAc,EAAU,YAAY,UAAU;AACpD,MAAI,CAAC,EAKH,CAJA,EAAU,sBAAsB;GAC9B,MAAM;GACN,aAAa;GACd,CAAC,EACF,IAAU;WACD,EAAY,SAAS,KAAK,EAAW,mBAC9C,KAAS;OACJ;GACL,IAAM,IACJ,EACA,gBAAgB;AAElB,OAAI,CAAC,EAIH,CAHC,EAAsD,eACrD,cACD,EAC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
|
1
1
|
import { n as e } from "./logger-BpgCb-ZG.js";
|
|
2
|
-
import { modifyOutcomeToFile as t } from "./modify-file-
|
|
2
|
+
import { modifyOutcomeToFile as t } from "./modify-file-DGBe3ycw.js";
|
|
3
3
|
import n from "node:fs";
|
|
4
4
|
import r from "node:path";
|
|
5
5
|
import { Project as i, SyntaxKind as a } from "ts-morph";
|
|
@@ -53,4 +53,4 @@ async function s(n) {
|
|
|
53
53
|
//#endregion
|
|
54
54
|
export { s as generate };
|
|
55
55
|
|
|
56
|
-
//# sourceMappingURL=generate.runtime-
|
|
56
|
+
//# sourceMappingURL=generate.runtime-C8Wbgx77.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-C8Wbgx77.js","names":[],"sources":["../../src/patterns/disable/api/modifies/hooks.server.ts","../../src/patterns/disable/api/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"success\", changed: false };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n return { status: \"success\", changed: false };\n }\n\n apiProp.remove();\n\n if (optionsObj.getProperties().length === 0) {\n callExpr.removeArgument(0);\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\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 { unmodifyHooksServer } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const file = modifyOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServer(hooksServerPath),\n );\n if (file) modifies.push(file);\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,SAAgB,EAAoB,GAAwC;AAC1E,KAAI,CAAC,EAAG,WAAW,EAAgB,CACjC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAiB,EAAG,aAAa,GAAiB,OAAO,EAEzD,IADU,IAAI,GAAS,CACF,oBAAoB,EAAgB,EAEzD,IAAW,EACd,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,mBAAmB;AAEpE,KAAI,CAAC,EACH,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAO,EAAS,cAAc;AACpC,KAAI,EAAK,WAAW,EAClB,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAW,EAAK;AACtB,KAAI,EAAS,SAAS,KAAK,EAAW,wBACpC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAa,EAAS,cAAc,EAAW,wBAAwB,EACvE,IAAU,EAAW,YAAY,MAAM;AAc7C,QAbK,KAIL,EAAQ,QAAQ,EAEZ,EAAW,eAAe,CAAC,WAAW,KACxC,EAAS,eAAe,EAAE,EAG5B,EAAW,YAAY,EACvB,EAAW,UAAU,EAEd;EACL,QAAQ;EACR,SAAS,EAAW,aAAa,KAAK;EACvC,IAfQ;EAAE,QAAQ;EAAW,SAAS;EAAO;;;;AC5BhD,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,EAAQ,EAC3B,IAAmB,EAAE;AAE3B,GAAO,KAAK,4BAA4B;CACxC,IAAM,IAAkB,EAAK,KAAK,EAAQ,MAAM,OAAO,kBAAkB,EACnE,IAAO,EACX,GACA,EAAoB,EAAgB,CACrC;AAGD,QAFI,KAAM,EAAS,KAAK,EAAK,EAEtB;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
2
|
import { n as t } from "./util-CLl3VxaE.js";
|
|
3
3
|
import { n } from "./logger-BpgCb-ZG.js";
|
|
4
|
-
import { t as r } from "./pocketbase-
|
|
5
|
-
import { modifyOutcomeToFile as i } from "./modify-file-
|
|
6
|
-
import { a, n as o, o as s, t as c } from "./ts-morph-helpers-
|
|
7
|
-
import { getMigrationFile as l, migrationDelay as u, withPocketbase as d } from "./pocketbase-
|
|
8
|
-
import { applyCollectionRulePatches as f, createCollectionIdempotent as p } from "./collections-
|
|
4
|
+
import { t as r } from "./pocketbase-D5p0NSdu.js";
|
|
5
|
+
import { modifyOutcomeToFile as i } from "./modify-file-DGBe3ycw.js";
|
|
6
|
+
import { a, n as o, o as s, t as c } from "./ts-morph-helpers-DjpZhZ7I.js";
|
|
7
|
+
import { getMigrationFile as l, migrationDelay as u, withPocketbase as d } from "./pocketbase-CEhGbssT.js";
|
|
8
|
+
import { applyCollectionRulePatches as f, createCollectionIdempotent as p } from "./collections-CUtXB8_s.js";
|
|
9
9
|
import m from "node:fs";
|
|
10
10
|
import h from "node:path";
|
|
11
11
|
import { Project as g, SyntaxKind as _ } from "ts-morph";
|
|
@@ -605,4 +605,4 @@ async function P(e) {
|
|
|
605
605
|
//#endregion
|
|
606
606
|
export { P as generate };
|
|
607
607
|
|
|
608
|
-
//# sourceMappingURL=generate.runtime-
|
|
608
|
+
//# sourceMappingURL=generate.runtime-CJg6JI4m.js.map
|