@velastack/patterns 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{_layout-D0OmzCu1.js → _layout-DqH4lA_r.js} +8 -8
- package/dist/chunks/{_layout-D0OmzCu1.js.map → _layout-DqH4lA_r.js.map} +1 -1
- package/dist/chunks/{collections-DDYlpDNO.js → collections-CcL5bbBk.js} +2 -2
- package/dist/chunks/{collections-DDYlpDNO.js.map → collections-CcL5bbBk.js.map} +1 -1
- package/dist/chunks/compose-handle-D16KmBVd.js +322 -0
- package/dist/chunks/compose-handle-D16KmBVd.js.map +1 -0
- package/dist/chunks/{config-target-DOi8kI_f.js → config-target-Co-ij8p3.js} +9 -9
- package/dist/chunks/{config-target-DOi8kI_f.js.map → config-target-Co-ij8p3.js.map} +1 -1
- package/dist/chunks/format-result-Cb2hWsb8.js +64 -0
- package/dist/chunks/format-result-Cb2hWsb8.js.map +1 -0
- package/dist/chunks/{generate.runtime-AjCpCfv3.js → generate.runtime-1gbaOucO.js} +144 -137
- package/dist/chunks/generate.runtime-1gbaOucO.js.map +1 -0
- package/dist/chunks/{generate.runtime-BpYOznG5.js → generate.runtime-A8wfItN7.js} +21 -21
- package/dist/chunks/{generate.runtime-BpYOznG5.js.map → generate.runtime-A8wfItN7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BtX_9lLk.js → generate.runtime-BL7uKgW7.js} +33 -33
- package/dist/chunks/{generate.runtime-BtX_9lLk.js.map → generate.runtime-BL7uKgW7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BYJZB1ad.js → generate.runtime-BX53l-rL.js} +37 -57
- package/dist/chunks/generate.runtime-BX53l-rL.js.map +1 -0
- package/dist/chunks/{generate.runtime-DEl6b1Ti.js → generate.runtime-Bb64J0ab.js} +15 -15
- package/dist/chunks/{generate.runtime-DEl6b1Ti.js.map → generate.runtime-Bb64J0ab.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DRcq4d5D.js → generate.runtime-BbNMkG4j.js} +27 -27
- package/dist/chunks/{generate.runtime-DRcq4d5D.js.map → generate.runtime-BbNMkG4j.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BgezGu15.js → generate.runtime-BdPtilz4.js} +94 -93
- package/dist/chunks/generate.runtime-BdPtilz4.js.map +1 -0
- package/dist/chunks/{generate.runtime-DH9o-888.js → generate.runtime-BqxVaq5P.js} +24 -24
- package/dist/chunks/{generate.runtime-DH9o-888.js.map → generate.runtime-BqxVaq5P.js.map} +1 -1
- package/dist/chunks/{generate.runtime-fSDNxfGG.js → generate.runtime-CJVy-mMN.js} +11 -11
- package/dist/chunks/{generate.runtime-fSDNxfGG.js.map → generate.runtime-CJVy-mMN.js.map} +1 -1
- package/dist/chunks/generate.runtime-CN3v78hx.js +82 -0
- package/dist/chunks/generate.runtime-CN3v78hx.js.map +1 -0
- package/dist/chunks/generate.runtime-CSXj-ebM.js +122 -0
- package/dist/chunks/generate.runtime-CSXj-ebM.js.map +1 -0
- package/dist/chunks/{generate.runtime-B6kxV3Bi.js → generate.runtime-CVLtEsXb.js} +28 -28
- package/dist/chunks/{generate.runtime-B6kxV3Bi.js.map → generate.runtime-CVLtEsXb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B_Fk1Jjs.js → generate.runtime-CiTmbkAk.js} +31 -34
- package/dist/chunks/{generate.runtime-B_Fk1Jjs.js.map → generate.runtime-CiTmbkAk.js.map} +1 -1
- package/dist/chunks/{generate.runtime-OjW1XETW.js → generate.runtime-CwzHEcKv.js} +33 -33
- package/dist/chunks/{generate.runtime-OjW1XETW.js.map → generate.runtime-CwzHEcKv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-SQhCLSah.js → generate.runtime-DAkg7Fy5.js} +13 -13
- package/dist/chunks/{generate.runtime-SQhCLSah.js.map → generate.runtime-DAkg7Fy5.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DK7iXmAZ.js → generate.runtime-DPIH5sSI.js} +17 -17
- package/dist/chunks/{generate.runtime-DK7iXmAZ.js.map → generate.runtime-DPIH5sSI.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CTiJEVF2.js → generate.runtime-Dj22Kx0W.js} +31 -31
- package/dist/chunks/{generate.runtime-CTiJEVF2.js.map → generate.runtime-Dj22Kx0W.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CycY6kPr.js → generate.runtime-DnWw9tL1.js} +41 -41
- package/dist/chunks/{generate.runtime-CycY6kPr.js.map → generate.runtime-DnWw9tL1.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DHRCNPVx.js → generate.runtime-Dx8Mcs2i.js} +27 -27
- package/dist/chunks/{generate.runtime-DHRCNPVx.js.map → generate.runtime-Dx8Mcs2i.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cq1gqxzg.js → generate.runtime-Dywp4xth.js} +22 -22
- package/dist/chunks/{generate.runtime-Cq1gqxzg.js.map → generate.runtime-Dywp4xth.js.map} +1 -1
- package/dist/chunks/{generate.runtime-qjsxSPaH.js → generate.runtime-T9DZJH8m.js} +38 -38
- package/dist/chunks/{generate.runtime-qjsxSPaH.js.map → generate.runtime-T9DZJH8m.js.map} +1 -1
- package/dist/chunks/{generate.runtime-vTneb2SY.js → generate.runtime-Zh5n8XpR.js} +45 -45
- package/dist/chunks/{generate.runtime-vTneb2SY.js.map → generate.runtime-Zh5n8XpR.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CZQoVNt3.js → generate.runtime-d9HT4v-7.js} +33 -33
- package/dist/chunks/{generate.runtime-CZQoVNt3.js.map → generate.runtime-d9HT4v-7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dtf2BI_5.js → generate.runtime-j1gfY6Xq.js} +9 -9
- package/dist/chunks/{generate.runtime-Dtf2BI_5.js.map → generate.runtime-j1gfY6Xq.js.map} +1 -1
- package/dist/chunks/generate.runtime-l-Tiahb2.js +170 -0
- package/dist/chunks/generate.runtime-l-Tiahb2.js.map +1 -0
- package/dist/chunks/modify-file-BlWTOkCH.js +212 -0
- package/dist/chunks/modify-file-BlWTOkCH.js.map +1 -0
- package/dist/chunks/{modify-svelte-config-remote-D3eBzcZc.js → modify-svelte-config-remote-CDKs_Qi0.js} +2 -2
- package/dist/chunks/{modify-svelte-config-remote-D3eBzcZc.js.map → modify-svelte-config-remote-CDKs_Qi0.js.map} +1 -1
- package/dist/chunks/{pocketbase-BerjVikJ.js → pocketbase-ewxQLtse.js} +16 -16
- package/dist/chunks/{pocketbase-BerjVikJ.js.map → pocketbase-ewxQLtse.js.map} +1 -1
- package/dist/chunks/{shared-Cmbzu7Od.js → shared-Bm3eMFy-.js} +2 -2
- package/dist/chunks/{shared-Cmbzu7Od.js.map → shared-Bm3eMFy-.js.map} +1 -1
- package/dist/chunks/svelte-file-B3RfgVdt.js +123 -0
- package/dist/chunks/svelte-file-B3RfgVdt.js.map +1 -0
- package/dist/chunks/{test-setup-DjbhQYZC.js → test-setup-B2hd8I-s.js} +15 -15
- package/dist/chunks/{test-setup-DjbhQYZC.js.map → test-setup-B2hd8I-s.js.map} +1 -1
- package/dist/chunks/{ui-BdkuOXPw.js → ui-CD-psDWi.js} +12 -12
- package/dist/chunks/{ui-BdkuOXPw.js.map → ui-CD-psDWi.js.map} +1 -1
- package/dist/chunks/ui-jhXrsw4T.js +12 -0
- package/dist/chunks/ui-jhXrsw4T.js.map +1 -0
- package/dist/chunks/{write-result-BVWPlGvE.js → write-result-DBKv-Q7J.js} +51 -51
- package/dist/chunks/{write-result-BVWPlGvE.js.map → write-result-DBKv-Q7J.js.map} +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +988 -996
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/format-result-BdAy5M8C.js +0 -50
- package/dist/chunks/format-result-BdAy5M8C.js.map +0 -1
- package/dist/chunks/generate.runtime-AjCpCfv3.js.map +0 -1
- package/dist/chunks/generate.runtime-BYJZB1ad.js.map +0 -1
- package/dist/chunks/generate.runtime-BcVAKzoY.js +0 -138
- package/dist/chunks/generate.runtime-BcVAKzoY.js.map +0 -1
- package/dist/chunks/generate.runtime-BgezGu15.js.map +0 -1
- package/dist/chunks/generate.runtime-D2WfvXm2.js +0 -106
- package/dist/chunks/generate.runtime-D2WfvXm2.js.map +0 -1
- package/dist/chunks/generate.runtime-DaPNrIyg.js +0 -28
- package/dist/chunks/generate.runtime-DaPNrIyg.js.map +0 -1
- package/dist/chunks/modify-file-Cgu_WeFk.js +0 -22
- package/dist/chunks/modify-file-Cgu_WeFk.js.map +0 -1
- package/dist/chunks/ts-morph-helpers-teS3yXg-.js +0 -229
- package/dist/chunks/ts-morph-helpers-teS3yXg-.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
3
|
import { a as n, i as r, n as i, o as a, r as o, s, t as c } from "./dispatch-B5PfQ2CA.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import p from "node:
|
|
7
|
-
import m from "node:
|
|
4
|
+
import { f as l, modifyOutcomeToFile as u, r as d } from "./modify-file-BlWTOkCH.js";
|
|
5
|
+
import { t as f } from "./svelte-file-B3RfgVdt.js";
|
|
6
|
+
import p from "node:fs";
|
|
7
|
+
import m from "node:path";
|
|
8
8
|
import { SyntaxKind as h } from "ts-morph";
|
|
9
9
|
//#region src/patterns/enable/subscriptions/modifies/modify-webhook-server.ts
|
|
10
10
|
var g = e`
|
|
@@ -39,17 +39,17 @@ var g = e`
|
|
|
39
39
|
break;
|
|
40
40
|
`;
|
|
41
41
|
function y(e) {
|
|
42
|
-
if (!
|
|
42
|
+
if (!p.existsSync(e)) return {
|
|
43
43
|
status: "not-found",
|
|
44
44
|
message: _
|
|
45
45
|
};
|
|
46
|
-
let t =
|
|
46
|
+
let t = p.readFileSync(e, "utf8");
|
|
47
47
|
if (t.includes("handleSubscriptionCreated")) return {
|
|
48
48
|
status: "success",
|
|
49
49
|
changed: !1
|
|
50
50
|
};
|
|
51
|
-
let n = !1, { source: r } =
|
|
52
|
-
|
|
51
|
+
let n = !1, { source: r } = l(t, (e) => {
|
|
52
|
+
d(e, [
|
|
53
53
|
{
|
|
54
54
|
namedImports: ["handleSubscriptionCreated"],
|
|
55
55
|
moduleSpecifier: "./subscription/created"
|
|
@@ -73,7 +73,7 @@ function y(e) {
|
|
|
73
73
|
} else return;
|
|
74
74
|
e.formatText(), n = !0;
|
|
75
75
|
});
|
|
76
|
-
return n ? (
|
|
76
|
+
return n ? (p.writeFileSync(e, r, "utf8"), {
|
|
77
77
|
status: "success",
|
|
78
78
|
changed: !0
|
|
79
79
|
}) : {
|
|
@@ -84,11 +84,11 @@ function y(e) {
|
|
|
84
84
|
//#endregion
|
|
85
85
|
//#region src/patterns/enable/subscriptions/modifies/modify-by-template.ts
|
|
86
86
|
function b(e, t, n, r) {
|
|
87
|
-
if (!
|
|
87
|
+
if (!p.existsSync(e)) return {
|
|
88
88
|
status: "not-found",
|
|
89
89
|
message: r
|
|
90
90
|
};
|
|
91
|
-
let i =
|
|
91
|
+
let i = p.readFileSync(e, "utf8");
|
|
92
92
|
if (i.includes(n)) return {
|
|
93
93
|
status: "success",
|
|
94
94
|
changed: !1
|
|
@@ -97,7 +97,7 @@ function b(e, t, n, r) {
|
|
|
97
97
|
return i === a ? {
|
|
98
98
|
status: "success",
|
|
99
99
|
changed: !1
|
|
100
|
-
} : (
|
|
100
|
+
} : (p.writeFileSync(e, a, "utf8"), {
|
|
101
101
|
status: "success",
|
|
102
102
|
changed: !0
|
|
103
103
|
});
|
|
@@ -116,11 +116,11 @@ var C = [
|
|
|
116
116
|
"<AppSidebar user={data.user} meta={data.meta} subscription={data.subscription} />"
|
|
117
117
|
].join("\n"), w = ["Create src/routes/(app)/+layout.svelte with an <AppSidebar /> that receives the subscription prop."].join("\n");
|
|
118
118
|
function T(e) {
|
|
119
|
-
if (!
|
|
119
|
+
if (!p.existsSync(e)) return {
|
|
120
120
|
status: "not-found",
|
|
121
121
|
message: w
|
|
122
122
|
};
|
|
123
|
-
let t =
|
|
123
|
+
let t = f.fromPath(e);
|
|
124
124
|
return t.hasElement("AppSidebar") ? t.hasAttribute("AppSidebar", "subscription") ? {
|
|
125
125
|
status: "success",
|
|
126
126
|
changed: !1
|
|
@@ -145,7 +145,7 @@ var E = "{ id: string; productName: string | null } | null", D = [
|
|
|
145
145
|
"3. Pass `{subscription}` to <NavUser>."
|
|
146
146
|
].join("\n"), O = ["Create src/lib/components/app-sidebar.svelte before enabling subscriptions."].join("\n");
|
|
147
147
|
function k(e) {
|
|
148
|
-
let t = !1, { source: n } =
|
|
148
|
+
let t = !1, { source: n } = l(e, (e) => {
|
|
149
149
|
for (let n of e.getVariableDeclarations()) {
|
|
150
150
|
let e = n.getInitializer();
|
|
151
151
|
if (!e || e.getText() !== "$props()") continue;
|
|
@@ -176,16 +176,16 @@ function k(e) {
|
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
function A(e) {
|
|
179
|
-
if (!
|
|
179
|
+
if (!p.existsSync(e)) return {
|
|
180
180
|
status: "not-found",
|
|
181
181
|
message: O
|
|
182
182
|
};
|
|
183
|
-
let t =
|
|
183
|
+
let t = p.readFileSync(e, "utf8");
|
|
184
184
|
if (t.includes("subscription?: {") || t.includes("subscription={subscription}") || t.includes("{subscription}")) return {
|
|
185
185
|
status: "success",
|
|
186
186
|
changed: !1
|
|
187
187
|
};
|
|
188
|
-
let n = new
|
|
188
|
+
let n = new f(t);
|
|
189
189
|
if (!n.hasElement("NavUser")) return {
|
|
190
190
|
status: "failed",
|
|
191
191
|
message: D
|
|
@@ -238,20 +238,20 @@ async function z(e) {
|
|
|
238
238
|
e && r.push(e);
|
|
239
239
|
};
|
|
240
240
|
n.info("Modifying webhooks/stripe/handlers/dispatch.ts");
|
|
241
|
-
let a =
|
|
242
|
-
i(
|
|
243
|
-
let o =
|
|
244
|
-
i(
|
|
245
|
-
let s =
|
|
246
|
-
i(
|
|
247
|
-
let c =
|
|
248
|
-
i(
|
|
249
|
-
let
|
|
250
|
-
i(l
|
|
251
|
-
let d =
|
|
252
|
-
i(
|
|
253
|
-
let f =
|
|
254
|
-
return i(
|
|
241
|
+
let a = m.join(e.root, "src", "routes", "webhooks", "stripe", "handlers", "dispatch.ts");
|
|
242
|
+
i(u(a, y(a))), n.info("Modifying (app)/+layout.server.ts");
|
|
243
|
+
let o = m.join(e.root, "src", "routes", "(app)", "+layout.server.ts");
|
|
244
|
+
i(u(o, S(o, R("src/routes/(app)/+layout.server.ts")))), n.info("Modifying (app)/+layout.svelte");
|
|
245
|
+
let s = m.join(e.root, "src", "routes", "(app)", "+layout.svelte");
|
|
246
|
+
i(u(s, T(s))), n.info("Modifying app-sidebar.svelte");
|
|
247
|
+
let c = m.join(e.root, "src", "lib", "components", "app-sidebar.svelte");
|
|
248
|
+
i(u(c, A(c))), n.info("Modifying nav-user.svelte");
|
|
249
|
+
let l = m.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
250
|
+
i(u(l, M(l, R("src/lib/components/nav-user.svelte")))), n.info("Modifying billing/+page.server.ts");
|
|
251
|
+
let d = m.join(e.root, "src", "routes", "(app)", "billing", "+page.server.ts");
|
|
252
|
+
i(u(d, P(d, R("src/routes/(app)/billing/+page.server.ts")))), n.info("Modifying billing/+page.svelte");
|
|
253
|
+
let f = m.join(e.root, "src", "routes", "(app)", "billing", "+page.svelte");
|
|
254
|
+
return i(u(f, I(f, R("src/routes/(app)/billing/+page.svelte")))), {
|
|
255
255
|
creates: [],
|
|
256
256
|
modifies: r,
|
|
257
257
|
deletes: [],
|
|
@@ -265,4 +265,4 @@ async function z(e) {
|
|
|
265
265
|
//#endregion
|
|
266
266
|
export { z as generate };
|
|
267
267
|
|
|
268
|
-
//# sourceMappingURL=generate.runtime-
|
|
268
|
+
//# sourceMappingURL=generate.runtime-d9HT4v-7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-CZQoVNt3.js","names":[],"sources":["../../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 { 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/handlers/dispatch.ts:\n\n Add imports:\n import { handleSubscriptionCreated } from \"./subscription/created\";\n import { handleSubscriptionUpdated } from \"./subscription/updated\";\n import { handleSubscriptionDeleted } from \"./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/handlers/dispatch.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: \"./subscription/created\",\n },\n {\n namedImports: [\"handleSubscriptionUpdated\"],\n moduleSpecifier: \"./subscription/updated\",\n },\n {\n namedImports: [\"handleSubscriptionDeleted\"],\n moduleSpecifier: \"./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(\n last.getText() + `\\n\\n${SUBSCRIPTION_CASES_SNIPPET}`,\n );\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(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\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((src) => updateScript(src).source);\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(filePath, template, \"selectPlan\", 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.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(filePath, template, \"availablePlans\", NOT_FOUND_HINT);\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 { 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 webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.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":";;;;;;;;;AASA,IAAM,IAAe,CAAM;;;;;;;;;;;;;;;;;;GAoBrB,IACJ,0GAEI,IAA6B,CAAM;;;;;;;;;;;;;AAczC,SAAgB,EAAoB,GAAiC;CACnE,IAAI,CAAC,EAAG,WAAW,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAGxD,IAAM,IAAW,EAAG,aAAa,GAAU,MAAM;CACjD,IAAI,EAAS,SAAS,2BAA2B,GAC/C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAI,IAAa,IACX,EAAE,cAAW,EAAmB,IAAW,MAAO;EACtD,EAAc,GAAI;GAChB;IACE,cAAc,CAAC,2BAA2B;IAC1C,iBAAiB;GACnB;GACA;IACE,c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,KAC7B,EAAQ,MACR,OACA,UACA,YACA,UACA,YACA,aACF;CAQA,AAPA,EACE,EACE,GACA,EAAoB,CAAiB,CACvC,CACF,GAEA,EAAO,KAAK,mCAAmC;CAC/C,IAAM,IAAsB,EAAK,KAC/B,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,EAAS,oCAAoC,CAC/C,CACF,CACF,GAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAM,IAAsB,EAAK,KAC/B,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAQA,AAPA,EACE,EACE,GACA,EAAsB,CAAmB,CAC3C,CACF,GAEA,EAAO,KAAK,8BAA8B;CAC1C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAKA,AAJA,EACE,EAAoB,GAAgB,EAAiB,CAAc,CAAC,CACtE,GAEA,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,EAAS,oCAAoC,CAC/C,CACF,CACF,GAEA,EAAO,KAAK,mCAAmC;CAC/C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,iBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,EAAS,0CAA0C,CACrD,CACF,CACF,GAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,cACF;CAWA,OAVA,EACE,EACE,GACA,EACE,GACA,EAAS,uCAAuC,CAClD,CACF,CACF,GAEO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-d9HT4v-7.js","names":[],"sources":["../../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 { 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/handlers/dispatch.ts:\n\n Add imports:\n import { handleSubscriptionCreated } from \"./subscription/created\";\n import { handleSubscriptionUpdated } from \"./subscription/updated\";\n import { handleSubscriptionDeleted } from \"./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/handlers/dispatch.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: \"./subscription/created\",\n },\n {\n namedImports: [\"handleSubscriptionUpdated\"],\n moduleSpecifier: \"./subscription/updated\",\n },\n {\n namedImports: [\"handleSubscriptionDeleted\"],\n moduleSpecifier: \"./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(\n last.getText() + `\\n\\n${SUBSCRIPTION_CASES_SNIPPET}`,\n );\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(\n /^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm,\n \"\",\n );\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((src) => updateScript(src).source);\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(filePath, template, \"selectPlan\", 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.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(filePath, template, \"availablePlans\", NOT_FOUND_HINT);\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 { 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 webhooks/stripe/handlers/dispatch.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.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":";;;;;;;;;AASA,IAAM,IAAe,CAAM;;;;;;;;;;;;;;;;;;GAoBrB,IACJ,0GAEI,IAA6B,CAAM;;;;;;;;;;;;;AAczC,SAAgB,EAAoB,GAAiC;CACnE,IAAI,CAAC,EAAG,WAAW,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAGxD,IAAM,IAAW,EAAG,aAAa,GAAU,MAAM;CACjD,IAAI,EAAS,SAAS,2BAA2B,GAC/C,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAI,IAAa,IACX,EAAE,cAAW,EAAmB,IAAW,MAAO;EACtD,EAAc,GAAI;GAChB;IACE,cAAc,CAAC,2BAA2B;IAC1C,iBAAiB;GACnB;GACA;IACE,cAAc,CAAC,2BAA2B;IAC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A,UACA,YACA,UACA,YACA,aACF;CAQA,AAPA,EACE,EACE,GACA,EAAoB,CAAiB,CACvC,CACF,GAEA,EAAO,KAAK,mCAAmC;CAC/C,IAAM,IAAsB,EAAK,KAC/B,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,EAAS,oCAAoC,CAC/C,CACF,CACF,GAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAM,IAAsB,EAAK,KAC/B,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAQA,AAPA,EACE,EACE,GACA,EAAsB,CAAmB,CAC3C,CACF,GAEA,EAAO,KAAK,8BAA8B;CAC1C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,OACA,cACA,oBACF;CAKA,AAJA,EACE,EAAoB,GAAgB,EAAiB,CAAc,CAAC,CACtE,GAEA,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,EAAS,oCAAoC,CAC/C,CACF,CACF,GAEA,EAAO,KAAK,mCAAmC;CAC/C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,iBACF;CAWA,AAVA,EACE,EACE,GACA,EACE,GACA,EAAS,0CAA0C,CACrD,CACF,CACF,GAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,cACF;CAWA,OAVA,EACE,EACE,GACA,EACE,GACA,EAAS,uCAAuC,CAClD,CACF,CACF,GAEO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { modifyOutcomeToFile as n } from "./modify-file-
|
|
4
|
-
import r from "node:
|
|
5
|
-
import i from "node:
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-BlWTOkCH.js";
|
|
4
|
+
import r from "node:fs";
|
|
5
|
+
import i from "node:path";
|
|
6
6
|
import { Project as a, QuoteKind as o } from "ts-morph";
|
|
7
7
|
//#region src/patterns/enable/workflows/modifies/hooks.server.ts
|
|
8
8
|
var s = e`
|
|
@@ -44,11 +44,11 @@ function d(e) {
|
|
|
44
44
|
return e.getVariableDeclaration("init") || e.getFunction("init") ? !0 : e.getExportDeclarations().some((e) => e.getNamedExports().some((e) => e.getName() === "init"));
|
|
45
45
|
}
|
|
46
46
|
function f(e) {
|
|
47
|
-
if (!
|
|
47
|
+
if (!r.existsSync(e)) return {
|
|
48
48
|
status: "not-found",
|
|
49
49
|
message: l
|
|
50
50
|
};
|
|
51
|
-
if (
|
|
51
|
+
if (r.readFileSync(e, "utf8").includes("startWorker")) return {
|
|
52
52
|
status: "success",
|
|
53
53
|
changed: !1
|
|
54
54
|
};
|
|
@@ -67,9 +67,9 @@ function f(e) {
|
|
|
67
67
|
//#endregion
|
|
68
68
|
//#region src/patterns/enable/workflows/generate.runtime.ts
|
|
69
69
|
async function p(e) {
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
let o =
|
|
70
|
+
let r = t(e), a = [];
|
|
71
|
+
r.info("Modifying hooks.server.ts");
|
|
72
|
+
let o = i.join(e.root, "src", "hooks.server.ts"), s = n(o, f(o));
|
|
73
73
|
return s && a.push(s), {
|
|
74
74
|
creates: [],
|
|
75
75
|
modifies: a,
|
|
@@ -84,4 +84,4 @@ async function p(e) {
|
|
|
84
84
|
//#endregion
|
|
85
85
|
export { p as generate };
|
|
86
86
|
|
|
87
|
-
//# sourceMappingURL=generate.runtime-
|
|
87
|
+
//# sourceMappingURL=generate.runtime-j1gfY6Xq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-j1gfY6Xq.js","names":[],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit';\n import { startWorker } from '$lib/server/workflows';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): 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(\"startWorker\")) {\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 if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"$lib/server/workflows\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\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 { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\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":";;;;;;;AAKA,IAAM,IAAe,CAAM;;;GAKrB,IAAe,CAAM;;;;;;;;;GAWrB,IAAiB,CAAM;;;;;;;;AAS7B,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AAM,IAAS,EAAU,CAAO,GAC1B,IAAmB,CAAC;CAE1B,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAkB,EAAK,KAAK,EAAQ,MAAM,OAAO,iBAAiB,GAClE,IAAY,EAChB,GACA,EAA2B,CAAe,CAC5C;CAGA,OAFI,KAAW,EAAS,KAAK,CAAS,GAE/B;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { a as e } from "./util-BLYliuUK.js";
|
|
2
|
+
import { t } from "./dedent-Gq6Krl4n.js";
|
|
3
|
+
import { n } from "./logger-CQONztPm.js";
|
|
4
|
+
import { n as r } from "./shared-Bm3eMFy-.js";
|
|
5
|
+
import { a as i, modifyOutcomeToFile as a, n as o, revertOutcomeToFile as s, u as c } from "./modify-file-BlWTOkCH.js";
|
|
6
|
+
import { n as l } from "./compose-handle-D16KmBVd.js";
|
|
7
|
+
import { i as u, n as d, o as f } from "./test-setup-B2hd8I-s.js";
|
|
8
|
+
import p from "node:fs";
|
|
9
|
+
import m from "node:path";
|
|
10
|
+
import { Node as h, Project as g, QuoteKind as _ } from "ts-morph";
|
|
11
|
+
//#region src/patterns/disable/backend/modifies/hooks.server.ts
|
|
12
|
+
var v = t`
|
|
13
|
+
Take handlePocketbase(...) out of the exported handle in src/hooks.server.ts,
|
|
14
|
+
and its imports from '@velastack/pocketbase' and '$env/dynamic/private'.
|
|
15
|
+
`, y = t`
|
|
16
|
+
The workflows are removed with the backend. Take the startWorker() call out
|
|
17
|
+
of the init hook in src/hooks.server.ts, and its import:
|
|
18
|
+
|
|
19
|
+
import { startWorker } from '$lib/server/workflows';
|
|
20
|
+
`, b = [
|
|
21
|
+
"@velastack/pocketbase",
|
|
22
|
+
"$env/dynamic/private",
|
|
23
|
+
"$lib/server/workflows",
|
|
24
|
+
"@sveltejs/kit",
|
|
25
|
+
"@sveltejs/kit/hooks"
|
|
26
|
+
];
|
|
27
|
+
function x(e) {
|
|
28
|
+
return e ? h.isAwaitExpression(e) || h.isExpressionStatement(e) || h.isReturnStatement(e) ? x(e.getExpression()) : h.isCallExpression(e) && e.getExpression().getText() === "startWorker" && e.getArguments().length === 0 : !1;
|
|
29
|
+
}
|
|
30
|
+
function S(e) {
|
|
31
|
+
if (!h.isArrowFunction(e) && !h.isFunctionExpression(e) && !h.isFunctionDeclaration(e)) return !1;
|
|
32
|
+
let t = e.getBody();
|
|
33
|
+
if (!t) return !1;
|
|
34
|
+
if (!h.isBlock(t)) return x(t);
|
|
35
|
+
let n = t.getStatements();
|
|
36
|
+
return n.length === 1 && x(n[0]);
|
|
37
|
+
}
|
|
38
|
+
function C(e) {
|
|
39
|
+
let t = e.getFunction("init"), n = e.getVariableDeclaration("init"), r = t ?? n?.getVariableStatement();
|
|
40
|
+
return !r || !r.getText().includes("startWorker") ? null : (t ? S(t) : n?.getVariableStatement()?.getDeclarations().length === 1 && S(n.getInitializer())) ? r : "custom";
|
|
41
|
+
}
|
|
42
|
+
function w(e) {
|
|
43
|
+
if (!p.existsSync(e)) return {
|
|
44
|
+
status: "success",
|
|
45
|
+
changed: !1
|
|
46
|
+
};
|
|
47
|
+
let t = p.readFileSync(e, "utf8");
|
|
48
|
+
if (!t.includes("handlePocketbase") && !t.includes("startWorker")) return {
|
|
49
|
+
status: "success",
|
|
50
|
+
changed: !1
|
|
51
|
+
};
|
|
52
|
+
let n = new g({
|
|
53
|
+
compilerOptions: { allowJs: !0 },
|
|
54
|
+
manipulationSettings: { quoteKind: _.Single }
|
|
55
|
+
}).addSourceFileAtPath(e);
|
|
56
|
+
if (C(n) === "custom") return {
|
|
57
|
+
status: "failed",
|
|
58
|
+
message: y
|
|
59
|
+
};
|
|
60
|
+
if (l(n, "handlePocketbase").status === "unsupported") return {
|
|
61
|
+
status: "failed",
|
|
62
|
+
message: v
|
|
63
|
+
};
|
|
64
|
+
let r = C(n);
|
|
65
|
+
return r && r !== "custom" && c(n, r), i(n, b), n.formatText(), o(n), n.saveSync(), {
|
|
66
|
+
status: "success",
|
|
67
|
+
changed: n.getFullText() !== t
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/patterns/disable/backend/modifies/layout-server.ts
|
|
72
|
+
var T = t`
|
|
73
|
+
src/routes/+layout.server.ts still reads locals.meta, which only the
|
|
74
|
+
PocketBase hook provides. Read the values from a static module instead:
|
|
75
|
+
|
|
76
|
+
import { site } from '$lib/site';
|
|
77
|
+
|
|
78
|
+
// locals.meta.appName -> site.name
|
|
79
|
+
// locals.meta.appURL -> site.url
|
|
80
|
+
// meta: locals.meta -> meta: { appName: site.name, appURL: site.url }
|
|
81
|
+
`;
|
|
82
|
+
function E(e) {
|
|
83
|
+
if (!p.existsSync(e)) return {
|
|
84
|
+
status: "success",
|
|
85
|
+
changed: !1
|
|
86
|
+
};
|
|
87
|
+
let t = p.readFileSync(e, "utf8");
|
|
88
|
+
if (!t.includes("locals.meta")) return {
|
|
89
|
+
status: "success",
|
|
90
|
+
changed: !1
|
|
91
|
+
};
|
|
92
|
+
let n = t.replace(/\blocals\.meta\.appName\b/g, "site.name").replace(/\blocals\.meta\.appURL\b/g, "site.url").replace(/\bmeta:\s*locals\.meta\b/g, "meta: { appName: site.name, appURL: site.url }");
|
|
93
|
+
if (n.includes("locals.meta")) return {
|
|
94
|
+
status: "failed",
|
|
95
|
+
message: T
|
|
96
|
+
};
|
|
97
|
+
let r = n.replace(/\(\{\s*locals\s*,\s*/g, "({ ").replace(/,\s*locals\s*\}/g, " }");
|
|
98
|
+
return /\blocals\b/.test(r) || (n = r), /from\s+['"]\$lib\/site['"]/.test(n) || (n = "import { site } from '$lib/site';\n" + n), p.writeFileSync(e, n, "utf8"), {
|
|
99
|
+
status: "success",
|
|
100
|
+
changed: !0
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/patterns/disable/backend/generate.runtime.ts
|
|
105
|
+
function D(e) {
|
|
106
|
+
let t = "My App";
|
|
107
|
+
try {
|
|
108
|
+
let n = JSON.parse(p.readFileSync(m.join(e, "package.json"), "utf8"));
|
|
109
|
+
n.name && (t = n.name);
|
|
110
|
+
} catch {}
|
|
111
|
+
return [
|
|
112
|
+
"/**",
|
|
113
|
+
" * Site-wide metadata.",
|
|
114
|
+
" *",
|
|
115
|
+
" * Without a backend there is nothing to read this from at runtime, so this",
|
|
116
|
+
" * file is the source of truth. Set `url` to where the site is deployed:",
|
|
117
|
+
" * canonical links and Open Graph image URLs are built from it.",
|
|
118
|
+
" */",
|
|
119
|
+
"export const site = {",
|
|
120
|
+
`\tname: ${JSON.stringify(t)},`,
|
|
121
|
+
" url: 'http://localhost:5173'",
|
|
122
|
+
"};",
|
|
123
|
+
""
|
|
124
|
+
].join("\n");
|
|
125
|
+
}
|
|
126
|
+
function O(e) {
|
|
127
|
+
if (!p.existsSync(e)) return [];
|
|
128
|
+
let t = [];
|
|
129
|
+
for (let n of p.readdirSync(e, { withFileTypes: !0 })) {
|
|
130
|
+
let r = m.join(e, n.name);
|
|
131
|
+
n.isDirectory() ? t.push(...O(r)) : n.name === "server.test.ts" && t.push(r);
|
|
132
|
+
}
|
|
133
|
+
return t;
|
|
134
|
+
}
|
|
135
|
+
async function k(t) {
|
|
136
|
+
let i = n(t), o = [], c = [], l = [];
|
|
137
|
+
i.info("Reverting adapter config");
|
|
138
|
+
let h = f(t.root), g = a(h.filePath, h.outcome);
|
|
139
|
+
g && c.push(g), i.info("Reverting hooks.server.ts");
|
|
140
|
+
let _ = m.join(t.root, "src", "hooks.server.ts"), v = s(_, w(_));
|
|
141
|
+
v.modify && c.push(v.modify), v.delete && l.push(v.delete), i.info("Reverting .gitignore");
|
|
142
|
+
let y = m.join(t.root, ".gitignore"), b = a(y, u(y));
|
|
143
|
+
b && c.push(b), i.info("Reverting src/routes/+layout.server.ts");
|
|
144
|
+
let x = m.join(t.root, "src", "routes", "+layout.server.ts"), S = a(x, E(x));
|
|
145
|
+
S && c.push(S);
|
|
146
|
+
let C = m.join(t.root, "src", "lib", "site.ts");
|
|
147
|
+
S?.status === "success" && !p.existsSync(C) && (i.info("Creating src/lib/site.ts"), o.push({
|
|
148
|
+
path: C,
|
|
149
|
+
language: e(C),
|
|
150
|
+
content: D(t.root),
|
|
151
|
+
status: "success"
|
|
152
|
+
}));
|
|
153
|
+
for (let e of O(m.join(t.root, "src"))) i.info(`Removing ${m.relative(t.root, e)}`), l.push(r(e));
|
|
154
|
+
i.info("Reverting test/setup.ts");
|
|
155
|
+
let T = m.join(t.root, "test", "setup.ts"), k = a(T, d(T));
|
|
156
|
+
return k && c.push(k), {
|
|
157
|
+
creates: o,
|
|
158
|
+
modifies: c,
|
|
159
|
+
deletes: l,
|
|
160
|
+
components: [],
|
|
161
|
+
packages: [],
|
|
162
|
+
collections: [],
|
|
163
|
+
collectionPatches: [],
|
|
164
|
+
collectionDrops: []
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
export { k as generate };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=generate.runtime-l-Tiahb2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-l-Tiahb2.js","names":[],"sources":["../../src/patterns/disable/backend/modifies/hooks.server.ts","../../src/patterns/disable/backend/modifies/layout-server.ts","../../src/patterns/disable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport {\n Node,\n Project,\n QuoteKind,\n type SourceFile,\n type Statement,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n pruneUnusedImports,\n removeStatementWithComments,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst HANDLE_HINT = dedent`\n Take handlePocketbase(...) out of the exported handle in src/hooks.server.ts,\n and its imports from '@velastack/pocketbase' and '$env/dynamic/private'.\n`;\n\nconst INIT_HINT = dedent`\n The workflows are removed with the backend. Take the startWorker() call out\n of the init hook in src/hooks.server.ts, and its import:\n\n import { startWorker } from '$lib/server/workflows';\n`;\n\n/** Modules only the backend's handle and init import from. */\nconst BACKEND_MODULES = [\n \"@velastack/pocketbase\",\n \"$env/dynamic/private\",\n \"$lib/server/workflows\",\n \"@sveltejs/kit\",\n \"@sveltejs/kit/hooks\",\n];\n\n/** `startWorker()`, `await startWorker()` or `return startWorker()`. */\nfunction isStartWorkerCall(node: Node | undefined): boolean {\n if (!node) return false;\n if (Node.isAwaitExpression(node))\n return isStartWorkerCall(node.getExpression());\n if (Node.isExpressionStatement(node) || Node.isReturnStatement(node)) {\n return isStartWorkerCall(node.getExpression());\n }\n return (\n Node.isCallExpression(node) &&\n node.getExpression().getText() === \"startWorker\" &&\n node.getArguments().length === 0\n );\n}\n\n/** A function whose whole body starts the worker. */\nfunction onlyStartsWorker(fn: Node | undefined): boolean {\n if (\n !Node.isArrowFunction(fn) &&\n !Node.isFunctionExpression(fn) &&\n !Node.isFunctionDeclaration(fn)\n ) {\n return false;\n }\n const body = fn.getBody();\n if (!body) return false;\n if (!Node.isBlock(body)) return isStartWorkerCall(body);\n const statements = body.getStatements();\n return statements.length === 1 && isStartWorkerCall(statements[0]);\n}\n\n/**\n * The `init` export when all it does is start the workflow worker, the way\n * the minimal template and enable-workflows write it. `\"custom\"` when an init\n * starts the worker among other things; null when there is nothing to do.\n */\nfunction workerInit(sf: SourceFile): Statement | \"custom\" | null {\n const fn = sf.getFunction(\"init\");\n const decl = sf.getVariableDeclaration(\"init\");\n const target = fn ?? decl?.getVariableStatement();\n if (!target || !target.getText().includes(\"startWorker\")) return null;\n const onlyWorker = fn\n ? onlyStartsWorker(fn)\n : decl?.getVariableStatement()?.getDeclarations().length === 1 &&\n onlyStartsWorker(decl.getInitializer());\n return onlyWorker ? target : \"custom\";\n}\n\n/**\n * Undo what the backend put in `hooks.server.ts`: the PocketBase handle, and\n * the `init` that starts the workflow worker, which is deleted along with the\n * backend. Whatever else the file holds (i18n, content negotiation) stays; a\n * file with nothing else comes out empty, for the caller to delete.\n */\nexport function unmodifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (\n !original.includes(\"handlePocketbase\") &&\n !original.includes(\"startWorker\")\n ) {\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 // Checked before anything changes, so a failure leaves the file as it was.\n if (workerInit(sourceFile) === \"custom\") {\n return { status: \"failed\", message: INIT_HINT };\n }\n\n const removed = removeHandle(sourceFile, \"handlePocketbase\");\n if (removed.status === \"unsupported\") {\n return { status: \"failed\", message: HANDLE_HINT };\n }\n // Looked up again: edits to the file forget the nodes found before them.\n const init = workerInit(sourceFile);\n if (init && init !== \"custom\") removeStatementWithComments(sourceFile, init);\n\n pruneUnusedImports(sourceFile, BACKEND_MODULES);\n sourceFile.formatText();\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = dedent`\n src/routes/+layout.server.ts still reads locals.meta, which only the\n PocketBase hook provides. Read the values from a static module instead:\n\n import { site } from '$lib/site';\n\n // locals.meta.appName -> site.name\n // locals.meta.appURL -> site.url\n // meta: locals.meta -> meta: { appName: site.name, appURL: site.url }\n`;\n\n/**\n * Point the root layout's meta at `$lib/site` instead of `locals.meta`. The\n * minimal template reads app name and URL off the PocketBase hook; without\n * the backend nothing sets them, and `App.Locals` no longer declares them.\n */\nexport function unmodifyLayoutServerMeta(\n layoutServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (!original.includes(\"locals.meta\")) {\n return { status: \"success\", changed: false };\n }\n\n let updated = original\n .replace(/\\blocals\\.meta\\.appName\\b/g, \"site.name\")\n .replace(/\\blocals\\.meta\\.appURL\\b/g, \"site.url\")\n .replace(\n /\\bmeta:\\s*locals\\.meta\\b/g,\n \"meta: { appName: site.name, appURL: site.url }\",\n );\n\n if (updated.includes(\"locals.meta\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n // `locals` usually only carried meta; drop it from the destructuring when\n // nothing else reads it.\n const withoutParam = updated\n .replace(/\\(\\{\\s*locals\\s*,\\s*/g, \"({ \")\n .replace(/,\\s*locals\\s*\\}/g, \" }\");\n if (!/\\blocals\\b/.test(withoutParam)) {\n updated = withoutParam;\n }\n\n if (!/from\\s+['\"]\\$lib\\/site['\"]/.test(updated)) {\n updated = \"import { site } from '$lib/site';\\n\" + updated;\n }\n\n fs.writeFileSync(layoutServerPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\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 { languageFromPath } from \"../../../core/util\";\nimport {\n modifyOutcomeToFile,\n revertOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { unmodifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { unmodifyLayoutServerMeta } from \"./modifies/layout-server\";\nimport { unmodifySvelteConfig } from \"../../enable/backend/modifies/svelte-config\";\nimport { unmodifyGitignore } from \"../../enable/backend/modifies/gitignore\";\nimport { unmodifyTestSetup } from \"../../enable/backend/modifies/test-setup\";\n\n/** `src/lib/site.ts` as the static template ships it, named after the package. */\nfunction siteModule(root: string): string {\n let name = \"My App\";\n try {\n const pkg = JSON.parse(\n fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"),\n ) as { name?: string };\n if (pkg.name) name = pkg.name;\n } catch {\n // No package.json to name the site after; the placeholder stands.\n }\n return [\n \"/**\",\n \" * Site-wide metadata.\",\n \" *\",\n \" * Without a backend there is nothing to read this from at runtime, so this\",\n \" * file is the source of truth. Set `url` to where the site is deployed:\",\n \" * canonical links and Open Graph image URLs are built from it.\",\n \" */\",\n \"export const site = {\",\n `\\tname: ${JSON.stringify(name)},`,\n \"\\turl: 'http://localhost:5173'\",\n \"};\",\n \"\",\n ].join(\"\\n\");\n}\n\n/** Every server test under a directory; they need the PocketBase test context. */\nfunction serverTestFiles(dir: string): string[] {\n if (!fs.existsSync(dir)) return [];\n const found: string[] = [];\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) found.push(...serverTestFiles(full));\n else if (entry.name === \"server.test.ts\") found.push(full);\n }\n return found;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n logger.info(\"Reverting adapter config\");\n const revert = unmodifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(revert.filePath, revert.outcome);\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // Only the backend's handle and worker come out; handles other patterns\n // composed in stay. The file goes when nothing else was in it.\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerRevert = revertOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerRevert.modify) modifies.push(hooksServerRevert.modify);\n if (hooksServerRevert.delete) deletes.push(hooksServerRevert.delete);\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n unmodifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n logger.info(\"Reverting src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n const layoutServerFile = modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServerMeta(layoutServerPath),\n );\n if (layoutServerFile) modifies.push(layoutServerFile);\n\n const sitePath = path.join(options.root, \"src\", \"lib\", \"site.ts\");\n if (layoutServerFile?.status === \"success\" && !fs.existsSync(sitePath)) {\n logger.info(\"Creating src/lib/site.ts\");\n creates.push({\n path: sitePath,\n language: languageFromPath(sitePath),\n content: siteModule(options.root),\n status: \"success\",\n });\n }\n\n // Server tests run against the PocketBase-backed test context that the\n // backend's test/setup.ts provides; without it they neither type-check nor\n // run.\n for (const testFile of serverTestFiles(path.join(options.root, \"src\"))) {\n logger.info(`Removing ${path.relative(options.root, testFile)}`);\n deletes.push(toDeleteEntry(testFile));\n }\n\n logger.info(\"Reverting test/setup.ts\");\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n unmodifyTestSetup(testSetupPath),\n );\n if (testSetupFile) modifies.push(testSetupFile);\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":";;;;;;;;;;;AAiBA,IAAM,IAAc,CAAM;;;GAKpB,IAAY,CAAM;;;;;GAQlB,IAAkB;CACtB;CACA;CACA;CACA;CACA;AACF;AAGA,SAAS,EAAkB,GAAiC;CAO1D,OANK,IACD,EAAK,kBAAkB,CAAI,KAE3B,EAAK,sBAAsB,CAAI,KAAK,EAAK,kBAAkB,CAAI,IAC1D,EAAkB,EAAK,cAAc,CAAC,IAG7C,EAAK,iBAAiB,CAAI,KAC1B,EAAK,cAAc,C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