@velastack/patterns 0.0.42 → 0.0.43
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-CsAmAg4q.js → _server-Cv3bTkG0.js} +1 -1
- package/dist/chunks/{_server-CsAmAg4q.js.map → _server-Cv3bTkG0.js.map} +1 -1
- package/dist/chunks/{collections-rD0M_Wxo.js → collections-VC2LOzBB.js} +2 -2
- package/dist/chunks/{collections-rD0M_Wxo.js.map → collections-VC2LOzBB.js.map} +1 -1
- package/dist/chunks/{env-CDsRI_A5.js → env-KcKcG4Mg.js} +1 -1
- package/dist/chunks/{env-CDsRI_A5.js.map → env-KcKcG4Mg.js.map} +1 -1
- package/dist/chunks/{env.preview-Ds0NigL8.js → env.preview-u7rnWI2E.js} +1 -1
- package/dist/chunks/{env.preview-Ds0NigL8.js.map → env.preview-u7rnWI2E.js.map} +1 -1
- package/dist/chunks/{env.runtime-BGmr1gQZ.js → env.runtime-N65jqPxq.js} +1 -1
- package/dist/chunks/{env.runtime-BGmr1gQZ.js.map → env.runtime-N65jqPxq.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BbZ5w6b_.js → generate.runtime-33rNLYvg.js} +5 -5
- package/dist/chunks/{generate.runtime-BbZ5w6b_.js.map → generate.runtime-33rNLYvg.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bcgms0O_.js → generate.runtime-AgF-_CuZ.js} +2 -2
- package/dist/chunks/{generate.runtime-Bcgms0O_.js.map → generate.runtime-AgF-_CuZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-PFOJ6hwY.js → generate.runtime-B07nsq-H.js} +4 -4
- package/dist/chunks/{generate.runtime-PFOJ6hwY.js.map → generate.runtime-B07nsq-H.js.map} +1 -1
- package/dist/chunks/generate.runtime-B2xOWBKK.js +148 -0
- package/dist/chunks/generate.runtime-B2xOWBKK.js.map +1 -0
- package/dist/chunks/{generate.runtime-C7g-fJTr.js → generate.runtime-B9YSOuDJ.js} +4 -4
- package/dist/chunks/{generate.runtime-C7g-fJTr.js.map → generate.runtime-B9YSOuDJ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-qlUWZTcR.js → generate.runtime-CZALdXt6.js} +2 -2
- package/dist/chunks/{generate.runtime-qlUWZTcR.js.map → generate.runtime-CZALdXt6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C4_8WPai.js → generate.runtime-CczM1Zuw.js} +6 -6
- package/dist/chunks/{generate.runtime-C4_8WPai.js.map → generate.runtime-CczM1Zuw.js.map} +1 -1
- package/dist/chunks/{generate.runtime-zHO95VHU.js → generate.runtime-CznAdWvM.js} +6 -6
- package/dist/chunks/{generate.runtime-zHO95VHU.js.map → generate.runtime-CznAdWvM.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BSlNFRop.js → generate.runtime-D5pHSGv2.js} +4 -4
- package/dist/chunks/{generate.runtime-BSlNFRop.js.map → generate.runtime-D5pHSGv2.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D24qi85n.js → generate.runtime-DWi7AATX.js} +5 -5
- package/dist/chunks/{generate.runtime-D24qi85n.js.map → generate.runtime-DWi7AATX.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CPVMJTKB.js → generate.runtime-DZbx8giO.js} +2 -2
- package/dist/chunks/{generate.runtime-CPVMJTKB.js.map → generate.runtime-DZbx8giO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C7ZDF3hy.js → generate.runtime-DrU9LGRv.js} +4 -4
- package/dist/chunks/{generate.runtime-C7ZDF3hy.js.map → generate.runtime-DrU9LGRv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BVPDsGmt.js → generate.runtime-DuAbZVdC.js} +3 -3
- package/dist/chunks/{generate.runtime-BVPDsGmt.js.map → generate.runtime-DuAbZVdC.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D_8Nz9Kl.js → generate.runtime-Dw6iUo_7.js} +3 -3
- package/dist/chunks/{generate.runtime-D_8Nz9Kl.js.map → generate.runtime-Dw6iUo_7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BPsBAuGR.js → generate.runtime-KJTobj9H.js} +4 -4
- package/dist/chunks/{generate.runtime-BPsBAuGR.js.map → generate.runtime-KJTobj9H.js.map} +1 -1
- package/dist/chunks/{generate.runtime-4WWju7dJ.js → generate.runtime-LKYA2LrJ.js} +3 -3
- package/dist/chunks/{generate.runtime-4WWju7dJ.js.map → generate.runtime-LKYA2LrJ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DHVmSY2L.js → generate.runtime-PK7amfVR.js} +5 -5
- package/dist/chunks/{generate.runtime-DHVmSY2L.js.map → generate.runtime-PK7amfVR.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D6C-brcS.js → generate.runtime-VhD6Bmgq.js} +3 -3
- package/dist/chunks/{generate.runtime-D6C-brcS.js.map → generate.runtime-VhD6Bmgq.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CTXSSehF.js → generate.runtime-wy4PDbqn.js} +4 -4
- package/dist/chunks/{generate.runtime-CTXSSehF.js.map → generate.runtime-wy4PDbqn.js.map} +1 -1
- package/dist/chunks/{modify-file-Bgo3_PuG.js → modify-file-DE7tPADZ.js} +1 -1
- package/dist/chunks/{modify-file-Bgo3_PuG.js.map → modify-file-DE7tPADZ.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-C-Wl2nk1.js → modify-svelte-config-remote-BUt0Wt_p.js} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-C-Wl2nk1.js.map → modify-svelte-config-remote-BUt0Wt_p.js.map} +1 -1
- package/dist/chunks/{nav-user-Jp5yYtw5.js → nav-user-_VheJA6n.js} +1 -1
- package/dist/chunks/{nav-user-Jp5yYtw5.js.map → nav-user-_VheJA6n.js.map} +1 -1
- package/dist/chunks/{pocketbase-D5p0NSdu.js → pocketbase-Bj-cW2Zl.js} +1 -1
- package/dist/chunks/{pocketbase-D5p0NSdu.js.map → pocketbase-Bj-cW2Zl.js.map} +1 -1
- package/dist/chunks/{pocketbase-CEhGbssT.js → pocketbase-CjSrDiqR.js} +1 -1
- package/dist/chunks/{pocketbase-CEhGbssT.js.map → pocketbase-CjSrDiqR.js.map} +1 -1
- package/dist/chunks/pocketbase-Dm2SF3vM.js +13 -0
- package/dist/chunks/pocketbase-Dm2SF3vM.js.map +1 -0
- package/dist/chunks/{shared-4hq3AXC3.js → shared-C55q8tz4.js} +2 -2
- package/dist/chunks/{shared-4hq3AXC3.js.map → shared-C55q8tz4.js.map} +1 -1
- package/dist/chunks/{ts-morph-helpers-DjpZhZ7I.js → ts-morph-helpers-bR0-x04t.js} +1 -1
- package/dist/chunks/{ts-morph-helpers-DjpZhZ7I.js.map → ts-morph-helpers-bR0-x04t.js.map} +1 -1
- package/dist/chunks/{write-result-BPDot58Z.js → write-result-ByDzyVll.js} +2 -2
- package/dist/chunks/{write-result-BPDot58Z.js.map → write-result-ByDzyVll.js.map} +1 -1
- package/dist/index.d.ts +90 -30
- package/dist/index.js +1514 -1354
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-AgF-_CuZ.js","names":[],"sources":["../../src/patterns/disable/i18n/modifies/gitignore.ts","../../src/patterns/disable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (!original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const lines = original.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i];\n if (line === \"# Wuchale\") {\n let j = i + 1;\n let hasWuchale = false;\n while (j < lines.length && lines[j].trim() !== \"\") {\n if (lines[j] === \"src/locales/.wuchale\") {\n hasWuchale = true;\n }\n j++;\n }\n if (hasWuchale) {\n i = j;\n continue;\n }\n }\n if (line === \"src/locales/.wuchale\") continue;\n out.push(line);\n }\n\n let updated = out.join(\"\\n\");\n updated = updated.replace(/\\n{3,}/g, \"\\n\\n\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyGitignore } from \"./modifies/gitignore\";\n\nconst MANUAL_REMEDIATION = [\n \"vite.config, svelte.config, hooks.server, app.html, and +layout.ts must be reverted manually.\",\n \"The i18n integration touches these files in ways that are not safely reversible by tooling.\",\n \"See the enable-i18n modifies for the blocks to remove.\",\n].join(\" \");\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, unmodifyGitignore(gitignorePath)),\n );\n\n logger.info(MANUAL_REMEDIATION);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;AAGA,SAAgB,EAAkB,GAAsC;AACtE,KAAI,CAAC,EAAG,WAAW,EAAc,CAC/B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAW,EAAG,aAAa,GAAe,OAAO;AACvD,KAAI,CAAC,EAAS,SAAS,uBAAuB,CAC5C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAQ,EAAS,MAAM,KAAK,EAC5B,IAAgB,EAAE;AACxB,MAAK,IAAI,IAAI,GAAG,IAAI,EAAM,QAAQ,KAAK;EACrC,IAAM,IAAO,EAAM;AACnB,MAAI,MAAS,aAAa;GACxB,IAAI,IAAI,IAAI,GACR,IAAa;AACjB,UAAO,IAAI,EAAM,UAAU,EAAM,GAAG,MAAM,KAAK,IAI7C,CAHI,EAAM,OAAO,2BACf,IAAa,KAEf;AAEF,OAAI,GAAY;AACd,QAAI;AACJ;;;AAGA,QAAS,0BACb,EAAI,KAAK,EAAK;;CAGhB,IAAI,IAAU,EAAI,KAAK,KAAK;AAQ5B,QAPA,IAAU,EAAQ,QAAQ,WAAW,OAAO,EAExC,MAAY,IACP;EAAE,QAAQ;EAAW,SAAS;EAAO,IAG9C,EAAG,cAAc,GAAe,EAAQ,EACjC;EAAE,QAAQ;EAAW,SAAS;EAAM;;;;ACrC7C,IAAM,IAAqB;CACzB;CACA;CACA;CACD,CAAC,KAAK,IAAI;AAEX,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,EAAQ,EAC3B,IAAmB,EAAE,EACrB,KAAc,MAAsB;AACxC,EAAI,KAAM,EAAS,KAAK,EAAK;;AAG/B,GAAO,KAAK,uBAAuB;CACnC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,aAAa;AAO3D,QANA,EACE,EAAoB,GAAe,EAAkB,EAAc,CAAC,CACrE,EAED,EAAO,KAAK,EAAmB,EAExB;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-BpgCb-ZG.js";
|
|
2
|
-
import { t } from "./shared-
|
|
3
|
-
import { modifyOutcomeToFile as n } from "./modify-file-
|
|
4
|
-
import { i as r, o as i } from "./ts-morph-helpers-
|
|
2
|
+
import { t } from "./shared-C55q8tz4.js";
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-DE7tPADZ.js";
|
|
4
|
+
import { i as r, o as i } from "./ts-morph-helpers-bR0-x04t.js";
|
|
5
5
|
import a from "node:fs";
|
|
6
6
|
import o from "node:path";
|
|
7
7
|
//#region src/patterns/disable/teams/modifies/modify-nav-user.ts
|
|
@@ -57,4 +57,4 @@ async function l(r) {
|
|
|
57
57
|
//#endregion
|
|
58
58
|
export { l as generate };
|
|
59
59
|
|
|
60
|
-
//# sourceMappingURL=generate.runtime-
|
|
60
|
+
//# sourceMappingURL=generate.runtime-B07nsq-H.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-B07nsq-H.js","names":[],"sources":["../../src/patterns/disable/teams/modifies/modify-nav-user.ts","../../src/patterns/disable/teams/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/teams\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Teams\",\n \"@lucide/svelte/icons/users\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nconst MANUAL_REMEDIATION = [\n \"app-sidebar, +layout.server.ts (teams loader), and app-layout.svelte (AppSidebar team props) must be reverted manually.\",\n \"These edits are substantial and are not safely reversed by tooling.\",\n].join(\" \");\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserCandidates = [\n path.join(options.root, \"src\", \"lib\", \"components\", \"nav-user.svelte\"),\n ];\n const navUserPath =\n navUserCandidates.find((p) => fs.existsSync(p)) ?? navUserCandidates[0];\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(MANUAL_REMEDIATION);\n\n const collectionDrops = await planDropsForCollections(\n [\"team_invite_links\", \"team_invites\", \"team_memberships\", \"teams\"],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,EAAgB,GAAoC;AAClE,KAAI,CAAC,EAAG,WAAW,EAAY,CAC7B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAS,EAAG,aAAa,GAAa,OAAO;AACnD,KAAI,CAAC,EAAO,SAAS,SAAS,CAC5B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAO,IAAI,EAAW,EAAO,EAC/B,IAAa,IAEX,KAAa,MAAgD;AAC7D,OACJ,GAAK,MAAQ;GACX,IAAM,IAAS,EACb,GACA,SACA,6BACD;AAED,UADI,EAAO,eAAY,IAAa,KAC7B,EAAO;IACd;;AAWJ,QARA,GAAW,MAAO,EAAK,mBAAmB,EAAG,CAAC,EACzC,KAAY,GAAW,MAAO,EAAK,aAAa,EAAG,CAAC,EAEpD,KAIL,EAAG,cAAc,GAAa,EAAK,UAAU,EAAE,OAAO,EAC/C;EAAE,QAAQ;EAAW,SAAS;EAAM,IAJlC;EAAE,QAAQ;EAAW,SAAS;EAAO;;;;AC3BhD,IAAM,IAAqB,CACzB,2HACA,sEACD,CAAC,KAAK,IAAI;AAEX,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,EAAQ,EAC3B,IAAmB,EAAE,EACrB,KAAc,MAAsB;AACxC,EAAI,KAAM,EAAS,KAAK,EAAK;;AAG/B,GAAO,KAAK,4BAA4B;CACxC,IAAM,IAAoB,CACxB,EAAK,KAAK,EAAQ,MAAM,OAAO,OAAO,cAAc,kBAAkB,CACvE,EACK,IACJ,EAAkB,MAAM,MAAM,EAAG,WAAW,EAAE,CAAC,IAAI,EAAkB;AAUvE,QATA,EAAW,EAAoB,GAAa,EAAgB,EAAY,CAAC,CAAC,EAE1E,EAAO,KAAK,EAAmB,EAOxB;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAbsB,MAAM,EAC5B;GAAC;GAAqB;GAAgB;GAAoB;GAAQ,EAClE,EACD;EAWA"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
|
+
import { i as t } from "./util-BNtpm1tP.js";
|
|
3
|
+
import { n } from "./logger-BpgCb-ZG.js";
|
|
4
|
+
import { t as r } from "./pocketbase-Dm2SF3vM.js";
|
|
5
|
+
import { modifyOutcomeToFile as i } from "./modify-file-DE7tPADZ.js";
|
|
6
|
+
import { a, n as o, o as s } from "./ts-morph-helpers-bR0-x04t.js";
|
|
7
|
+
import { getMigrationFile as c, migrationDelay as l, withPocketbase as u } from "./pocketbase-CjSrDiqR.js";
|
|
8
|
+
import { applyCollectionRulePatches as d, createCollectionIdempotent as f } from "./collections-VC2LOzBB.js";
|
|
9
|
+
import p from "node:fs";
|
|
10
|
+
import m from "node:path";
|
|
11
|
+
//#region src/patterns/enable/notifications/modifies/modify-app-layout.ts
|
|
12
|
+
var h = "\n <div class=\"ml-auto px-4\">\n <NotificationsBell />\n </div>\n ", g = e`
|
|
13
|
+
import NotificationsBell from '$lib/components/notifications-bell.svelte';
|
|
14
|
+
`, _ = [
|
|
15
|
+
"Add the notifications bell inside the (app) layout's <header>.",
|
|
16
|
+
"",
|
|
17
|
+
"Imports to add to the <script> tag:",
|
|
18
|
+
"",
|
|
19
|
+
g,
|
|
20
|
+
"",
|
|
21
|
+
"Markup to add inside <header>:",
|
|
22
|
+
h
|
|
23
|
+
].join("\n"), v = [
|
|
24
|
+
"Create src/routes/(app)/+layout.svelte with a <header> that includes the bell.",
|
|
25
|
+
"",
|
|
26
|
+
"Imports for the <script> tag:",
|
|
27
|
+
"",
|
|
28
|
+
g,
|
|
29
|
+
"",
|
|
30
|
+
"Markup inside <header>:",
|
|
31
|
+
h
|
|
32
|
+
].join("\n");
|
|
33
|
+
function y(e) {
|
|
34
|
+
if (!p.existsSync(e)) return {
|
|
35
|
+
status: "not-found",
|
|
36
|
+
message: v
|
|
37
|
+
};
|
|
38
|
+
let t = s.fromPath(e);
|
|
39
|
+
return t.hasElement("header") ? t.hasElement("NotificationsBell") ? {
|
|
40
|
+
status: "success",
|
|
41
|
+
changed: !1
|
|
42
|
+
} : (t.modifyScript((e) => {
|
|
43
|
+
let { source: t } = a(e, (e) => {
|
|
44
|
+
o(e, [{
|
|
45
|
+
defaultImport: "NotificationsBell",
|
|
46
|
+
moduleSpecifier: "$lib/components/notifications-bell.svelte"
|
|
47
|
+
}]);
|
|
48
|
+
});
|
|
49
|
+
return t;
|
|
50
|
+
}), t.insertBeforeClosingTag("header", h), t.writeTo(e), {
|
|
51
|
+
status: "success",
|
|
52
|
+
changed: t.hasChanged()
|
|
53
|
+
}) : {
|
|
54
|
+
status: "failed",
|
|
55
|
+
message: _
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/patterns/enable/notifications/generate.runtime.ts
|
|
60
|
+
async function b(e, n, r, i = !0) {
|
|
61
|
+
if (!i) return;
|
|
62
|
+
await l();
|
|
63
|
+
let a = c(n, "created", r);
|
|
64
|
+
a && e.push({
|
|
65
|
+
path: a,
|
|
66
|
+
language: t(a),
|
|
67
|
+
content: p.readFileSync(a, "utf8"),
|
|
68
|
+
status: "success"
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async function x(e) {
|
|
72
|
+
let t = n(e), a = [];
|
|
73
|
+
await u(e.root, async (n) => {
|
|
74
|
+
let i = await n.collections.getOne("users");
|
|
75
|
+
t.info("Creating notifications collection"), await b(a, "notifications", e, (await ((e) => f(n, e, t))({
|
|
76
|
+
name: "notifications",
|
|
77
|
+
type: "base",
|
|
78
|
+
fields: [
|
|
79
|
+
{
|
|
80
|
+
name: "id",
|
|
81
|
+
type: "text",
|
|
82
|
+
primaryKey: !0,
|
|
83
|
+
autogeneratePattern: "[a-z0-9]{15}",
|
|
84
|
+
max: 15,
|
|
85
|
+
min: 15,
|
|
86
|
+
pattern: "^[a-z0-9]+$",
|
|
87
|
+
required: !0
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "user",
|
|
91
|
+
type: "relation",
|
|
92
|
+
cascadeDelete: !0,
|
|
93
|
+
collectionId: i.id,
|
|
94
|
+
maxSelect: 1,
|
|
95
|
+
minSelect: 0,
|
|
96
|
+
required: !0
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "title",
|
|
100
|
+
type: "text",
|
|
101
|
+
required: !0
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "body",
|
|
105
|
+
type: "text"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "read",
|
|
109
|
+
type: "bool"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "created",
|
|
113
|
+
type: "autodate",
|
|
114
|
+
onCreate: !0,
|
|
115
|
+
onUpdate: !1
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "updated",
|
|
119
|
+
type: "autodate",
|
|
120
|
+
onCreate: !0,
|
|
121
|
+
onUpdate: !0
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
indexes: ["CREATE INDEX `idx_notifications_user_read_created` ON `notifications` (`user`, `read`, `created` DESC)"]
|
|
125
|
+
})).created), t.info("Applying notifications rule patches");
|
|
126
|
+
let o = await d(n, r, e, t);
|
|
127
|
+
a.push(...o);
|
|
128
|
+
});
|
|
129
|
+
let o = [], s = (e) => {
|
|
130
|
+
e && o.push(e);
|
|
131
|
+
};
|
|
132
|
+
t.info("Modifying (app) +layout.svelte");
|
|
133
|
+
let c = m.join(e.root, "src", "routes", "(app)", "+layout.svelte");
|
|
134
|
+
return s(i(c, y(c))), {
|
|
135
|
+
creates: a,
|
|
136
|
+
modifies: o,
|
|
137
|
+
deletes: [],
|
|
138
|
+
components: [],
|
|
139
|
+
packages: [],
|
|
140
|
+
collections: [],
|
|
141
|
+
collectionPatches: [],
|
|
142
|
+
collectionDrops: []
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { x as generate };
|
|
147
|
+
|
|
148
|
+
//# sourceMappingURL=generate.runtime-B2xOWBKK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-B2xOWBKK.js","names":[],"sources":["../../src/patterns/enable/notifications/modifies/modify-app-layout.ts","../../src/patterns/enable/notifications/generate.runtime.ts"],"sourcesContent":["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 BELL_SNIPPET = `\n\t\t<div class=\"ml-auto px-4\">\n\t\t\t<NotificationsBell />\n\t\t</div>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import NotificationsBell from '$lib/components/notifications-bell.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the notifications bell inside the (app) layout's <header>.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <header>:\",\n BELL_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.svelte with a <header> that includes the bell.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <header>:\",\n BELL_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyAppLayout(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"header\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"NotificationsBell\")) {\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: \"NotificationsBell\",\n moduleSpecifier: \"$lib/components/notifications-bell.svelte\",\n },\n ]);\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"header\", BELL_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 { languageFromPath } from \"../../../core/util\";\nimport {\n applyCollectionRulePatches,\n createCollectionIdempotent,\n} from \"../../../runtime/collections\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyAppLayout } from \"./modifies/modify-app-layout\";\nimport { NOTIFICATION_RULE_PATCHES } from \"./runtime/pocketbase\";\n\nasync function pushMigrationCreates(\n creates: File[],\n collectionName: string,\n options: Options,\n created = true,\n) {\n if (!created) return;\n await migrationDelay();\n const migrationFile = getMigrationFile(collectionName, \"created\", options);\n if (!migrationFile) return;\n creates.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n const userCollection = await pb.collections.getOne(\"users\");\n const create = (spec: Parameters<typeof createCollectionIdempotent>[1]) =>\n createCollectionIdempotent(pb, spec, logger);\n\n logger.info(\"Creating notifications collection\");\n const result = await create({\n name: \"notifications\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n type: \"text\",\n primaryKey: true,\n autogeneratePattern: \"[a-z0-9]{15}\",\n max: 15,\n min: 15,\n pattern: \"^[a-z0-9]+$\",\n required: true,\n },\n {\n name: \"user\",\n type: \"relation\",\n cascadeDelete: true,\n collectionId: userCollection.id,\n maxSelect: 1,\n minSelect: 0,\n required: true,\n },\n {\n name: \"title\",\n type: \"text\",\n required: true,\n },\n {\n name: \"body\",\n type: \"text\",\n },\n {\n name: \"read\",\n type: \"bool\",\n },\n {\n name: \"created\",\n type: \"autodate\",\n onCreate: true,\n onUpdate: false,\n },\n {\n name: \"updated\",\n type: \"autodate\",\n onCreate: true,\n onUpdate: true,\n },\n ],\n indexes: [\n \"CREATE INDEX `idx_notifications_user_read_created` ON `notifications` (`user`, `read`, `created` DESC)\",\n ],\n });\n await pushMigrationCreates(\n creates,\n \"notifications\",\n options,\n result.created,\n );\n\n logger.info(\"Applying notifications rule patches\");\n const ruleMigrations = await applyCollectionRulePatches(\n pb,\n NOTIFICATION_RULE_PATCHES,\n options,\n logger,\n );\n creates.push(...ruleMigrations);\n });\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, modifyAppLayout(appLayoutPath)),\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,2EAMf,IAAiB,CAAM;;GAIvB,IAAe;CACnB;CACA;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,EAAgB,GAAmC;AACjE,KAAI,CAAC,EAAG,WAAW,EAAW,CAC5B,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAGzD,IAAM,IAAO,EAAW,SAAS,EAAW;AAsB5C,QArBK,EAAK,WAAW,SAAS,GAG1B,EAAK,WAAW,oBAAoB,GAC/B;EAAE,QAAQ;EAAW,SAAS;EAAO,IAG9C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQ,MAAQ,EAAmB,IAAS,MAAO;AACzD,KAAc,GAAI,CAChB;IACE,eAAe;IACf,iBAAiB;IAClB,CACF,CAAC;IACF;AACF,SAAO;GACP,EAEF,EAAK,uBAAuB,UAAU,EAAa,EACnD,EAAK,QAAQ,EAAW,EACjB;EAAE,QAAQ;EAAW,SAAS,EAAK,YAAY;EAAE,IApB/C;EAAE,QAAQ;EAAU,SAAS;EAAc;;;;AC9BtD,eAAe,EACb,GACA,GACA,GACA,IAAU,IACV;AACA,KAAI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K,KACzB,EAAQ,MACR,OACA,UACA,SACA,iBACD;AAKD,QAJA,EACE,EAAoB,GAAe,EAAgB,EAAc,CAAC,CACnE,EAEM;EACL;EACA;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as e } from "./dedent-C4qKBQXh.js";
|
|
2
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-
|
|
4
|
-
import { modifyOutcomeToFile as u } from "./modify-file-
|
|
5
|
-
import { a as d, n as f, o as p } from "./ts-morph-helpers-
|
|
3
|
+
import { a as n, c as r, i, n as a, o, r as s, s as c, t as l } from "./_server-Cv3bTkG0.js";
|
|
4
|
+
import { modifyOutcomeToFile as u } from "./modify-file-DE7tPADZ.js";
|
|
5
|
+
import { a as d, n as f, o as p } from "./ts-morph-helpers-bR0-x04t.js";
|
|
6
6
|
import m from "node:fs";
|
|
7
7
|
import h from "node:path";
|
|
8
8
|
import { SyntaxKind as g } from "ts-morph";
|
|
@@ -306,4 +306,4 @@ async function W(e) {
|
|
|
306
306
|
//#endregion
|
|
307
307
|
export { W as generate };
|
|
308
308
|
|
|
309
|
-
//# sourceMappingURL=generate.runtime-
|
|
309
|
+
//# sourceMappingURL=generate.runtime-B9YSOuDJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-C7g-fJTr.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(\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 { 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,KAAI,EAAQ,SAAS,uBAAuB,CAC1C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;AAE9C,KAAI,CAAC,EAAQ,SAAS,WAAW,CAC/B,QAAO;EAAE,QAAQ;EAAU,SAAS;EAAc;CAGpD,IAAM,IAAO,GAAG,IADC,EAAQ,SAAS,KAAK,GAAG,KAAK,KACZ,IAAI,EAAa;AAEpD,QADA,EAAG,cAAc,GAAU,GAAM,OAAO,EACjC;EAAE,QAAQ;EAAW,SAAS;EAAM;;;;AC9B7C,IAAM,IAAe,CAAM;;;;;;;;;;;;;;;;;;GAoBrB,IACJ,gGAEI,IAA6B,CAAM;;;;;;;;;;;;;AAczC,SAAgB,EAAoB,GAAiC;AACnE,KAAI,CAAC,EAAG,WAAW,EAAS,CAC1B,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAGzD,IAAM,IAAW,EAAG,aAAa,GAAU,OAAO;AAClD,KAAI,EAAS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X,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAA;EAClB"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-B9YSOuDJ.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(\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 { 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,KAAI,EAAQ,SAAS,uBAAuB,CAC1C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;AAE9C,KAAI,CAAC,EAAQ,SAAS,WAAW,CAC/B,QAAO;EAAE,QAAQ;EAAU,SAAS;EAAc;CAGpD,IAAM,IAAO,GAAG,IADC,EAAQ,SAAS,KA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AC/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,5 +1,5 @@
|
|
|
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-DE7tPADZ.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-CZALdXt6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-CZALdXt6.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;EA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m1tP.js";
|
|
3
3
|
import { t as n } from "./taggedTemplateLiteral-Bfbldyfk.js";
|
|
4
4
|
import { n as r } from "./logger-BpgCb-ZG.js";
|
|
5
|
-
import { modifyOutcomeToFile as i } from "./modify-file-
|
|
6
|
-
import { o as a, t as o } from "./ts-morph-helpers-
|
|
7
|
-
import { t as s } from "./env-
|
|
8
|
-
import { getMigrationFile as c, migrationDelay as l, withPocketbase as u } from "./pocketbase-
|
|
9
|
-
import { createCollectionIdempotent as d } from "./collections-
|
|
5
|
+
import { modifyOutcomeToFile as i } from "./modify-file-DE7tPADZ.js";
|
|
6
|
+
import { o as a, t as o } from "./ts-morph-helpers-bR0-x04t.js";
|
|
7
|
+
import { t as s } from "./env-KcKcG4Mg.js";
|
|
8
|
+
import { getMigrationFile as c, migrationDelay as l, withPocketbase as u } from "./pocketbase-CjSrDiqR.js";
|
|
9
|
+
import { createCollectionIdempotent as d } from "./collections-VC2LOzBB.js";
|
|
10
10
|
import f from "node:fs";
|
|
11
11
|
import p from "node:path";
|
|
12
12
|
import { Project as m, QuoteKind as h, SyntaxKind as g } from "ts-morph";
|
|
@@ -656,4 +656,4 @@ async function P(e) {
|
|
|
656
656
|
//#endregion
|
|
657
657
|
export { P as generate };
|
|
658
658
|
|
|
659
|
-
//# sourceMappingURL=generate.runtime-
|
|
659
|
+
//# sourceMappingURL=generate.runtime-CczM1Zuw.js.map
|