@velastack/patterns 0.3.0 → 0.3.2
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/README.md +32 -2
- package/dist/chunks/_layout-B7ujvjnA.js +55 -0
- package/dist/chunks/_layout-B7ujvjnA.js.map +1 -0
- package/dist/chunks/{collections-CgdvZXmh.js → collections-UPqYto13.js} +2 -2
- package/dist/chunks/{collections-CgdvZXmh.js.map → collections-UPqYto13.js.map} +1 -1
- package/dist/chunks/{compose-handle-Cg9jnCsS.js → compose-handle-B-CkDcQD.js} +23 -23
- package/dist/chunks/{compose-handle-Cg9jnCsS.js.map → compose-handle-B-CkDcQD.js.map} +1 -1
- package/dist/chunks/config-target-Bln26FJe.js +164 -0
- package/dist/chunks/config-target-Bln26FJe.js.map +1 -0
- package/dist/chunks/errors-DR3gF_7a.js +18 -0
- package/dist/chunks/errors-DR3gF_7a.js.map +1 -0
- package/dist/chunks/{generate-DRA63W0r.js → generate-6snrlnpA.js} +2 -2
- package/dist/chunks/{generate-DRA63W0r.js.map → generate-6snrlnpA.js.map} +1 -1
- package/dist/chunks/{generate-BkQ1xMDp.js → generate-C6xi5S5L.js} +4 -4
- package/dist/chunks/{generate-BkQ1xMDp.js.map → generate-C6xi5S5L.js.map} +1 -1
- package/dist/chunks/{generate-tOkjJFUf.js → generate-CyuY2Ci7.js} +4 -3
- package/dist/chunks/generate-CyuY2Ci7.js.map +1 -0
- package/dist/chunks/{generate-iQP31-m1.js → generate-DHgKgHb7.js} +4 -4
- package/dist/chunks/{generate-iQP31-m1.js.map → generate-DHgKgHb7.js.map} +1 -1
- package/dist/chunks/{generate-_LvrYK6i.js → generate-jsB_oO0b.js} +4 -4
- package/dist/chunks/{generate-_LvrYK6i.js.map → generate-jsB_oO0b.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DAmYsIvF.js → generate.runtime-9R2AUKLS.js} +5 -5
- package/dist/chunks/{generate.runtime-DAmYsIvF.js.map → generate.runtime-9R2AUKLS.js.map} +1 -1
- package/dist/chunks/generate.runtime-B3yX6kl2.js +87 -0
- package/dist/chunks/generate.runtime-B3yX6kl2.js.map +1 -0
- package/dist/chunks/{generate.runtime-BKo-Nidn.js → generate.runtime-B7wkyj-8.js} +6 -6
- package/dist/chunks/{generate.runtime-BKo-Nidn.js.map → generate.runtime-B7wkyj-8.js.map} +1 -1
- package/dist/chunks/generate.runtime-BHf8p_3K.js +94 -0
- package/dist/chunks/generate.runtime-BHf8p_3K.js.map +1 -0
- package/dist/chunks/{generate.runtime-BbIN0tUZ.js → generate.runtime-BSFIwX58.js} +67 -66
- package/dist/chunks/generate.runtime-BSFIwX58.js.map +1 -0
- package/dist/chunks/{generate.runtime-BnWE4qsu.js → generate.runtime-Bb9CCwQm.js} +55 -54
- package/dist/chunks/generate.runtime-Bb9CCwQm.js.map +1 -0
- package/dist/chunks/{generate.runtime-D8vgh5MH.js → generate.runtime-BjciAjq7.js} +156 -76
- package/dist/chunks/generate.runtime-BjciAjq7.js.map +1 -0
- package/dist/chunks/{generate.runtime-BwhGDnGu.js → generate.runtime-BpTpRBdH.js} +151 -150
- package/dist/chunks/generate.runtime-BpTpRBdH.js.map +1 -0
- package/dist/chunks/{generate.runtime-D0icLb5j.js → generate.runtime-Brf08fMW.js} +11 -10
- package/dist/chunks/{generate.runtime-D0icLb5j.js.map → generate.runtime-Brf08fMW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-S5RIgbQx.js → generate.runtime-C6DfW_NO.js} +98 -92
- package/dist/chunks/generate.runtime-C6DfW_NO.js.map +1 -0
- package/dist/chunks/{generate.runtime-DhkaXTq3.js → generate.runtime-C9fSqy6a.js} +61 -59
- package/dist/chunks/generate.runtime-C9fSqy6a.js.map +1 -0
- package/dist/chunks/{generate.runtime-CRYjWJRe.js → generate.runtime-CawvLUoV.js} +89 -88
- package/dist/chunks/generate.runtime-CawvLUoV.js.map +1 -0
- package/dist/chunks/{generate.runtime-DNaQxed-.js → generate.runtime-CzS7PuPN.js} +84 -83
- package/dist/chunks/generate.runtime-CzS7PuPN.js.map +1 -0
- package/dist/chunks/{generate.runtime-B0hhtyAL.js → generate.runtime-D1NZPV6C.js} +27 -26
- package/dist/chunks/generate.runtime-D1NZPV6C.js.map +1 -0
- package/dist/chunks/generate.runtime-D3baqo6a.js +111 -0
- package/dist/chunks/generate.runtime-D3baqo6a.js.map +1 -0
- package/dist/chunks/{generate.runtime-DSqkXvps.js → generate.runtime-D47djbeG.js} +15 -14
- package/dist/chunks/{generate.runtime-DSqkXvps.js.map → generate.runtime-D47djbeG.js.map} +1 -1
- package/dist/chunks/generate.runtime-D72UBiwD.js +313 -0
- package/dist/chunks/generate.runtime-D72UBiwD.js.map +1 -0
- package/dist/chunks/{generate.runtime-CcuAXuV2.js → generate.runtime-DDPoXmqN.js} +15 -14
- package/dist/chunks/{generate.runtime-CcuAXuV2.js.map → generate.runtime-DDPoXmqN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-acRmiU7e.js → generate.runtime-DEnn0HKw.js} +9 -8
- package/dist/chunks/{generate.runtime-acRmiU7e.js.map → generate.runtime-DEnn0HKw.js.map} +1 -1
- package/dist/chunks/{generate.runtime-wA1G3tQ4.js → generate.runtime-DHXkw2gf.js} +38 -37
- package/dist/chunks/generate.runtime-DHXkw2gf.js.map +1 -0
- package/dist/chunks/{generate.runtime-DOuufRLr.js → generate.runtime-DIuCrH6l.js} +82 -81
- package/dist/chunks/generate.runtime-DIuCrH6l.js.map +1 -0
- package/dist/chunks/generate.runtime-DOB4U-Sa.js +57 -0
- package/dist/chunks/generate.runtime-DOB4U-Sa.js.map +1 -0
- package/dist/chunks/generate.runtime-DPAy7Cav.js +328 -0
- package/dist/chunks/generate.runtime-DPAy7Cav.js.map +1 -0
- package/dist/chunks/{generate.runtime-BORbegw_.js → generate.runtime-D_ZqiYt-.js} +123 -122
- package/dist/chunks/generate.runtime-D_ZqiYt-.js.map +1 -0
- package/dist/chunks/{generate.runtime-B49wetSx.js → generate.runtime-Dm7g_WTN.js} +43 -42
- package/dist/chunks/generate.runtime-Dm7g_WTN.js.map +1 -0
- package/dist/chunks/{generate.runtime-DoZdSh9W.js → generate.runtime-HE9rzfXz.js} +58 -57
- package/dist/chunks/generate.runtime-HE9rzfXz.js.map +1 -0
- package/dist/chunks/{generate.runtime-flFRYzpi.js → generate.runtime-ejrt1o6M.js} +62 -61
- package/dist/chunks/generate.runtime-ejrt1o6M.js.map +1 -0
- package/dist/chunks/generate.runtime-l6I-St2R.js +94 -0
- package/dist/chunks/generate.runtime-l6I-St2R.js.map +1 -0
- package/dist/chunks/modify-file-DGe7MJu_.js +46 -0
- package/dist/chunks/modify-file-DGe7MJu_.js.map +1 -0
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js → modify-svelte-config-remote-BUU_EaDf.js} +2 -2
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js.map → modify-svelte-config-remote-BUU_EaDf.js.map} +1 -1
- package/dist/chunks/{providers-DO9kMyzB.js → providers-BL9vJP_9.js} +2 -2
- package/dist/chunks/{providers-DO9kMyzB.js.map → providers-BL9vJP_9.js.map} +1 -1
- package/dist/chunks/{shared-BwHQM-a9.js → shared-DkGfltvn.js} +2 -2
- package/dist/chunks/{shared-BwHQM-a9.js.map → shared-DkGfltvn.js.map} +1 -1
- package/dist/chunks/{test-setup-B2hd8I-s.js → test-setup-DHEFKEHE.js} +23 -10
- package/dist/chunks/test-setup-DHEFKEHE.js.map +1 -0
- package/dist/chunks/ts-morph-helpers-CeduA--o.js +253 -0
- package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +1 -0
- package/dist/chunks/{ui-B4Tuit-7.js → ui-B3-B3sE2.js} +3 -3
- package/dist/chunks/{ui-B4Tuit-7.js.map → ui-B3-B3sE2.js.map} +1 -1
- package/dist/chunks/{ui-jhXrsw4T.js → ui-DD4NltyN.js} +2 -2
- package/dist/chunks/{ui-jhXrsw4T.js.map → ui-DD4NltyN.js.map} +1 -1
- package/dist/chunks/unmodify-load-jfdcVZ_a.js +81 -0
- package/dist/chunks/unmodify-load-jfdcVZ_a.js.map +1 -0
- package/dist/chunks/write-result-DRwceOV3.js +452 -0
- package/dist/chunks/write-result-DRwceOV3.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1920 -1903
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/_layout-DqH4lA_r.js +0 -47
- package/dist/chunks/_layout-DqH4lA_r.js.map +0 -1
- package/dist/chunks/config-target-Co-ij8p3.js +0 -163
- package/dist/chunks/config-target-Co-ij8p3.js.map +0 -1
- package/dist/chunks/errors-D6gyegUK.js +0 -14
- package/dist/chunks/errors-D6gyegUK.js.map +0 -1
- package/dist/chunks/generate-tOkjJFUf.js.map +0 -1
- package/dist/chunks/generate.runtime-B0hhtyAL.js.map +0 -1
- package/dist/chunks/generate.runtime-B49wetSx.js.map +0 -1
- package/dist/chunks/generate.runtime-B7LRx-BU.js +0 -86
- package/dist/chunks/generate.runtime-B7LRx-BU.js.map +0 -1
- package/dist/chunks/generate.runtime-BORbegw_.js.map +0 -1
- package/dist/chunks/generate.runtime-BbIN0tUZ.js.map +0 -1
- package/dist/chunks/generate.runtime-BnWE4qsu.js.map +0 -1
- package/dist/chunks/generate.runtime-BwhGDnGu.js.map +0 -1
- package/dist/chunks/generate.runtime-CCg2Pjcv.js +0 -257
- package/dist/chunks/generate.runtime-CCg2Pjcv.js.map +0 -1
- package/dist/chunks/generate.runtime-CRYjWJRe.js.map +0 -1
- package/dist/chunks/generate.runtime-D2e_KRj0.js +0 -56
- package/dist/chunks/generate.runtime-D2e_KRj0.js.map +0 -1
- package/dist/chunks/generate.runtime-D44gjxRA.js +0 -332
- package/dist/chunks/generate.runtime-D44gjxRA.js.map +0 -1
- package/dist/chunks/generate.runtime-D8vgh5MH.js.map +0 -1
- package/dist/chunks/generate.runtime-DNaQxed-.js.map +0 -1
- package/dist/chunks/generate.runtime-DOuufRLr.js.map +0 -1
- package/dist/chunks/generate.runtime-DhkaXTq3.js.map +0 -1
- package/dist/chunks/generate.runtime-DoZdSh9W.js.map +0 -1
- package/dist/chunks/generate.runtime-S5RIgbQx.js.map +0 -1
- package/dist/chunks/generate.runtime-WmSMWL15.js +0 -82
- package/dist/chunks/generate.runtime-WmSMWL15.js.map +0 -1
- package/dist/chunks/generate.runtime-flFRYzpi.js.map +0 -1
- package/dist/chunks/generate.runtime-gtpOuLNO.js +0 -110
- package/dist/chunks/generate.runtime-gtpOuLNO.js.map +0 -1
- package/dist/chunks/generate.runtime-kLxeDGnS.js +0 -93
- package/dist/chunks/generate.runtime-kLxeDGnS.js.map +0 -1
- package/dist/chunks/generate.runtime-wA1G3tQ4.js.map +0 -1
- package/dist/chunks/modify-file-GQD6uNgI.js +0 -254
- package/dist/chunks/modify-file-GQD6uNgI.js.map +0 -1
- package/dist/chunks/test-setup-B2hd8I-s.js.map +0 -1
- package/dist/chunks/unmodify-load-W1ePZQHr.js +0 -80
- package/dist/chunks/unmodify-load-W1ePZQHr.js.map +0 -1
- package/dist/chunks/write-result-DewHCNhM.js +0 -451
- package/dist/chunks/write-result-DewHCNhM.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-DEnn0HKw.js","names":[],"sources":["../../src/patterns/enable/analytics/modifies/layout.svelte.ts","../../src/patterns/enable/analytics/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 MODULE_SPECIFIER = \"$lib/components/analytics/analytics.svelte\";\n\nconst IMPORT_SNIPPET = dedent`\n import Analytics from '${MODULE_SPECIFIER}';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<Analytics />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <Analytics /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <Analytics /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<Analytics />` at the top level of the root layout, ahead of\n * `{@render children()}`. The component is the same path for every provider,\n * so this modifier is provider-agnostic and a re-run with another provider\n * leaves the layout alone.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"Analytics\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { defaultImport: \"Analytics\", moduleSpecifier: MODULE_SPECIFIER },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { resolveProvider, suppliedProviderEnv } from \"../../../core/providers\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { envEditsFor, META } from \"./generate\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, modifyLayoutSvelte(layoutPath)));\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n pushResult(\n modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\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,IAAmB,8CAEnB,IAAiB,CAAM;2BACF,EAAiB;GAGtC,IAAiB,qBAEjB,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA,EAAe,KAAK;AACtB,CAAC,CAAC,KAAK,IAAI,GAEL,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA,EAAe,KAAK;AACtB,CAAC,CAAC,KAAK,IAAI;AAQX,SAAgB,EAAmB,GAAmC;CACpE,IAAI,CAAC,EAAG,WAAW,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAGxD,IAAM,IAAO,EAAW,SAAS,CAAU;CAqB3C,OApBI,EAAK,WAAW,WAAW,IACtB;EAAE,QAAQ;EAAW,SAAS;CAAM,IAExC,EAAK,UAAU,KAIpB,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQ,MAAQ,EAAmB,IAAS,MAAO;GACzD,EAAc,GAAI,CAChB;IAAE,eAAe;IAAa,iBAAiB;GAAiB,CAClE,CAAC;EACH,CAAC;EACD,OAAO;CACT,CAAC,GAEI,EAAK,qBAAqB,CAAc,KAC3C,EAAK,aAAa,CAAc,GAElC,EAAK,QAAQ,CAAU,GAChB;EAAE,QAAQ;EAAW,SAAS,EAAK,WAAW;CAAE,KAhB9C;EAAE,QAAQ;EAAU,SAAS;CAAa;AAiBrD;;;AC/DA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAW,EAAgB,GAAM,CAAO,GACxC,IAAmB,CAAC,GAEpB,KAAc,MAAsB;EACxC,AAAI,KAAM,EAAS,KAAK,CAAI;CAC9B;CAEA,EAAO,KAAK,qCAAqC;CACjD,IAAM,IAAa,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAG5E,AAFA,EAAW,EAAoB,GAAY,EAAmB,CAAU,CAAC,CAAC,GAE1E,EAAO,KAAK,eAAe;CAC3B,IAAM,IAAU,EAAK,KAAK,EAAQ,MAAM,MAAM;CAQ9C,OAPA,EACE,EACE,GACA,EAAU,GAAS,EAAY,GAAU,EAAoB,CAAO,CAAC,CAAC,CACxE,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,29 +1,30 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { t } from "./shared-
|
|
2
|
+
import { t } from "./shared-DkGfltvn.js";
|
|
3
3
|
import { n } from "./env-BPfk1VAw.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import o from "
|
|
7
|
-
import s from "node:
|
|
8
|
-
import
|
|
4
|
+
import { f as r, o as i } from "./ts-morph-helpers-CeduA--o.js";
|
|
5
|
+
import { modifyOutcomeToFile as a } from "./modify-file-DGe7MJu_.js";
|
|
6
|
+
import { t as o } from "./svelte-file-B3RfgVdt.js";
|
|
7
|
+
import s from "node:fs";
|
|
8
|
+
import c from "node:path";
|
|
9
|
+
import { Project as l, QuoteKind as u, SyntaxKind as d } from "ts-morph";
|
|
9
10
|
//#region src/patterns/disable/payments/modifies/modify-nav-user.ts
|
|
10
|
-
function
|
|
11
|
-
if (!
|
|
11
|
+
function f(e) {
|
|
12
|
+
if (!s.existsSync(e)) return {
|
|
12
13
|
status: "success",
|
|
13
14
|
changed: !1
|
|
14
15
|
};
|
|
15
|
-
let t =
|
|
16
|
+
let t = s.readFileSync(e, "utf8");
|
|
16
17
|
if (!t.includes("/billing")) return {
|
|
17
18
|
status: "success",
|
|
18
19
|
changed: !1
|
|
19
20
|
};
|
|
20
|
-
let n = new
|
|
21
|
-
|
|
22
|
-
let t =
|
|
23
|
-
return t.wasRemoved && (
|
|
21
|
+
let n = new o(t), i = !1, a = (e) => {
|
|
22
|
+
i || e((e) => {
|
|
23
|
+
let t = r(e, "Billing", "@lucide/svelte/icons/credit-card");
|
|
24
|
+
return t.wasRemoved && (i = !0), t.source;
|
|
24
25
|
});
|
|
25
26
|
};
|
|
26
|
-
return
|
|
27
|
+
return a((e) => n.modifyModuleScript(e)), i || a((e) => n.modifyScript(e)), i ? (s.writeFileSync(e, n.toString(), "utf8"), {
|
|
27
28
|
status: "success",
|
|
28
29
|
changed: !0
|
|
29
30
|
}) : {
|
|
@@ -33,39 +34,39 @@ function d(e) {
|
|
|
33
34
|
}
|
|
34
35
|
//#endregion
|
|
35
36
|
//#region src/patterns/disable/payments/modifies/modify-user-signup.ts
|
|
36
|
-
var
|
|
37
|
-
function
|
|
38
|
-
if (!
|
|
37
|
+
var p = /* @__PURE__ */ new Set(["linkStripeCustomer.run", "linkStripeCustomer"]);
|
|
38
|
+
function m(e) {
|
|
39
|
+
if (!s.existsSync(e)) return {
|
|
39
40
|
status: "success",
|
|
40
41
|
changed: !1
|
|
41
42
|
};
|
|
42
|
-
let t =
|
|
43
|
+
let t = s.readFileSync(e, "utf8");
|
|
43
44
|
if (!t.includes("linkStripeCustomer")) return {
|
|
44
45
|
status: "success",
|
|
45
46
|
changed: !1
|
|
46
47
|
};
|
|
47
|
-
let n = new
|
|
48
|
+
let n = new l({ manipulationSettings: { quoteKind: u.Single } }).addSourceFileAtPath(e);
|
|
48
49
|
for (let e of ["$lib/workflows/link-stripe-customer", "$lib/stripe"]) {
|
|
49
50
|
let t = n.getImportDeclarations().find((t) => t.getModuleSpecifierValue() === e);
|
|
50
51
|
t && t.remove();
|
|
51
52
|
}
|
|
52
53
|
let r = n.getVariableStatement((e) => e.getDeclarations().some((e) => e.getName() === "linkStripeCustomer"));
|
|
53
54
|
r && r.remove();
|
|
54
|
-
let
|
|
55
|
-
for (let e of
|
|
56
|
-
let t = e.getFirstAncestorByKind(
|
|
55
|
+
let a = n.getDescendantsOfKind(d.CallExpression).filter((e) => p.has(e.getExpression().getText()));
|
|
56
|
+
for (let e of a) {
|
|
57
|
+
let t = e.getFirstAncestorByKind(d.ExpressionStatement);
|
|
57
58
|
t && t.remove();
|
|
58
59
|
}
|
|
59
|
-
return n
|
|
60
|
+
return i(n), n.saveSync(), {
|
|
60
61
|
status: "success",
|
|
61
62
|
changed: n.getFullText() !== t
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
//#endregion
|
|
65
66
|
//#region src/patterns/disable/payments/generate.runtime.ts
|
|
66
|
-
async function
|
|
67
|
-
let
|
|
68
|
-
e &&
|
|
67
|
+
async function h(r) {
|
|
68
|
+
let i = r.features.auth, o = e(r), s = [], l = (e) => {
|
|
69
|
+
e && s.push(e);
|
|
69
70
|
};
|
|
70
71
|
o.info("Stripping Stripe credentials from .env");
|
|
71
72
|
let u = [
|
|
@@ -85,32 +86,32 @@ async function m(i) {
|
|
|
85
86
|
type: "var",
|
|
86
87
|
key: "STRIPE_WEBHOOK_SECRET"
|
|
87
88
|
}
|
|
88
|
-
],
|
|
89
|
-
if (l(
|
|
89
|
+
], d = c.join(r.root, ".env");
|
|
90
|
+
if (l(a(d, n(d, u))), i) {
|
|
90
91
|
o.info("Reverting nav-user.svelte");
|
|
91
|
-
let e =
|
|
92
|
-
l(
|
|
93
|
-
let t =
|
|
94
|
-
l(
|
|
92
|
+
let e = c.join(r.root, "src", "lib", "components", "nav-user.svelte");
|
|
93
|
+
l(a(e, f(e))), o.info("Reverting signup +page.server.ts");
|
|
94
|
+
let t = c.join(r.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
|
|
95
|
+
l(a(t, m(t)));
|
|
95
96
|
}
|
|
96
97
|
return {
|
|
97
98
|
creates: [],
|
|
98
|
-
modifies:
|
|
99
|
+
modifies: s,
|
|
99
100
|
deletes: [],
|
|
100
101
|
components: [],
|
|
101
102
|
packages: [],
|
|
102
103
|
collections: [],
|
|
103
104
|
collectionPatches: [],
|
|
104
|
-
collectionDrops: await t(
|
|
105
|
+
collectionDrops: await t(i ? [
|
|
105
106
|
"transactions",
|
|
106
107
|
"stripe_customers",
|
|
107
108
|
"stripe_payment_methods",
|
|
108
109
|
"stripe_prices",
|
|
109
110
|
"stripe_products"
|
|
110
|
-
] : ["stripe_prices", "stripe_products"],
|
|
111
|
+
] : ["stripe_prices", "stripe_products"], r)
|
|
111
112
|
};
|
|
112
113
|
}
|
|
113
114
|
//#endregion
|
|
114
|
-
export {
|
|
115
|
+
export { h as generate };
|
|
115
116
|
|
|
116
|
-
//# sourceMappingURL=generate.runtime-
|
|
117
|
+
//# sourceMappingURL=generate.runtime-DHXkw2gf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-DHXkw2gf.js","names":[],"sources":["../../src/patterns/disable/payments/modifies/modify-nav-user.ts","../../src/patterns/disable/payments/modifies/modify-user-signup.ts","../../src/patterns/disable/payments/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(\"/billing\")) {\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 \"Billing\",\n \"@lucide/svelte/icons/credit-card\",\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 fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst CALL_EXPRESSIONS = new Set([\n \"linkStripeCustomer.run\",\n // Projects from before the workflow: an inline helper called directly.\n \"linkStripeCustomer\",\n]);\n\nexport function unmodifyUserSignup(userSignupPath: string): ModifyOutcome {\n if (!fs.existsSync(userSignupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(userSignupPath, \"utf8\");\n if (!originalSource.includes(\"linkStripeCustomer\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(userSignupPath);\n\n for (const specifier of [\n \"$lib/workflows/link-stripe-customer\",\n \"$lib/stripe\",\n ]) {\n const decl = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === specifier);\n if (decl) decl.remove();\n }\n\n const linkFn = sourceFile.getVariableStatement((s) =>\n s.getDeclarations().some((d) => d.getName() === \"linkStripeCustomer\"),\n );\n if (linkFn) linkFn.remove();\n\n const callStatements = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => CALL_EXPRESSIONS.has(ce.getExpression().getText()));\n for (const call of callStatements) {\n const stmt = call.getFirstAncestorByKind(SyntaxKind.ExpressionStatement);\n if (stmt) stmt.remove();\n }\n\n formatLikeSource(sourceFile);\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 { modifyEnvRemove, type EnvEdit } from \"../../../runtime/env\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyUserSignup } from \"./modifies/modify-user-signup\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const isAppMode = options.features.auth;\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(\"Stripping Stripe credentials from .env\");\n const envEdits: EnvEdit[] = [\n { type: \"comment\", key: \"Stripe credentials\" },\n { type: \"var\", key: \"STRIPE_SECRET_KEY\" },\n { type: \"var\", key: \"PUBLIC_STRIPE_PUBLISHABLE_KEY\" },\n { type: \"var\", key: \"STRIPE_WEBHOOK_SECRET\" },\n ];\n const envPath = path.join(options.root, \".env\");\n pushResult(modifyOutcomeToFile(envPath, modifyEnvRemove(envPath, envEdits)));\n\n if (isAppMode) {\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"(auth)\",\n \"signup\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(userSignupPath, unmodifyUserSignup(userSignupPath)),\n );\n }\n\n const collectionNames = [\n \"transactions\",\n \"stripe_customers\",\n \"stripe_payment_methods\",\n \"stripe_prices\",\n \"stripe_products\",\n ];\n const collectionDrops = await planDropsForCollections(\n isAppMode ? collectionNames : [\"stripe_prices\", \"stripe_products\"],\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;CAClE,IAAI,CAAC,EAAG,WAAW,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAS,EAAG,aAAa,GAAa,MAAM;CAClD,IAAI,CAAC,EAAO,SAAS,UAAU,GAC7B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAO,IAAI,EAAW,CAAM,GAC9B,IAAa,IAEX,KAAa,MAAgD;EAC7D,KACJ,GAAK,MAAQ;GACX,IAAM,IAAS,EACb,GACA,WACA,kCACF;GAEA,OADI,EAAO,eAAY,IAAa,KAC7B,EAAO;EAChB,CAAC;CACH;CAUA,OARA,GAAW,MAAO,EAAK,mBAAmB,CAAE,CAAC,GACxC,KAAY,GAAW,MAAO,EAAK,aAAa,CAAE,CAAC,GAEnD,KAIL,EAAG,cAAc,GAAa,EAAK,SAAS,GAAG,MAAM,GAC9C;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAW,SAAS;CAAM;AAK/C;;;ACnCA,IAAM,oBAAmB,IAAI,IAAI,CAC/B,0BAEA,oBACF,CAAC;AAED,SAAgB,EAAmB,GAAuC;CACxE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAiB,EAAG,aAAa,GAAgB,MAAM;CAC7D,IAAI,C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K,EAAQ,MAAM,MAAM;CAG9C,IAFA,EAAW,EAAoB,GAAS,EAAgB,GAAS,CAAQ,CAAC,CAAC,GAEvE,GAAW;EACb,EAAO,KAAK,2BAA2B;EACvC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,iBACF;EAGA,AAFA,EAAW,EAAoB,GAAa,EAAgB,CAAW,CAAC,CAAC,GAEzE,EAAO,KAAK,kCAAkC;EAC9C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,UACA,YACA,UACA,UACA,iBACF;EACA,EACE,EAAoB,GAAgB,EAAmB,CAAc,CAAC,CACxE;CACF;CAcA,OAAO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4B,EAC5B,IAAY;GAPZ;GACA;GACA;GACA;GACA;EAGY,IAAkB,CAAC,iBAAiB,iBAAiB,GACjE,CACF;CAWA;AACF"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
3
|
import { a as n, i as r, n as i, o as a, r as o, s, t as c } from "./dispatch-BRnt8PcW.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import p from "
|
|
7
|
-
import m from "node:
|
|
8
|
-
import
|
|
4
|
+
import { _ as l, o as u, r as d } from "./ts-morph-helpers-CeduA--o.js";
|
|
5
|
+
import { modifyOutcomeToFile as f } from "./modify-file-DGe7MJu_.js";
|
|
6
|
+
import { t as p } from "./svelte-file-B3RfgVdt.js";
|
|
7
|
+
import m from "node:fs";
|
|
8
|
+
import h from "node:path";
|
|
9
|
+
import { SyntaxKind as g } from "ts-morph";
|
|
9
10
|
//#region src/patterns/enable/subscriptions/modifies/modify-webhook-server.ts
|
|
10
|
-
var
|
|
11
|
+
var _ = e`
|
|
11
12
|
Wire the subscription event handlers into src/routes/webhooks/stripe/handlers/dispatch.ts:
|
|
12
13
|
|
|
13
14
|
Add imports:
|
|
@@ -25,7 +26,7 @@ var g = e`
|
|
|
25
26
|
case "customer.subscription.deleted":
|
|
26
27
|
await handleSubscriptionDeleted(event.data.object, locals);
|
|
27
28
|
break;
|
|
28
|
-
`,
|
|
29
|
+
`, v = "Enable payments first — src/routes/webhooks/stripe/handlers/dispatch.ts is created by enable-payments.", y = e`
|
|
29
30
|
case "customer.subscription.created":
|
|
30
31
|
await handleSubscriptionCreated(event.data.object, locals);
|
|
31
32
|
break;
|
|
@@ -38,12 +39,12 @@ var g = e`
|
|
|
38
39
|
await handleSubscriptionDeleted(event.data.object, locals);
|
|
39
40
|
break;
|
|
40
41
|
`;
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
42
|
+
function b(e) {
|
|
43
|
+
if (!m.existsSync(e)) return {
|
|
43
44
|
status: "not-found",
|
|
44
|
-
message:
|
|
45
|
+
message: v
|
|
45
46
|
};
|
|
46
|
-
let t =
|
|
47
|
+
let t = m.readFileSync(e, "utf8");
|
|
47
48
|
if (t.includes("handleSubscriptionCreated")) return {
|
|
48
49
|
status: "success",
|
|
49
50
|
changed: !1
|
|
@@ -63,32 +64,32 @@ function y(e) {
|
|
|
63
64
|
moduleSpecifier: "./subscription/deleted"
|
|
64
65
|
}
|
|
65
66
|
]);
|
|
66
|
-
let t = e.getDescendantsOfKind(
|
|
67
|
+
let t = e.getDescendantsOfKind(g.SwitchStatement).find((e) => e.getExpression().getText().includes("event.type"));
|
|
67
68
|
if (!t) return;
|
|
68
|
-
let r = t.getCaseBlock().getClauses(), i = r.find((e) => e.getKind() ===
|
|
69
|
+
let r = t.getCaseBlock().getClauses(), i = r.find((e) => e.getKind() === g.DefaultClause), a = `${y}\n\n`;
|
|
69
70
|
if (i) i.replaceWithText(a + i.getText());
|
|
70
71
|
else if (r.length > 0) {
|
|
71
72
|
let e = r[r.length - 1];
|
|
72
|
-
e.replaceWithText(e.getText() + `\n\n${
|
|
73
|
+
e.replaceWithText(e.getText() + `\n\n${y}`);
|
|
73
74
|
} else return;
|
|
74
|
-
e
|
|
75
|
+
u(e), n = !0;
|
|
75
76
|
});
|
|
76
|
-
return n ? (
|
|
77
|
+
return n ? (m.writeFileSync(e, r, "utf8"), {
|
|
77
78
|
status: "success",
|
|
78
79
|
changed: !0
|
|
79
80
|
}) : {
|
|
80
81
|
status: "failed",
|
|
81
|
-
message:
|
|
82
|
+
message: _
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
//#endregion
|
|
85
86
|
//#region src/patterns/enable/subscriptions/modifies/modify-by-template.ts
|
|
86
|
-
function
|
|
87
|
-
if (!
|
|
87
|
+
function x(e, t, n, r) {
|
|
88
|
+
if (!m.existsSync(e)) return {
|
|
88
89
|
status: "not-found",
|
|
89
90
|
message: r
|
|
90
91
|
};
|
|
91
|
-
let i =
|
|
92
|
+
let i = m.readFileSync(e, "utf8");
|
|
92
93
|
if (i.includes(n)) return {
|
|
93
94
|
status: "success",
|
|
94
95
|
changed: !1
|
|
@@ -97,30 +98,30 @@ function b(e, t, n, r) {
|
|
|
97
98
|
return i === a ? {
|
|
98
99
|
status: "success",
|
|
99
100
|
changed: !1
|
|
100
|
-
} : (
|
|
101
|
+
} : (m.writeFileSync(e, a, "utf8"), {
|
|
101
102
|
status: "success",
|
|
102
103
|
changed: !0
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
//#endregion
|
|
106
107
|
//#region src/patterns/enable/subscriptions/modifies/modify-app-layout-server.ts
|
|
107
|
-
var
|
|
108
|
-
function
|
|
109
|
-
return
|
|
108
|
+
var S = ["Create src/routes/(app)/+layout.server.ts before enabling subscriptions.", "Enable auth first — the (app) layout is provided by the velastack-auth baseline."].join("\n");
|
|
109
|
+
function C(e, t) {
|
|
110
|
+
return x(e, t, "loadActiveSubscription", S);
|
|
110
111
|
}
|
|
111
112
|
//#endregion
|
|
112
113
|
//#region src/patterns/enable/subscriptions/modifies/modify-app-layout-svelte.ts
|
|
113
|
-
var
|
|
114
|
+
var w = [
|
|
114
115
|
"Pass the subscription prop to <AppSidebar> in src/routes/(app)/+layout.svelte:",
|
|
115
116
|
"",
|
|
116
117
|
"<AppSidebar user={data.user} subscription={data.subscription} />"
|
|
117
|
-
].join("\n"),
|
|
118
|
-
function
|
|
119
|
-
if (!
|
|
118
|
+
].join("\n"), T = ["Create src/routes/(app)/+layout.svelte with an <AppSidebar /> that receives the subscription prop."].join("\n");
|
|
119
|
+
function E(e) {
|
|
120
|
+
if (!m.existsSync(e)) return {
|
|
120
121
|
status: "not-found",
|
|
121
|
-
message:
|
|
122
|
+
message: T
|
|
122
123
|
};
|
|
123
|
-
let t =
|
|
124
|
+
let t = p.fromPath(e);
|
|
124
125
|
return t.hasElement("AppSidebar") ? t.hasAttribute("AppSidebar", "subscription") ? {
|
|
125
126
|
status: "success",
|
|
126
127
|
changed: !1
|
|
@@ -129,38 +130,38 @@ function T(e) {
|
|
|
129
130
|
changed: t.hasChanged()
|
|
130
131
|
}) : {
|
|
131
132
|
status: "failed",
|
|
132
|
-
message:
|
|
133
|
+
message: w
|
|
133
134
|
} : {
|
|
134
135
|
status: "failed",
|
|
135
|
-
message:
|
|
136
|
+
message: w
|
|
136
137
|
};
|
|
137
138
|
}
|
|
138
139
|
//#endregion
|
|
139
140
|
//#region src/patterns/enable/subscriptions/modifies/modify-app-sidebar.ts
|
|
140
|
-
var
|
|
141
|
+
var D = "{ id: string; productName: string | null } | null", O = [
|
|
141
142
|
"Update src/lib/components/app-sidebar.svelte to forward a subscription prop:",
|
|
142
143
|
"",
|
|
143
144
|
"1. Add `subscription = null` to the destructured $props() call.",
|
|
144
|
-
`2. Add \`subscription?: ${
|
|
145
|
+
`2. Add \`subscription?: ${D}\` to the props type.`,
|
|
145
146
|
"3. Pass `{subscription}` to <NavUser>."
|
|
146
|
-
].join("\n"),
|
|
147
|
-
function
|
|
147
|
+
].join("\n"), k = ["Create src/lib/components/app-sidebar.svelte before enabling subscriptions."].join("\n");
|
|
148
|
+
function A(e) {
|
|
148
149
|
let t = !1, { source: n } = l(e, (e) => {
|
|
149
150
|
for (let n of e.getVariableDeclarations()) {
|
|
150
151
|
let e = n.getInitializer();
|
|
151
152
|
if (!e || e.getText() !== "$props()") continue;
|
|
152
153
|
let r = n.getNameNode();
|
|
153
|
-
if (r.getKind() !==
|
|
154
|
-
let i = r.asKindOrThrow(
|
|
154
|
+
if (r.getKind() !== g.ObjectBindingPattern) continue;
|
|
155
|
+
let i = r.asKindOrThrow(g.ObjectBindingPattern), a = i.getElements();
|
|
155
156
|
if (a.some((e) => e.getName() === "subscription")) return;
|
|
156
157
|
let o = n.getTypeNode();
|
|
157
|
-
if (o?.getKind() ===
|
|
158
|
-
let e = o.asKindOrThrow(
|
|
158
|
+
if (o?.getKind() === g.IntersectionType) {
|
|
159
|
+
let e = o.asKindOrThrow(g.IntersectionType);
|
|
159
160
|
for (let t of e.getTypeNodes()) {
|
|
160
|
-
if (t.getKind() !==
|
|
161
|
-
let e = t.asKindOrThrow(
|
|
161
|
+
if (t.getKind() !== g.TypeLiteral) continue;
|
|
162
|
+
let e = t.asKindOrThrow(g.TypeLiteral), n = e.getProperties().map((e) => e.getText().replace(/[;,]\s*$/, ""));
|
|
162
163
|
if (!n.some((e) => /^\s*subscription\??\s*:/.test(e))) {
|
|
163
|
-
n.push(`subscription?: ${
|
|
164
|
+
n.push(`subscription?: ${D}`), e.replaceWithText(`{ ${n.join("; ")}; }`);
|
|
164
165
|
break;
|
|
165
166
|
}
|
|
166
167
|
}
|
|
@@ -168,32 +169,32 @@ function k(e) {
|
|
|
168
169
|
let s = a.map((e) => e.getText()), c = a.findIndex((e) => e.getDotDotDotToken() || e.getInitializer());
|
|
169
170
|
c === -1 && (c = s.length), s.splice(c, 0, "subscription = null"), i.replaceWithText(`{ ${s.join(", ")} }`), t = !0;
|
|
170
171
|
}
|
|
171
|
-
e
|
|
172
|
+
u(e);
|
|
172
173
|
});
|
|
173
174
|
return {
|
|
174
175
|
source: n,
|
|
175
176
|
wasAdded: t
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
|
-
function
|
|
179
|
-
if (!
|
|
179
|
+
function j(e) {
|
|
180
|
+
if (!m.existsSync(e)) return {
|
|
180
181
|
status: "not-found",
|
|
181
|
-
message:
|
|
182
|
+
message: k
|
|
182
183
|
};
|
|
183
|
-
let t =
|
|
184
|
+
let t = m.readFileSync(e, "utf8");
|
|
184
185
|
if (t.includes("subscription?: {") || t.includes("subscription={subscription}") || t.includes("{subscription}")) return {
|
|
185
186
|
status: "success",
|
|
186
187
|
changed: !1
|
|
187
188
|
};
|
|
188
|
-
let n = new
|
|
189
|
+
let n = new p(t);
|
|
189
190
|
if (!n.hasElement("NavUser")) return {
|
|
190
191
|
status: "failed",
|
|
191
|
-
message:
|
|
192
|
+
message: O
|
|
192
193
|
};
|
|
193
|
-
let r = n.modifyScript((e) =>
|
|
194
|
+
let r = n.modifyScript((e) => A(e).source), i = !n.hasAttribute("NavUser", "subscription") && n.appendToAttributes("NavUser", " {subscription}");
|
|
194
195
|
return !r && !i ? {
|
|
195
196
|
status: "failed",
|
|
196
|
-
message:
|
|
197
|
+
message: O
|
|
197
198
|
} : (n.writeTo(e), {
|
|
198
199
|
status: "success",
|
|
199
200
|
changed: n.hasChanged()
|
|
@@ -201,25 +202,25 @@ function A(e) {
|
|
|
201
202
|
}
|
|
202
203
|
//#endregion
|
|
203
204
|
//#region src/patterns/enable/subscriptions/modifies/modify-nav-user.ts
|
|
204
|
-
var
|
|
205
|
-
function
|
|
206
|
-
return
|
|
205
|
+
var M = ["src/lib/components/nav-user.svelte is missing.", "Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user."].join("\n");
|
|
206
|
+
function N(e, t) {
|
|
207
|
+
return x(e, t, "planLabel", M);
|
|
207
208
|
}
|
|
208
209
|
//#endregion
|
|
209
210
|
//#region src/patterns/enable/subscriptions/modifies/modify-billing-page-server.ts
|
|
210
|
-
var
|
|
211
|
-
function
|
|
212
|
-
return
|
|
211
|
+
var P = ["src/routes/(app)/billing/+page.server.ts is missing.", "Enable payments first — subscriptions extends the billing page with plan management."].join("\n");
|
|
212
|
+
function F(e, t) {
|
|
213
|
+
return x(e, t, "selectPlan", P);
|
|
213
214
|
}
|
|
214
215
|
//#endregion
|
|
215
216
|
//#region src/patterns/enable/subscriptions/modifies/modify-billing-page-svelte.ts
|
|
216
|
-
var
|
|
217
|
-
function
|
|
218
|
-
return
|
|
217
|
+
var I = ["src/routes/(app)/billing/+page.svelte is missing.", "Enable payments first — subscriptions extends the billing page with plan management."].join("\n");
|
|
218
|
+
function L(e, t) {
|
|
219
|
+
return x(e, t, "availablePlans", I);
|
|
219
220
|
}
|
|
220
221
|
//#endregion
|
|
221
222
|
//#region src/patterns/enable/subscriptions/generate.runtime.ts
|
|
222
|
-
var
|
|
223
|
+
var R = /* #__PURE__ */ Object.assign({
|
|
223
224
|
"./preview-modifies/src/lib/components/app-sidebar.svelte": s,
|
|
224
225
|
"./preview-modifies/src/lib/components/nav-user.svelte": a,
|
|
225
226
|
"./preview-modifies/src/routes/(app)/+layout.server.ts": n,
|
|
@@ -228,30 +229,30 @@ var L = /* #__PURE__ */ Object.assign({
|
|
|
228
229
|
"./preview-modifies/src/routes/(app)/billing/+page.svelte": i,
|
|
229
230
|
"./preview-modifies/src/routes/webhooks/stripe/handlers/dispatch.ts": c
|
|
230
231
|
});
|
|
231
|
-
function
|
|
232
|
-
let t =
|
|
232
|
+
function z(e) {
|
|
233
|
+
let t = R[`./preview-modifies/${e}`];
|
|
233
234
|
if (t === void 0) throw Error(`Missing template for ${e} in subscriptions preview-modifies`);
|
|
234
235
|
return t;
|
|
235
236
|
}
|
|
236
|
-
async function
|
|
237
|
+
async function B(e) {
|
|
237
238
|
let n = t(e), r = [], i = (e) => {
|
|
238
239
|
e && r.push(e);
|
|
239
240
|
};
|
|
240
241
|
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 l =
|
|
250
|
-
i(
|
|
251
|
-
let
|
|
252
|
-
i(u
|
|
253
|
-
let
|
|
254
|
-
return i(
|
|
242
|
+
let a = h.join(e.root, "src", "routes", "webhooks", "stripe", "handlers", "dispatch.ts");
|
|
243
|
+
i(f(a, b(a))), n.info("Modifying (app)/+layout.server.ts");
|
|
244
|
+
let o = h.join(e.root, "src", "routes", "(app)", "+layout.server.ts");
|
|
245
|
+
i(f(o, C(o, z("src/routes/(app)/+layout.server.ts")))), n.info("Modifying (app)/+layout.svelte");
|
|
246
|
+
let s = h.join(e.root, "src", "routes", "(app)", "+layout.svelte");
|
|
247
|
+
i(f(s, E(s))), n.info("Modifying app-sidebar.svelte");
|
|
248
|
+
let c = h.join(e.root, "src", "lib", "components", "app-sidebar.svelte");
|
|
249
|
+
i(f(c, j(c))), n.info("Modifying nav-user.svelte");
|
|
250
|
+
let l = h.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
251
|
+
i(f(l, N(l, z("src/lib/components/nav-user.svelte")))), n.info("Modifying billing/+page.server.ts");
|
|
252
|
+
let u = h.join(e.root, "src", "routes", "(app)", "billing", "+page.server.ts");
|
|
253
|
+
i(f(u, F(u, z("src/routes/(app)/billing/+page.server.ts")))), n.info("Modifying billing/+page.svelte");
|
|
254
|
+
let d = h.join(e.root, "src", "routes", "(app)", "billing", "+page.svelte");
|
|
255
|
+
return i(f(d, L(d, z("src/routes/(app)/billing/+page.svelte")))), {
|
|
255
256
|
creates: [],
|
|
256
257
|
modifies: r,
|
|
257
258
|
deletes: [],
|
|
@@ -263,6 +264,6 @@ async function z(e) {
|
|
|
263
264
|
};
|
|
264
265
|
}
|
|
265
266
|
//#endregion
|
|
266
|
-
export {
|
|
267
|
+
export { B as generate };
|
|
267
268
|
|
|
268
|
-
//# sourceMappingURL=generate.runtime-
|
|
269
|
+
//# sourceMappingURL=generate.runtime-DIuCrH6l.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-DIuCrH6l.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 formatLikeSource,\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 formatLikeSource(sf);\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} 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 {\n withInMemoryScript,\n formatLikeSource,\n} 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 formatLikeSource(sf);\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":";;;;;;;;;;AAUA,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;E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;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
+
import { o as t } from "./ts-morph-helpers-CeduA--o.js";
|
|
3
|
+
import { modifyOutcomeToFile as n } from "./modify-file-DGe7MJu_.js";
|
|
4
|
+
import r from "node:fs";
|
|
5
|
+
import i from "node:path";
|
|
6
|
+
import { Project as a, SyntaxKind as o } from "ts-morph";
|
|
7
|
+
//#region src/patterns/disable/api/modifies/hooks.server.ts
|
|
8
|
+
function s(e) {
|
|
9
|
+
if (!r.existsSync(e)) return {
|
|
10
|
+
status: "success",
|
|
11
|
+
changed: !1
|
|
12
|
+
};
|
|
13
|
+
let n = r.readFileSync(e, "utf8"), i = new a().addSourceFileAtPath(e), s = i.getDescendantsOfKind(o.CallExpression).find((e) => e.getExpression().getText() === "handlePocketbase");
|
|
14
|
+
if (!s) return {
|
|
15
|
+
status: "success",
|
|
16
|
+
changed: !1
|
|
17
|
+
};
|
|
18
|
+
let c = s.getArguments();
|
|
19
|
+
if (c.length === 0) return {
|
|
20
|
+
status: "success",
|
|
21
|
+
changed: !1
|
|
22
|
+
};
|
|
23
|
+
let l = c[0];
|
|
24
|
+
if (l.getKind() !== o.ObjectLiteralExpression) return {
|
|
25
|
+
status: "success",
|
|
26
|
+
changed: !1
|
|
27
|
+
};
|
|
28
|
+
let u = l.asKindOrThrow(o.ObjectLiteralExpression), d = u.getProperty("api");
|
|
29
|
+
return d ? (d.remove(), u.getProperties().length === 0 && s.removeArgument(0), t(i), i.saveSync(), {
|
|
30
|
+
status: "success",
|
|
31
|
+
changed: i.getFullText() !== n
|
|
32
|
+
}) : {
|
|
33
|
+
status: "success",
|
|
34
|
+
changed: !1
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/patterns/disable/api/generate.runtime.ts
|
|
39
|
+
async function c(t) {
|
|
40
|
+
let r = e(t), a = [];
|
|
41
|
+
r.info("Reverting hooks.server.ts");
|
|
42
|
+
let o = i.join(t.root, "src", "hooks.server.ts"), c = n(o, s(o));
|
|
43
|
+
return c && a.push(c), {
|
|
44
|
+
creates: [],
|
|
45
|
+
modifies: a,
|
|
46
|
+
deletes: [],
|
|
47
|
+
components: [],
|
|
48
|
+
packages: [],
|
|
49
|
+
collections: [],
|
|
50
|
+
collectionPatches: [],
|
|
51
|
+
collectionDrops: []
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { c as generate };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=generate.runtime-DOB4U-Sa.js.map
|