@velastack/patterns 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{collections-BYcVyY9O.js → collections-DzwWwFUQ.js} +2 -2
- package/dist/chunks/{collections-BYcVyY9O.js.map → collections-DzwWwFUQ.js.map} +1 -1
- package/dist/chunks/{constants-Bdx8mp7v.js → constants-8cLxGOB0.js} +3 -3
- package/dist/chunks/constants-8cLxGOB0.js.map +1 -0
- package/dist/chunks/{currency.server-Dwz8LgvP.js → currency.server-CzHS7Svd.js} +2 -2
- package/dist/chunks/{currency.server-Dwz8LgvP.js.map → currency.server-CzHS7Svd.js.map} +1 -1
- package/dist/chunks/{env-vars-0hvKe55u.js → env-vars-CNH-ItSY.js} +3 -3
- package/dist/chunks/{env-vars-0hvKe55u.js.map → env-vars-CNH-ItSY.js.map} +1 -1
- package/dist/chunks/{generate-BOuNjssv.js → generate-BEc_h7OI.js} +2 -2
- package/dist/chunks/{generate-BOuNjssv.js.map → generate-BEc_h7OI.js.map} +1 -1
- package/dist/chunks/{generate-DoHn_xJZ.js → generate-C3OaUggX.js} +2 -2
- package/dist/chunks/{generate-DoHn_xJZ.js.map → generate-C3OaUggX.js.map} +1 -1
- package/dist/chunks/{generate-l2JZTRKb.js → generate-CtQcmjPM.js} +2 -2
- package/dist/chunks/{generate-l2JZTRKb.js.map → generate-CtQcmjPM.js.map} +1 -1
- package/dist/chunks/{generate-Df7t5Nbk.js → generate-D21dCU-o.js} +3 -3
- package/dist/chunks/{generate-Df7t5Nbk.js.map → generate-D21dCU-o.js.map} +1 -1
- package/dist/chunks/{generate-CNabcEBx.js → generate-DiwvSC9c.js} +2 -2
- package/dist/chunks/{generate-CNabcEBx.js.map → generate-DiwvSC9c.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BnqS_Zq8.js → generate.runtime--VeSxyIm.js} +3 -3
- package/dist/chunks/{generate.runtime-BnqS_Zq8.js.map → generate.runtime--VeSxyIm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cv3unKap.js → generate.runtime--yCjGZ6-.js} +3 -3
- package/dist/chunks/{generate.runtime-Cv3unKap.js.map → generate.runtime--yCjGZ6-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BoYwV0nt.js → generate.runtime-B3yuIjJD.js} +2 -2
- package/dist/chunks/{generate.runtime-BoYwV0nt.js.map → generate.runtime-B3yuIjJD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-q17D7QUT.js → generate.runtime-BBfiR_Le.js} +3 -3
- package/dist/chunks/{generate.runtime-q17D7QUT.js.map → generate.runtime-BBfiR_Le.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bvjj3zn0.js → generate.runtime-BK7x32md.js} +3 -3
- package/dist/chunks/{generate.runtime-Bvjj3zn0.js.map → generate.runtime-BK7x32md.js.map} +1 -1
- package/dist/chunks/{generate.runtime-gZ4wfYBP.js → generate.runtime-BL62aRng.js} +6 -6
- package/dist/chunks/{generate.runtime-gZ4wfYBP.js.map → generate.runtime-BL62aRng.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Du84quuK.js → generate.runtime-BTHuPon9.js} +5 -5
- package/dist/chunks/{generate.runtime-Du84quuK.js.map → generate.runtime-BTHuPon9.js.map} +1 -1
- package/dist/chunks/{generate.runtime-e_BkDyP0.js → generate.runtime-Brakd35X.js} +2 -2
- package/dist/chunks/{generate.runtime-e_BkDyP0.js.map → generate.runtime-Brakd35X.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B84ymwlD.js → generate.runtime-Bx_CaBZD.js} +2 -2
- package/dist/chunks/{generate.runtime-B84ymwlD.js.map → generate.runtime-Bx_CaBZD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-oUJUQRdg.js → generate.runtime-C8-mjcn8.js} +6 -6
- package/dist/chunks/{generate.runtime-oUJUQRdg.js.map → generate.runtime-C8-mjcn8.js.map} +1 -1
- package/dist/chunks/generate.runtime-CAO_SpsA.js +50 -0
- package/dist/chunks/generate.runtime-CAO_SpsA.js.map +1 -0
- package/dist/chunks/{generate.runtime-DJ5uF6EN.js → generate.runtime-CCE-9xQV.js} +2 -2
- package/dist/chunks/{generate.runtime-DJ5uF6EN.js.map → generate.runtime-CCE-9xQV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C7tlPKH1.js → generate.runtime-CGJ_4VS_.js} +4 -4
- package/dist/chunks/{generate.runtime-C7tlPKH1.js.map → generate.runtime-CGJ_4VS_.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CVWCUn52.js → generate.runtime-CPDJolef.js} +4 -4
- package/dist/chunks/{generate.runtime-CVWCUn52.js.map → generate.runtime-CPDJolef.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DqLmhrsM.js → generate.runtime-CaOO0281.js} +6 -6
- package/dist/chunks/{generate.runtime-DqLmhrsM.js.map → generate.runtime-CaOO0281.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dfz53sSK.js → generate.runtime-Ce2O5uWy.js} +3 -3
- package/dist/chunks/{generate.runtime-Dfz53sSK.js.map → generate.runtime-Ce2O5uWy.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DERcpgc-.js → generate.runtime-CeoqgxiO.js} +4 -4
- package/dist/chunks/{generate.runtime-DERcpgc-.js.map → generate.runtime-CeoqgxiO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-T7JLE4Wc.js → generate.runtime-CowdMKQs.js} +3 -3
- package/dist/chunks/{generate.runtime-T7JLE4Wc.js.map → generate.runtime-CowdMKQs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DSs4gVRU.js → generate.runtime-CtFCayo8.js} +7 -7
- package/dist/chunks/{generate.runtime-DSs4gVRU.js.map → generate.runtime-CtFCayo8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C4LUUuq7.js → generate.runtime-D34lCyet.js} +3 -3
- package/dist/chunks/{generate.runtime-C4LUUuq7.js.map → generate.runtime-D34lCyet.js.map} +1 -1
- package/dist/chunks/generate.runtime-DOWDoe6B.js +24 -0
- package/dist/chunks/generate.runtime-DOWDoe6B.js.map +1 -0
- package/dist/chunks/{generate.runtime-D677SB4v.js → generate.runtime-DOv-bhM6.js} +2 -2
- package/dist/chunks/{generate.runtime-D677SB4v.js.map → generate.runtime-DOv-bhM6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-WPq7bHRA.js → generate.runtime-DRuPb-67.js} +2 -2
- package/dist/chunks/{generate.runtime-WPq7bHRA.js.map → generate.runtime-DRuPb-67.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ByPcr9vJ.js → generate.runtime-DUBOC6AA.js} +3 -3
- package/dist/chunks/{generate.runtime-ByPcr9vJ.js.map → generate.runtime-DUBOC6AA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CHUCMVa2.js → generate.runtime-DVwha8lZ.js} +2 -2
- package/dist/chunks/{generate.runtime-CHUCMVa2.js.map → generate.runtime-DVwha8lZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BP31tAcD.js → generate.runtime-D_HYO-mG.js} +4 -4
- package/dist/chunks/{generate.runtime-BP31tAcD.js.map → generate.runtime-D_HYO-mG.js.map} +1 -1
- package/dist/chunks/{generate.runtime-nyJ6v56q.js → generate.runtime-DbMDlglD.js} +4 -4
- package/dist/chunks/{generate.runtime-nyJ6v56q.js.map → generate.runtime-DbMDlglD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BC6CBKh6.js → generate.runtime-DbSRJF-C.js} +3 -3
- package/dist/chunks/{generate.runtime-BC6CBKh6.js.map → generate.runtime-DbSRJF-C.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DuDcKDUl.js → generate.runtime-DlPeHx19.js} +2 -2
- package/dist/chunks/{generate.runtime-DuDcKDUl.js.map → generate.runtime-DlPeHx19.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cj-5fzbQ.js → generate.runtime-DroVnvQz.js} +4 -4
- package/dist/chunks/{generate.runtime-Cj-5fzbQ.js.map → generate.runtime-DroVnvQz.js.map} +1 -1
- package/dist/chunks/{generate.runtime-zr6uIHCd.js → generate.runtime-Drpy9sWO.js} +2 -2
- package/dist/chunks/{generate.runtime-zr6uIHCd.js.map → generate.runtime-Drpy9sWO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-bN61eWkc.js → generate.runtime-Dy9uuf7M.js} +6 -6
- package/dist/chunks/{generate.runtime-bN61eWkc.js.map → generate.runtime-Dy9uuf7M.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CIvecd9c.js → generate.runtime-HkvT9gm6.js} +4 -4
- package/dist/chunks/{generate.runtime-CIvecd9c.js.map → generate.runtime-HkvT9gm6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DiqfbDfk.js → generate.runtime-kEHEiLBL.js} +2 -2
- package/dist/chunks/{generate.runtime-DiqfbDfk.js.map → generate.runtime-kEHEiLBL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BqCbJ-No.js → generate.runtime-r9Ouwr5B.js} +3 -3
- package/dist/chunks/{generate.runtime-BqCbJ-No.js.map → generate.runtime-r9Ouwr5B.js.map} +1 -1
- package/dist/chunks/{generate.runtime-rLlDp4R6.js → generate.runtime-sALBNh1T.js} +4 -4
- package/dist/chunks/{generate.runtime-rLlDp4R6.js.map → generate.runtime-sALBNh1T.js.map} +1 -1
- package/dist/chunks/layout.svelte-Cb12mxua.js +65 -0
- package/dist/chunks/layout.svelte-Cb12mxua.js.map +1 -0
- package/dist/chunks/{modify-file-B4uJzOEj.js → modify-file-DdXJCMHN.js} +2 -2
- package/dist/chunks/{modify-file-B4uJzOEj.js.map → modify-file-DdXJCMHN.js.map} +1 -1
- package/dist/chunks/{pocketbase-BtN-wL8f.js → pocketbase-uOpghyT5.js} +2 -2
- package/dist/chunks/{pocketbase-BtN-wL8f.js.map → pocketbase-uOpghyT5.js.map} +1 -1
- package/dist/chunks/{providers-DRwJnSzb.js → providers-ypCW70Mb.js} +2 -2
- package/dist/chunks/{providers-DRwJnSzb.js.map → providers-ypCW70Mb.js.map} +1 -1
- package/dist/chunks/{shared-BbxLil4g.js → shared-DIDAkVts.js} +2 -2
- package/dist/chunks/{shared-BbxLil4g.js.map → shared-DIDAkVts.js.map} +1 -1
- package/dist/chunks/{site-VrqOvuiU.js → site-CVtsbO_S.js} +2 -2
- package/dist/chunks/{site-VrqOvuiU.js.map → site-CVtsbO_S.js.map} +1 -1
- package/dist/chunks/{table-core-BHFT-uMX.js → table-core-CUGp4Rf2.js} +2 -2
- package/dist/chunks/{table-core-BHFT-uMX.js.map → table-core-CUGp4Rf2.js.map} +1 -1
- package/dist/chunks/{test-setup-BtV6Gk9I.js → test-setup-B37g3TRn.js} +3 -3
- package/dist/chunks/{test-setup-BtV6Gk9I.js.map → test-setup-B37g3TRn.js.map} +1 -1
- package/dist/chunks/{ui-gG8i_Mzk.js → ui-Ct_9B91R.js} +3 -3
- package/dist/chunks/{ui-gG8i_Mzk.js.map → ui-Ct_9B91R.js.map} +1 -1
- package/dist/chunks/{whatsapp-DbjOxHaZ.js → whatsapp-Dr29ohbb.js} +2 -2
- package/dist/chunks/{whatsapp-DbjOxHaZ.js.map → whatsapp-Dr29ohbb.js.map} +1 -1
- package/dist/chunks/{write-result-DcqMefuP.js → write-result-mtVbmDyQ.js} +12 -12
- package/dist/chunks/{write-result-DcqMefuP.js.map → write-result-mtVbmDyQ.js.map} +1 -1
- package/dist/index.d.ts +124 -0
- package/dist/index.js +2113 -1953
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/constants-Bdx8mp7v.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-DiqfbDfk.js","names":["FAILURE_HINT","NOT_FOUND_HINT","dedent","getLogger","formatLikeSource","addNavItemToScript","modifyOutcomeToFile","SvelteFile","modifyUtils","fs","path","FAILURE_HINT$1","NOT_FOUND_HINT$1","modifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","args","firstArg","optionsObj","apiProp","apiInit","apiObj","apiKeysProp","keysInit","keysObj","API_KEYS_NAV_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","addItemToNavUser","file","navUserSnippet","wasAdded","tryAdd","run","result","source","title","url","icon","iconImportPath","fn","modifyNavUser","navUserPath","newNavUserSnippet","generate","logger","options","modifies","pushResult","utilsPath"],"sources":["../../src/patterns/enable/api-keys/modifies/hooks.server.ts","../../src/patterns/enable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/enable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with API keys in hooks.server.ts:\n\n handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\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: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(\n 0,\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n optionsObj.addPropertyAssignment({\n name: \"api\",\n initializer: `{ enabled: true, apiKeys: { enabled: true } }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (apiProp.getKind() === SyntaxKind.PropertyAssignment) {\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (apiInit && apiInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const enabledProp = apiObj.getProperty(\"enabled\");\n if (!enabledProp) {\n apiObj.addPropertyAssignment({ name: \"enabled\", initializer: \"true\" });\n }\n\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n apiObj.addPropertyAssignment({\n name: \"apiKeys\",\n initializer: `{ enabled: true }`,\n });\n } else if (apiKeysProp.getKind() === SyntaxKind.PropertyAssignment) {\n const keysInit = (\n apiKeysProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (\n keysInit &&\n keysInit.getKind() === SyntaxKind.ObjectLiteralExpression\n ) {\n const keysObj =\n keysInit as import(\"ts-morph\").ObjectLiteralExpression;\n const keysEnabled = keysObj.getProperty(\"enabled\");\n if (!keysEnabled) {\n keysObj.addPropertyAssignment({\n name: \"enabled\",\n initializer: \"true\",\n });\n }\n } else {\n (apiKeysProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `{ enabled: true }`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { addNavItemToScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst API_KEYS_NAV_SNIPPET = [\n \"import KeyRoundIcon from '@lucide/svelte/icons/key-round';\",\n \"\",\n \"// Add to your navUser array:\",\n \"{ title: 'API Keys', url: '/api-keys', icon: KeyRoundIcon }\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Add an API Keys nav item to nav-user.svelte:\",\n \"\",\n API_KEYS_NAV_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create nav-user.svelte with an API Keys entry:\",\n \"\",\n API_KEYS_NAV_SNIPPET,\n].join(\"\\n\");\n\nexport function addItemToNavUser(\n navUserSnippet: string,\n title: string,\n url: string,\n icon: string,\n iconImportPath: string,\n): { newNavUserSnippet: string; wasAdded: boolean } {\n const file = new SvelteFile(navUserSnippet);\n let wasAdded = false;\n\n const tryAdd = (run: (fn: (s: string) => string) => boolean) => {\n if (wasAdded) return;\n run((source) => {\n const result = addNavItemToScript(\n source,\n title,\n url,\n icon,\n iconImportPath,\n );\n if (result.wasAdded) wasAdded = true;\n return result.source;\n });\n };\n\n tryAdd((fn) => file.modifyModuleScript(fn));\n if (!wasAdded) tryAdd((fn) => file.modifyScript(fn));\n\n return { newNavUserSnippet: file.toString(), wasAdded };\n}\n\nexport function modifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const navUserSnippet = fs.readFileSync(navUserPath, \"utf8\");\n if (navUserSnippet.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const { newNavUserSnippet, wasAdded } = addItemToNavUser(\n navUserSnippet,\n \"API Keys\",\n \"/api-keys\",\n \"KeyRoundIcon\",\n \"@lucide/svelte/icons/key-round\",\n );\n\n if (!wasAdded) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(navUserPath, newNavUserSnippet, \"utf8\");\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 { modifyUtils } from \"../../../runtime/modify-utils\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifyNavUser } from \"./modifies/nav-user.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, modifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Modifying nav-user\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, modifyNavUser(navUserPath)));\n\n logger.info(\"Modifying utils.ts\");\n const utilsPath = path.join(options.root, \"src\", \"lib\", \"utils.ts\");\n pushResult(modifyOutcomeToFile(utilsPath, modifyUtils(utilsPath)));\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":";;;;;;;;;;AAMA,IAAMA,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;;;;;AAa7B,SAAgBY,EAAkB,GAAwC;CACxE,IAAI,CAACJ,EAAG,WAAWK,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAa,SAASb;CAAe;CAGxD,IAAMc,IAAiBN,EAAG,aAAaK,GAAiB,MAAM,GAExDE,IAAa,IADCC,EACD,CAAA,CAAQ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ALKC,KAIL3B,EAAG,cAAcsC,GAAaC,GAAmB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAU,SAASjB;CAAa;AAKrD;;;ACvEA,eAAsBkB,EAAS,GAAkB;CAC/C,IAAMC,IAAS/C,EAAUgD,CAAO,GAE1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAInB,KAAMkB,EAAS,KAAKlB,CAAI;CAC9B;CAEA,EAAO,KAAK,2BAA2B;CACvC,IAAMpB,IAAkBJ,EAAK,KAAKyC,EAAQ,MAAM,OAAO,iBAAiB;CAKxE,AAJAE,EACE/C,EAAoBQ,GAAiBD,EAAkBC,CAAe,CAAC,CACzE,GAEAoC,EAAO,KAAK,oBAAoB;CAChC,IAAMH,IAAcrC,EAAK,KACvByC,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAW/C,EAAoByC,GAAaD,EAAcC,CAAW,CAAC,CAAC,GAEvEG,EAAO,KAAK,oBAAoB;CAChC,IAAMI,IAAY5C,EAAK,KAAKyC,EAAQ,MAAM,OAAO,OAAO,UAAU;CAGlE,OAFAE,EAAW/C,EAAoBgD,GAAW9C,EAAY8C,CAAS,CAAC,CAAC,GAE1D;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-kEHEiLBL.js","names":["FAILURE_HINT","NOT_FOUND_HINT","dedent","getLogger","formatLikeSource","addNavItemToScript","modifyOutcomeToFile","SvelteFile","modifyUtils","fs","path","FAILURE_HINT$1","NOT_FOUND_HINT$1","modifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","args","firstArg","optionsObj","apiProp","apiInit","apiObj","apiKeysProp","keysInit","keysObj","API_KEYS_NAV_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","addItemToNavUser","file","navUserSnippet","wasAdded","tryAdd","run","result","source","title","url","icon","iconImportPath","fn","modifyNavUser","navUserPath","newNavUserSnippet","generate","logger","options","modifies","pushResult","utilsPath"],"sources":["../../src/patterns/enable/api-keys/modifies/hooks.server.ts","../../src/patterns/enable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/enable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with API keys in hooks.server.ts:\n\n handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\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: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(\n 0,\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n optionsObj.addPropertyAssignment({\n name: \"api\",\n initializer: `{ enabled: true, apiKeys: { enabled: true } }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (apiProp.getKind() === SyntaxKind.PropertyAssignment) {\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (apiInit && apiInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const enabledProp = apiObj.getProperty(\"enabled\");\n if (!enabledProp) {\n apiObj.addPropertyAssignment({ name: \"enabled\", initializer: \"true\" });\n }\n\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n apiObj.addPropertyAssignment({\n name: \"apiKeys\",\n initializer: `{ enabled: true }`,\n });\n } else if (apiKeysProp.getKind() === SyntaxKind.PropertyAssignment) {\n const keysInit = (\n apiKeysProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (\n keysInit &&\n keysInit.getKind() === SyntaxKind.ObjectLiteralExpression\n ) {\n const keysObj =\n keysInit as import(\"ts-morph\").ObjectLiteralExpression;\n const keysEnabled = keysObj.getProperty(\"enabled\");\n if (!keysEnabled) {\n keysObj.addPropertyAssignment({\n name: \"enabled\",\n initializer: \"true\",\n });\n }\n } else {\n (apiKeysProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `{ enabled: true }`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { addNavItemToScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst API_KEYS_NAV_SNIPPET = [\n \"import KeyRoundIcon from '@lucide/svelte/icons/key-round';\",\n \"\",\n \"// Add to your navUser array:\",\n \"{ title: 'API Keys', url: '/api-keys', icon: KeyRoundIcon }\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Add an API Keys nav item to nav-user.svelte:\",\n \"\",\n API_KEYS_NAV_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create nav-user.svelte with an API Keys entry:\",\n \"\",\n API_KEYS_NAV_SNIPPET,\n].join(\"\\n\");\n\nexport function addItemToNavUser(\n navUserSnippet: string,\n title: string,\n url: string,\n icon: string,\n iconImportPath: string,\n): { newNavUserSnippet: string; wasAdded: boolean } {\n const file = new SvelteFile(navUserSnippet);\n let wasAdded = false;\n\n const tryAdd = (run: (fn: (s: string) => string) => boolean) => {\n if (wasAdded) return;\n run((source) => {\n const result = addNavItemToScript(\n source,\n title,\n url,\n icon,\n iconImportPath,\n );\n if (result.wasAdded) wasAdded = true;\n return result.source;\n });\n };\n\n tryAdd((fn) => file.modifyModuleScript(fn));\n if (!wasAdded) tryAdd((fn) => file.modifyScript(fn));\n\n return { newNavUserSnippet: file.toString(), wasAdded };\n}\n\nexport function modifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const navUserSnippet = fs.readFileSync(navUserPath, \"utf8\");\n if (navUserSnippet.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const { newNavUserSnippet, wasAdded } = addItemToNavUser(\n navUserSnippet,\n \"API Keys\",\n \"/api-keys\",\n \"KeyRoundIcon\",\n \"@lucide/svelte/icons/key-round\",\n );\n\n if (!wasAdded) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(navUserPath, newNavUserSnippet, \"utf8\");\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 { modifyUtils } from \"../../../runtime/modify-utils\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifyNavUser } from \"./modifies/nav-user.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, modifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Modifying nav-user\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, modifyNavUser(navUserPath)));\n\n logger.info(\"Modifying utils.ts\");\n const utilsPath = path.join(options.root, \"src\", \"lib\", \"utils.ts\");\n pushResult(modifyOutcomeToFile(utilsPath, modifyUtils(utilsPath)));\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":";;;;;;;;;;AAMA,IAAMA,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;;;;;AAa7B,SAAgBY,EAAkB,GAAwC;CACxE,IAAI,CAACJ,EAAG,WAAWK,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAa,SAASb;CAAe;CAGxD,IAAMc,IAAiBN,EAAG,aAAaK,GAAiB,MAAM,GAExDE,IAAa,IADCC,EACD,CAAA,CAAQ,oBAAoBH,CAAe,GAExDI,IAAWF,EACd,qBAAqBG,EAAW,c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EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAU,SAASjB;CAAa;AAKrD;;;ACvEA,eAAsBkB,EAAS,GAAkB;CAC/C,IAAMC,IAAS/C,EAAUgD,CAAO,GAE1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAInB,KAAMkB,EAAS,KAAKlB,CAAI;CAC9B;CAEA,EAAO,KAAK,2BAA2B;CACvC,IAAMpB,IAAkBJ,EAAK,KAAKyC,EAAQ,MAAM,OAAO,iBAAiB;CAKxE,AAJAE,EACE/C,EAAoBQ,GAAiBD,EAAkBC,CAAe,CAAC,CACzE,GAEAoC,EAAO,KAAK,oBAAoB;CAChC,IAAMH,IAAcrC,EAAK,KACvByC,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAW/C,EAAoByC,GAAaD,EAAcC,CAAW,CAAC,CAAC,GAEvEG,EAAO,KAAK,oBAAoB;CAChC,IAAMI,IAAY5C,EAAK,KAAKyC,EAAQ,MAAM,OAAO,OAAO,UAAU;CAGlE,OAFAE,EAAW/C,EAAoBgD,GAAW9C,EAAY8C,CAAS,CAAC,CAAC,GAE1D;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,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { t } from "./shared-
|
|
2
|
+
import { t } from "./shared-DIDAkVts.js";
|
|
3
3
|
import { f as n, o as r } from "./ts-morph-helpers-CHI9wAil.js";
|
|
4
|
-
import { r as i } from "./modify-file-
|
|
4
|
+
import { r as i } from "./modify-file-DdXJCMHN.js";
|
|
5
5
|
import { t as a } from "./svelte-file-Dv5-bl79.js";
|
|
6
6
|
import o from "node:fs";
|
|
7
7
|
import s from "node:path";
|
|
@@ -91,4 +91,4 @@ async function f(n) {
|
|
|
91
91
|
//#endregion
|
|
92
92
|
export { f as generate };
|
|
93
93
|
|
|
94
|
-
//# sourceMappingURL=generate.runtime-
|
|
94
|
+
//# sourceMappingURL=generate.runtime-r9Ouwr5B.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-r9Ouwr5B.js","names":["apiObj","getLogger","removeNavItemFromScript","formatLikeSource","modifyOutcomeToFile","SvelteFile","fs","path","unmodifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","firstArg","apiProp","apiInit","apiKeysProp","unmodifyNavUser","navUserPath","source","file","wasRemoved","tryRemove","run","result","src","fn","generate","logger","options","modifies","pushResult","planDropsForCollections"],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\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 if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || 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 || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","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(\"/api-keys\")) {\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 \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\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 type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\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 hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\n );\n\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 const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\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,SAAgBQ,EAAoB,GAAwC;CAC1E,IAAI,CAACF,EAAG,WAAWG,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAiBJ,EAAG,aAAaG,GAAiB,MAAM,GAExDE,IAAa,IADCC,EACD,CAAA,CAAQ,oBAAoBH,CAAe,GAExDI,IAAWF,EACd,qBAAqBG,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,kBAAkB;CACnE,IAAI,CAACF,GAAU,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE1D,IAAM,CAACG,KAAYH,EAAS,aAAa;CACzC,IAAI,CAACG,KAAYA,EAAS,QAAQ,MAAMF,EAAW,yBACjD,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAI7C,IAAMG,IADaD,EAAS,cAAcF,EAAW,uBACrC,CAAA,CAAW,YAAY,KAAK;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,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIX,KAAMU,EAAS,KAAKV,CAAI;CAC9B;CAEA,EAAO,KAAK,2BAA2B;CACvC,IAAMd,IAAkBF,EAAK,KAAKyB,EAAQ,MAAM,OAAO,iBAAiB;CAKxE,AAJAE,EACE9B,EAAoBK,GAAiBD,EAAoBC,CAAe,CAAC,CAC3E,GAEAsB,EAAO,KAAK,2BAA2B;CACvC,IAAMV,IAAcd,EAAK,KACvByB,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAKA,OAJAE,EAAW9B,EAAoBiB,GAAaD,EAAgBC,CAAW,CAAC,CAAC,GAIlE;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAV4Bc,EAAwB,CAAC,UAAU,GAAGH,CAAO;CAW3E;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { i as t, n } from "./pocketbase-
|
|
3
|
-
import { r } from "./modify-file-
|
|
4
|
-
import { i, n as a, o } from "./whatsapp-
|
|
2
|
+
import { i as t, n } from "./pocketbase-uOpghyT5.js";
|
|
3
|
+
import { r } from "./modify-file-DdXJCMHN.js";
|
|
4
|
+
import { i, n as a, o } from "./whatsapp-Dr29ohbb.js";
|
|
5
5
|
import { swapAuthPages as s } from "./auth-pages-jsyDV1GR.js";
|
|
6
6
|
import c from "node:fs";
|
|
7
7
|
import l from "node:path";
|
|
@@ -39,4 +39,4 @@ async function d(d) {
|
|
|
39
39
|
//#endregion
|
|
40
40
|
export { d as generate };
|
|
41
41
|
|
|
42
|
-
//# sourceMappingURL=generate.runtime-
|
|
42
|
+
//# sourceMappingURL=generate.runtime-sALBNh1T.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-sALBNh1T.js","names":["getLogger","withPocketbase","disableWhatsAppAuth","fs","path","DOCS_URL","generate","logger","options","creates","hasWhatsAppPlugin","pb","migrationDelay","file","writeWhatsAppConfigMigration","modifies","outcomes","swapAuthPages","filePath","outcome","modifyOutcomeToFile"],"sources":["../../src/patterns/disable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { migrationDelay, withPocketbase } from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n disableWhatsAppAuth,\n hasWhatsAppPlugin,\n writeWhatsAppConfigMigration,\n} from \"../../enable/whatsapp/runtime/whatsapp\";\nimport { swapAuthPages } from \"../../enable/whatsapp/modifies/auth-pages\";\n\nconst DOCS_URL = \"https://velastack.dev/docs/disable/whatsapp\";\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 // Without the plugin there is no WhatsApp sign-in to turn off.\n if (!(await hasWhatsAppPlugin(pb))) return;\n\n logger.info(\"Turning off WhatsApp sign-in for users\");\n await disableWhatsAppAuth(pb);\n await migrationDelay();\n const file = writeWhatsAppConfigMigration(options, false);\n if (!file) return;\n creates.push({\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n });\n });\n logger.info(\n \"Keeping the phone fields on users, and email optional: they hold your users' data\",\n );\n\n logger.info(\"Taking WhatsApp off the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"disable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of it by hand: ${DOCS_URL}`,\n );\n for (const [filePath, outcome] of outcomes) {\n const file = modifyOutcomeToFile(filePath, outcome);\n if (file) modifies.push(file);\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":";;;;;;;;AAaA,IAAMK,IAAW;AAEjB,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASP,EAAUQ,CAAO,GAC1BC,IAAkB,CAAC;CAsBzB,AApBA,MAAMR,EAAeO,EAAQ,MAAM,OAAO,MAAO;EAE/C,IAAI,CAAE,MAAME,EAAkBC,CAAE,GAAI;EAIpC,AAFAJ,EAAO,KAAK,wCAAwC,GACpD,MAAML,EAAoBS,CAAE,GAC5B,MAAMC,EAAe;EACrB,IAAMC,IAAOC,EAA6BN,GAAS,EAAK;EACxD,AAAKK,KACLJ,EAAQ,KAAK;GACX,MAAMI;GACN,UAAU;GACV,SAASV,EAAG,aAAaU,GAAM,MAAM;GACrC,QAAQ;EACV,CAAC;CACH,CAAC,GACDN,EAAO,KACL,mFACF,GAEAA,EAAO,KAAK,gDAAgD;CAC5D,IAAMQ,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBT,EAAQ,MACR,YACC,MACC,GAAGJ,EAAK,SAASI,EAAQ,MAAMU,CAAQ,EAAE,+GAA+Gb,GAC5J;CACA,KAAK,IAAM,CAACa,GAAUC,MAAYH,GAAU;EAC1C,IAAMH,IAAOO,EAAoBF,GAAUC,CAAO;EAClD,AAAIN,KAAME,EAAS,KAAKF,CAAI;CAC9B;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
|
+
import { _ as t, r as n } from "./ts-morph-helpers-CHI9wAil.js";
|
|
3
|
+
import { t as r } from "./svelte-file-Dv5-bl79.js";
|
|
4
|
+
import i from "node:fs";
|
|
5
|
+
import { Node as a, SyntaxKind as o } from "ts-morph";
|
|
6
|
+
//#region src/patterns/enable/og/modifies/layout.svelte.ts
|
|
7
|
+
var s = "#lib/og/index.js", c = [
|
|
8
|
+
"Pass the meta tags the root src/routes/+layout.svelte renders through withCard.",
|
|
9
|
+
"",
|
|
10
|
+
"Imports for the <script lang=\"ts\"> tag:",
|
|
11
|
+
"",
|
|
12
|
+
e`
|
|
13
|
+
import { page } from '$app/state';
|
|
14
|
+
import { withCard } from '${s}';
|
|
15
|
+
`,
|
|
16
|
+
"",
|
|
17
|
+
"Then wrap what <MetaTags> is given:",
|
|
18
|
+
"",
|
|
19
|
+
"let metaTags = $derived(withCard(deepMerge(data.baseMetaTags, page.data.pageMetaTags), page.url));"
|
|
20
|
+
].join("\n");
|
|
21
|
+
function l(e) {
|
|
22
|
+
let t = e.getDescendantsOfKind(o.VariableDeclaration).find((e) => e.getName() === "metaTags")?.getInitializer();
|
|
23
|
+
return !t || !a.isCallExpression(t) || t.getExpression().getText() !== "$derived" ? null : t.getArguments().length === 1 ? t : null;
|
|
24
|
+
}
|
|
25
|
+
function u(e) {
|
|
26
|
+
if (!i.existsSync(e)) return {
|
|
27
|
+
status: "not-found",
|
|
28
|
+
message: c
|
|
29
|
+
};
|
|
30
|
+
let a = r.fromPath(e), o = a.getScript();
|
|
31
|
+
if (!o) return {
|
|
32
|
+
status: "failed",
|
|
33
|
+
message: c
|
|
34
|
+
};
|
|
35
|
+
if (o.content.includes("withCard(")) return {
|
|
36
|
+
status: "success",
|
|
37
|
+
changed: !1
|
|
38
|
+
};
|
|
39
|
+
let u = !1;
|
|
40
|
+
return a.modifyScript((e) => {
|
|
41
|
+
let { source: r } = t(e, (e) => {
|
|
42
|
+
let t = l(e);
|
|
43
|
+
if (!t) return;
|
|
44
|
+
let [r] = t.getArguments();
|
|
45
|
+
r.replaceWithText(`withCard(${r.getText()}, page.url)`), u = !0, n(e, [{
|
|
46
|
+
namedImports: ["page"],
|
|
47
|
+
moduleSpecifier: "$app/state"
|
|
48
|
+
}, {
|
|
49
|
+
namedImports: ["withCard"],
|
|
50
|
+
moduleSpecifier: s
|
|
51
|
+
}]);
|
|
52
|
+
});
|
|
53
|
+
return u ? r : e;
|
|
54
|
+
}), u ? (a.writeTo(e), {
|
|
55
|
+
status: "success",
|
|
56
|
+
changed: a.hasChanged()
|
|
57
|
+
}) : {
|
|
58
|
+
status: "failed",
|
|
59
|
+
message: c
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { l as n, u as r, s as t };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=layout.svelte-Cb12mxua.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.svelte-Cb12mxua.js","names":["dedent","withInMemoryScript","ensureImports","SvelteFile","fs","MODULE_SPECIFIER","HINT","findMetaTagsDerived","init","sf","SyntaxKind","d","Node","modifyLayoutSvelte","layoutPath","file","script","wrapped","out","source","derived","arg"],"sources":["../../src/patterns/enable/og/modifies/layout.svelte.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node, SyntaxKind, type CallExpression } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport const MODULE_SPECIFIER = \"#lib/og/index.js\";\n\nconst HINT = [\n \"Pass the meta tags the root src/routes/+layout.svelte renders through withCard.\",\n \"\",\n 'Imports for the <script lang=\"ts\"> tag:',\n \"\",\n dedent`\n import { page } from '$app/state';\n import { withCard } from '${MODULE_SPECIFIER}';\n `,\n \"\",\n \"Then wrap what <MetaTags> is given:\",\n \"\",\n \"let metaTags = $derived(withCard(deepMerge(data.baseMetaTags, page.data.pageMetaTags), page.url));\",\n].join(\"\\n\");\n\n/** The `$derived(...)` call that `let metaTags = ...` is initialised with. */\nexport function findMetaTagsDerived(\n sf: import(\"ts-morph\").SourceFile,\n): CallExpression | null {\n const declaration = sf\n .getDescendantsOfKind(SyntaxKind.VariableDeclaration)\n .find((d) => d.getName() === \"metaTags\");\n const init = declaration?.getInitializer();\n if (!init || !Node.isCallExpression(init)) return null;\n if (init.getExpression().getText() !== \"$derived\") return null;\n return init.getArguments().length === 1 ? init : null;\n}\n\n/**\n * Wraps the root layout's `metaTags` in `withCard(..., page.url)`, which swaps\n * the site-wide `/og.jpg` for the page's generated card. Vela's templates all\n * build `metaTags` the same way; a layout that does not gets the snippet to\n * paste instead.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n const script = file.getScript();\n if (!script) return { status: \"failed\", message: HINT };\n if (script.content.includes(\"withCard(\")) {\n return { status: \"success\", changed: false };\n }\n\n let wrapped = false;\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n const derived = findMetaTagsDerived(sf);\n if (!derived) return;\n const [arg] = derived.getArguments();\n arg.replaceWithText(`withCard(${arg.getText()}, page.url)`);\n wrapped = true;\n ensureImports(sf, [\n { namedImports: [\"page\"], moduleSpecifier: \"$app/state\" },\n { namedImports: [\"withCard\"], moduleSpecifier: MODULE_SPECIFIER },\n ]);\n });\n return wrapped ? out : source;\n });\n\n if (!wrapped) return { status: \"failed\", message: HINT };\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n"],"mappings":";;;;;;AAUA,IAAaK,IAAmB,oBAE1BC,IAAO;CACX;CACA;CACA;CACA;CACA,CAAM;;gCAEwBD,EAAiB;;CAE/C;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAGX,SAAgBE,EACd,GACuB;CAIvB,IAAMC,IAHcC,EACjB,qBAAqBC,EAAW,mBAAmB,CAAC,CACpD,MAAM,MAAMC,EAAE,QAAQ,MAAM,UAClB,CAAA,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ared-
|
|
3
|
+
import { n } from "./shared-DIDAkVts.js";
|
|
4
4
|
import { _ as r, s as i } from "./ts-morph-helpers-CHI9wAil.js";
|
|
5
5
|
import a from "node:fs";
|
|
6
6
|
import o from "node:path";
|
|
@@ -50,4 +50,4 @@ function d(e, t) {
|
|
|
50
50
|
//#endregion
|
|
51
51
|
export { l as a, s as i, d as n, c as r, u as t };
|
|
52
52
|
|
|
53
|
-
//# sourceMappingURL=modify-file-
|
|
53
|
+
//# sourceMappingURL=modify-file-DdXJCMHN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-file-
|
|
1
|
+
{"version":3,"file":"modify-file-DdXJCMHN.js","names":["__exportAll","languageFromPath","withInMemoryScript","isEffectivelyEmpty","fs","path","modify_file_exports","envRevertOutcomeToFile","keepMissing","modifyOutcomeToFile","revertOutcomeToFile","language","filePath","outcome","toDeleteEntry","envPath","creates","root","file"],"sources":["../../src/runtime/modify-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, ModifyOutcome } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { toDeleteEntry } from \"../patterns/destroy/shared\";\nimport { isEffectivelyEmpty, withInMemoryScript } from \"./ts-morph-helpers\";\n\nexport function modifyOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): File | null {\n const language = languageFromPath(filePath);\n\n if (outcome.status === \"success\") {\n if (!outcome.changed) return null;\n return {\n path: filePath,\n language,\n content: fs.readFileSync(filePath, \"utf8\"),\n status: \"success\",\n };\n }\n\n const content =\n outcome.status === \"failed\" && fs.existsSync(filePath)\n ? fs.readFileSync(filePath, \"utf8\")\n : \"\";\n\n return {\n path: filePath,\n language,\n content,\n status: outcome.status,\n message: outcome.message,\n };\n}\n\n/**\n * `modifyOutcomeToFile` for a revert that may have taken out everything the\n * file held: a script left with no statements, only comments and whitespace,\n * is reported as a delete. For hooks files a pattern created, or that ended\n * up holding nothing but what patterns put there.\n */\nexport function revertOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(filePath) &&\n withInMemoryScript(fs.readFileSync(filePath, \"utf8\"), isEffectivelyEmpty)\n .result\n ) {\n return { modify: null, delete: toDeleteEntry(filePath) };\n }\n return { modify: modifyOutcomeToFile(filePath, outcome), delete: null };\n}\n\n/**\n * `modifyOutcomeToFile` for a `.env` revert: a file the revert left empty is\n * reported as a delete. The enable pattern most likely created it, and an\n * empty `.env` holds nothing worth keeping.\n */\nexport function envRevertOutcomeToFile(\n envPath: string,\n outcome: ModifyOutcome,\n): { modify: File | null; delete: File | null } {\n if (\n outcome.status === \"success\" &&\n outcome.changed &&\n fs.existsSync(envPath) &&\n fs.readFileSync(envPath, \"utf8\").trim() === \"\"\n ) {\n return { modify: null, delete: toDeleteEntry(envPath) };\n }\n return { modify: modifyOutcomeToFile(envPath, outcome), delete: null };\n}\n\n/**\n * Drop any create that already exists on disk.\n *\n * `writeResult` overwrites an existing create whose content differs and\n * reports it as a modify, which would mean a re-run silently resetting a\n * developer's edits, or a create clobbering a file other patterns have\n * already written to. The file is theirs once it exists; a pattern that has\n * something to add to it does so with a modifier.\n */\nexport function keepMissing(creates: File[], root: string): File[] {\n return creates.filter((file) => !fs.existsSync(path.join(root, file.path)));\n}\n"],"mappings":";;;;;;;;;;;;;AAOA,SAAgBS,EACd,GACA,GACa;CACb,IAAME,IAAWV,EAAiBW,CAAQ;CAiB1C,OAfIC,EAAQ,WAAW,YAChBA,EAAQ,UACN;EACL,MAAMD;EACN;EACA,SAASR,EAAG,aAAaQ,GAAU,MAAM;EACzC,QAAQ;CACV,IAN6B,OAcxB;EACL,MAAMA;EACN;EACA,SAPAC,EAAQ,WAAW,YAAYT,EAAG,WAAWQ,CAAQ,IACjDR,EAAG,aAAaQ,GAAU,MAAM,IAChC;EAMJ,QAAQC,EAAQ;EAChB,SAASA,EAAQ;CACnB;AACF;AAQA,SAAgBH,EACd,GACA,GAC8C;CAU9C,OAREG,EAAQ,WAAW,aACnBA,EAAQ,WACRT,EAAG,WAAWQ,CAAQ,KACtBV,EAAmBE,EAAG,aAAaQ,GAAU,MAAM,GAAGT,CAAkB,CAAC,CACtE,SAEI;EAAE,QAAQ;EAAM,QAAQW,EAAcF,CAAQ;CAAE,IAElD;EAAE,QAAQH,EAAoBG,GAAUC,CAAO;EAAG,QAAQ;CAAK;AACxE;AAOA,SAAgBN,EACd,GACA,GAC8C;CAS9C,OAPEM,EAAQ,WAAW,aACnBA,EAAQ,WACRT,EAAG,WAAWW,CAAO,KACrBX,EAAG,aAAaW,GAAS,MAAM,CAAC,CAAC,KAAK,MAAM,KAErC;EAAE,QAAQ;EAAM,QAAQD,EAAcC,CAAO;CAAE,IAEjD;EAAE,QAAQN,EAAoBM,GAASF,CAAO;EAAG,QAAQ;CAAK;AACvE;AAWA,SAAgBL,EAAY,GAAiB,GAAsB;CACjE,OAAOQ,EAAQ,QAAQ,MAAS,CAACZ,EAAG,WAAWC,EAAK,KAAKY,GAAMC,EAAK,IAAI,CAAC,CAAC;AAC5E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e } from "./rolldown-runtime-5HNE8Q1r.js";
|
|
2
|
-
import { i as t, s as n } from "./constants-
|
|
2
|
+
import { i as t, s as n } from "./constants-8cLxGOB0.js";
|
|
3
3
|
import { existsSync as r, readFileSync as i, readdirSync as a } from "node:fs";
|
|
4
4
|
import o from "node:path";
|
|
5
5
|
import s from "pocketbase";
|
|
@@ -224,4 +224,4 @@ function T(e, t) {
|
|
|
224
224
|
//#endregion
|
|
225
225
|
export { w as i, b as n, v as r, x as t };
|
|
226
226
|
|
|
227
|
-
//# sourceMappingURL=pocketbase-
|
|
227
|
+
//# sourceMappingURL=pocketbase-uOpghyT5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pocketbase-BtN-wL8f.js","names":["__exportAll","DATA_DIR","MIGRATIONS_DIR","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","authWithRetries","getMigrationFile","getPocketbaseMetadata","migrationDelay","withPocketbase","MIGRATION_DELAY_MS","ending","action","collectionName","migrationFile","readdirSync","options","file","metadataPath","cwd","existsSync","readFileSync","authSuccess","attempt","pb","email","password","dir","migrationsDir","metadata","fn","commandArgs","packageManager","detect","resolveCommand","args","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport { DATA_DIR, MIGRATIONS_DIR } from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const commandArgs = [\n \"pocketbase-server\",\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ];\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(\n packageManager,\n \"execute\",\n commandArgs,\n )!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n // Start the PocketBase server process. The package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `pocketbase-server exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAaO,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACzE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACtE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAM;CAAM;CACxE;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CAAM;CACxE;CAAM;CAAM;AACd,CAAC;AAED,SAASC,EAAe,GAA+B;CACrD,OAAO,IAAI,SAAS,GAAS,MAAW;EACtC,IAAMC,IAASH,EAAI,aAAa;EAGhC,AAFAG,EA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,MAAMgB,EACJmB,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAMM,EAAGN,CAAE;CACb,UAAU;EAER,EAAgBa,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
|
|
1
|
+
{"version":3,"file":"pocketbase-uOpghyT5.js","names":["__exportAll","DATA_DIR","MIGRATIONS_DIR","path","PocketBase","spawn","net","BAD_PORTS","osAssignedPort","server","reject","host","resolve","port","freePort","waitForPort","attempts","tryConnect","socket","maxAttempts","describeFetchError","error","cause","waitForHealth","lastFailure","tryHealth","response","url","pocketbase_exports","authWithRetries","getMigrationFile","getPocketbaseMetadata","migrationDelay","withPocketbase","MIGRATION_DELAY_MS","ending","action","collectionName","migrationFile","readdirSync","options","file","metadataPath","cwd","existsSync","readFileSync","authSuccess","attempt","pb","email","password","dir","migrationsDir","metadata","fn","commandArgs","packageManager","detect","resolveCommand","args","detached","serverProcess","command","exited","signal","code","stopProcessTree","child"],"sources":["../../src/runtime/net.ts","../../src/runtime/pocketbase.ts"],"sourcesContent":["import net from \"node:net\";\n\n/**\n * Ports the Fetch spec tells clients to refuse outright\n * (https://fetch.spec.whatwg.org/#port-blocking). Node's `fetch` enforces the\n * list, so a server bound to one of them is unreachable from `waitForHealth`\n * and the PocketBase SDK alike: the request fails with cause \"bad port\"\n * before a connection is even attempted. 10080 sat inside the 10000–19999\n * range ports used to be drawn from, and cost a CI run a 30-second health\n * timeout whenever the draw landed on it.\n */\nexport const BAD_PORTS: ReadonlySet<number> = new Set([\n 1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42, 43, 53, 69, 77, 79,\n 87, 95, 101, 102, 103, 104, 109, 110, 111, 113, 115, 117, 119, 123, 135, 137,\n 139, 143, 161, 179, 389, 427, 465, 512, 513, 514, 515, 526, 530, 531, 532,\n 540, 548, 554, 556, 563, 587, 601, 636, 989, 990, 993, 995, 1719, 1720, 1723,\n 2049, 3659, 4045, 4190, 5060, 5061, 6000, 6566, 6665, 6666, 6667, 6668, 6669,\n 6679, 6697, 10080,\n]);\n\nfunction osAssignedPort(host: string): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.once(\"error\", reject);\n server.listen(0, host, () => {\n const { port } = server.address() as net.AddressInfo;\n server.close(() => resolve(port));\n });\n });\n}\n\n/**\n * A port nothing is listening on right now, taken from the OS's ephemeral\n * range so it neither collides with whatever else the machine runs nor hits\n * `BAD_PORTS`. The port is released again before this resolves, so the\n * caller's server has to bind it promptly.\n */\nexport async function freePort(host: string): Promise<number> {\n for (;;) {\n const port = await osAssignedPort(host);\n if (!BAD_PORTS.has(port)) return port;\n }\n}\n\n// Wait for the port to be available. A cold `npx pocketbase-server` on a CI\n// runner can take well over the five seconds the old default allowed.\nexport function waitForPort(\n port: number,\n host: string,\n maxAttempts = 60,\n): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n\n const tryConnect = () => {\n attempts++;\n\n const socket = new net.Socket();\n\n const onError = () => {\n socket.destroy();\n\n if (attempts === maxAttempts) {\n reject(\n new Error(`Timed out waiting for port ${port} to be available`),\n );\n return;\n }\n\n setTimeout(tryConnect, 500);\n };\n\n socket.once(\"error\", onError);\n\n socket.connect(port, host, () => {\n socket.destroy();\n resolve();\n });\n };\n\n tryConnect();\n });\n}\n\n/**\n * `fetch` wraps the interesting part in `cause`: an errno error for a\n * connection that was refused, or a bare string such as \"bad port\" for a\n * request undici declined to make.\n */\nfunction describeFetchError(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n const { cause } = error as Error & { cause?: unknown };\n if (cause instanceof Error) {\n const code = (cause as NodeJS.ErrnoException).code;\n return code || cause.message || error.message;\n }\n if (cause !== undefined) return String(cause);\n return error.message;\n}\n\n// Wait for the health check to be successful\nexport function waitForHealth(url: string, maxAttempts = 60): Promise<void> {\n return new Promise((resolve, reject) => {\n let attempts = 0;\n let lastFailure = \"no attempt made\";\n\n const tryHealth = async () => {\n attempts++;\n\n try {\n const response = await fetch(`${url}/api/health`);\n if (response.status === 200) {\n resolve();\n return;\n }\n lastFailure = `HTTP ${response.status}`;\n } catch (error) {\n lastFailure = describeFetchError(error);\n }\n\n if (attempts === maxAttempts) {\n reject(\n new Error(\n `Timed out waiting for health check at ${url}/api/health (last attempt: ${lastFailure})`,\n ),\n );\n return;\n }\n\n setTimeout(tryHealth, 500);\n };\n\n tryHealth();\n });\n}\n","import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport PocketBase from \"pocketbase\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport { freePort, waitForPort, waitForHealth } from \"./net\";\nimport type { Options } from \"../core/types\";\nimport { DATA_DIR, MIGRATIONS_DIR } from \"../core/constants\";\n\n/**\n * PocketBase names migration files with a 1-second-resolution Unix timestamp\n * (e.g. `1776099881_created_users.js`). Two schema operations issued in the\n * same wall-clock second produce files that sort alphabetically by their\n * action/collection suffix — which reverses the intended order whenever a\n * later migration depends on an earlier one. Wait out the full second between\n * migration-producing calls so the timestamps stay distinct.\n */\nconst MIGRATION_DELAY_MS = 1100;\n\nexport function migrationDelay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, MIGRATION_DELAY_MS));\n}\n\nexport function getMigrationFile(\n collectionName: string,\n action: \"created\" | \"deleted\" | \"updated\",\n options: Options,\n): string | undefined {\n const ending = `${action}_${collectionName}.js`;\n\n // find last file with ending in migrations dir\n const migrationFiles = readdirSync(\n path.join(options.root, MIGRATIONS_DIR),\n ).filter((file) => file.endsWith(ending));\n\n const migrationFile = migrationFiles.sort().pop();\n\n if (!migrationFile) {\n return undefined;\n }\n\n return path.join(options.root, MIGRATIONS_DIR, migrationFile);\n}\n\nexport function getPocketbaseMetadata(cwd: string): {\n pocketbaseUrl: string;\n vitePort: number;\n} | null {\n const metadataPath = path.join(\n cwd,\n \"node_modules\",\n \".vite\",\n \"_pocketbase_metadata.json\",\n );\n if (existsSync(metadataPath)) {\n return JSON.parse(readFileSync(metadataPath, \"utf8\"));\n }\n return null;\n}\n\nexport async function authWithRetries(\n pb: PocketBase,\n email: string,\n password: string,\n) {\n // Retry authentication up to 3 times with 100ms backoff\n let authSuccess = false;\n for (let attempt = 1; attempt <= 3; attempt++) {\n try {\n await pb.collection(\"_superusers\").authWithPassword(email, password);\n authSuccess = true;\n break;\n } catch {\n if (attempt < 3) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n }\n\n if (!authSuccess) {\n throw new Error(\n \"Failed to authenticate with PocketBase. Check your superuser credentials.\",\n );\n }\n}\n\nexport async function withPocketbase(\n cwd: string,\n fn: (pb: PocketBase) => Promise<void>,\n) {\n const dir = path.join(cwd, DATA_DIR);\n const migrationsDir = path.join(cwd, MIGRATIONS_DIR);\n const host = \"localhost\";\n\n if (!existsSync(dir)) {\n throw new Error(\"PocketBase data directory does not exist\");\n }\n\n // First check if the server is already running by reading node_modules/.vite/_pocketbase_metadata.json\n const metadata = getPocketbaseMetadata(cwd);\n if (metadata) {\n if (metadata.pocketbaseUrl) {\n const pb = new PocketBase(metadata.pocketbaseUrl);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n return;\n }\n }\n\n const port = await freePort(host);\n const commandArgs = [\n \"pocketbase-server\",\n \"serve\",\n \"--dir\",\n dir,\n \"--migrationsDir\",\n migrationsDir,\n \"--http\",\n `${host}:${port}`,\n ];\n\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const { command, args } = resolveCommand(\n packageManager,\n \"execute\",\n commandArgs,\n )!;\n\n // adding --yes as the first parameter helps avoiding the \"Need to install the following packages:\" message\n if (packageManager === \"npm\") args.unshift(\"--yes\");\n\n // Start the PocketBase server process. The package manager wrapper (`npx`)\n // spawns the real binary as a grandchild; put the tree in its own process\n // group so it can be killed as a whole, otherwise `pocketbase serve` outlives\n // us and keeps the data directory open.\n const detached = process.platform !== \"win32\";\n const serverProcess = spawn(command, args, {\n cwd,\n stdio: \"ignore\",\n detached,\n });\n\n // A wrapper that dies before the server listens (missing binary, bad\n // arguments) would otherwise only surface as a port timeout a minute later.\n const exited = new Promise<never>((_, reject) => {\n serverProcess.once(\"exit\", (code, signal) => {\n reject(\n new Error(\n `pocketbase-server exited before listening on ${host}:${port} (${signal ?? `code ${code}`})`,\n ),\n );\n });\n serverProcess.once(\"error\", reject);\n });\n\n try {\n // Wait for the server to be ready\n await Promise.race([\n (async () => {\n await waitForPort(port, host);\n await waitForHealth(`http://${host}:${port}`);\n })(),\n exited,\n ]);\n\n const pb = new PocketBase(`http://${host}:${port}`);\n await authWithRetries(\n pb,\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n );\n await fn(pb);\n } finally {\n // Ensure we always clean up the process tree\n stopProcessTree(serverProcess, detached);\n }\n}\n\nfunction stopProcessTree(\n child: ReturnType<typeof spawn>,\n detached: boolean,\n): void {\n if (detached && child.pid) {\n try {\n process.kill(-child.pid, \"SIGTERM\");\n return;\n } catch {\n // Group already gone or unsupported; fall through to the plain kill.\n }\n }\n child.kill();\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAaO,oBAAiC,IAAI,IAAI;CACpD;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CAAI;CACzE;CAAI;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CACzE;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAA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,GAAGE,EAAK,IAAImD,KAAU,QAAQC,IAAO,EAC5F,CACF;EACF,CAAC,GACDJ,EAAc,KAAK,SAASnD,CAAM;CACpC,CAAC;CAED,IAAI;EAEF,MAAM,QAAQ,KAAK,EAChB,YAAY;GAEX,AADA,MAAMK,EAAYF,GAAMF,CAAI,GAC5B,MAAMY,EAAc,UAAUZ,EAAK,GAAGE,GAAM;EAC9C,EAAA,CAAG,GACHkD,CACF,CAAC;EAED,IAAMf,IAAK,IAAI5C,EAAW,UAAUO,EAAK,GAAGE,GAAM;EAMlD,AALA,MAAMgB,EACJmB,GACA,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BACd,GACA,MAAMM,EAAGN,CAAE;CACb,UAAU;EAER,EAAgBa,GAAeD,CAAQ;CACzC;AACF;AAEA,SAASM,EACP,GACA,GACM;CACN,IAAIN,KAAYO,EAAM,KACpB,IAAI;EACF,QAAQ,KAAK,CAACA,EAAM,KAAK,SAAS;EAClC;CACF,QAAQ,CAER;CAEF,EAAM,KAAK;AACb"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e, s as t } from "./providers-CL9kQ4hp.js";
|
|
2
|
-
import { readEnvVarNames as n } from "./env-vars-
|
|
2
|
+
import { readEnvVarNames as n } from "./env-vars-CNH-ItSY.js";
|
|
3
3
|
import r from "node:fs";
|
|
4
4
|
import i from "node:path";
|
|
5
5
|
//#region src/runtime/providers.ts
|
|
@@ -35,4 +35,4 @@ function s(e) {
|
|
|
35
35
|
//#endregion
|
|
36
36
|
export { a as detectProviders };
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=providers-
|
|
38
|
+
//# sourceMappingURL=providers-ypCW70Mb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers-
|
|
1
|
+
{"version":3,"file":"providers-ypCW70Mb.js","names":["capabilityName","providerMarkers","fs","path","detectProviders","detected","present","markerProbe","root","pattern","patterns","ids","provider","capability","envNames","dependencies","marker","readEnvVarNames","readDependencies","file","pkg"],"sources":["../../src/runtime/providers.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { capabilityName, providerMarkers } from \"../core/providers\";\nimport type { DetectedProviders, Pattern, ProviderMarker } from \"../core/types\";\nimport { readEnvVarNames } from \"./env-vars\";\n\ntype DetectablePattern = Pick<\n Pattern,\n \"slug\" | \"providers\" | \"inheritsProvider\"\n>;\n\n/**\n * The provider in use for each capability, read from what the providers left\n * in the project. Nothing records the choice, so this is the only way to know\n * it. A pattern that inherits its provider is skipped: its files say nothing\n * the capability it is built on doesn't already.\n *\n * The registry is passed in rather than imported, so this module and the\n * package entry don't import each other.\n */\nexport function detectProviders(\n root: string,\n patterns: readonly DetectablePattern[],\n): DetectedProviders {\n const detected: DetectedProviders = { providers: {}, ambiguous: [] };\n const present = markerProbe(root);\n\n for (const pattern of patterns) {\n if (!pattern.providers?.length || pattern.inheritsProvider) continue;\n const ids = pattern.providers\n .filter((provider) => providerMarkers(provider).some(present))\n .map((provider) => provider.id);\n\n const capability = capabilityName(pattern.slug);\n if (ids.length === 1) detected.providers[capability] = ids[0];\n if (ids.length > 1) detected.ambiguous.push({ capability, ids });\n }\n\n return detected;\n}\n\n/** Checks one marker against the project; `src/env.ts` and `package.json` are read once. */\nfunction markerProbe(root: string): (marker: ProviderMarker) => boolean {\n let envNames: Set<string> | undefined;\n let dependencies: Set<string> | undefined;\n\n return (marker) => {\n if (\"env\" in marker) {\n envNames ??= readEnvVarNames(root);\n return envNames.has(marker.env);\n }\n if (\"path\" in marker) {\n return fs.existsSync(path.join(root, marker.path));\n }\n dependencies ??= readDependencies(root);\n return dependencies.has(marker.dependency);\n };\n}\n\nfunction readDependencies(root: string): Set<string> {\n const file = path.join(root, \"package.json\");\n if (!fs.existsSync(file)) return new Set();\n try {\n const pkg = JSON.parse(fs.readFileSync(file, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return new Set([\n ...Object.keys(pkg.dependencies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CAC1C,CAAC;CACH,QAAQ;EACN,uBAAO,IAAI,IAAI;CACjB;AACF"}
|
|
@@ -15,7 +15,7 @@ async function n(e, t) {
|
|
|
15
15
|
exists: !0,
|
|
16
16
|
rowCount: 0
|
|
17
17
|
}));
|
|
18
|
-
let { withPocketbase: n } = await import("./pocketbase-
|
|
18
|
+
let { withPocketbase: n } = await import("./pocketbase-uOpghyT5.js").then((e) => e.r), { planCollectionDrops: r } = await import("./collections-DzwWwFUQ.js").then((e) => e.n), i = [];
|
|
19
19
|
return await n(t.root, async (t) => {
|
|
20
20
|
let n = await r(t, e);
|
|
21
21
|
i.push(...n);
|
|
@@ -24,4 +24,4 @@ async function n(e, t) {
|
|
|
24
24
|
//#endregion
|
|
25
25
|
export { t as n, n as t };
|
|
26
26
|
|
|
27
|
-
//# sourceMappingURL=shared-
|
|
27
|
+
//# sourceMappingURL=shared-DIDAkVts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-DIDAkVts.js","names":["languageFromPath","toDeleteEntry","path","planDropsForCollections","collectionNames","options","n","drops","withPocketbase","plans","planCollectionDrops","pb"],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgBC,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAUD,EAAiBE,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsBC,EACpB,GACA,GAC+B;CAC/B,IAAIC,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAIC,EAAQ,QAAQ,WAClB,OAAOD,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,2BAAA,CAAA,MAAA,MAAAE,EAAA,CAAA,GAClC,EAAE,2BAAwB,MAAM,OAAO,4BAAA,CAAA,MAAA,MAAAA,EAAA,CAAA,GACvCC,IAA8B,CAAC;CAKrC,OAJA,MAAMC,EAAeH,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAMI,IAAQ,MAAMC,EAAoBC,GAAIP,CAAe;EAC3D,EAAM,KAAK,GAAGK,CAAK;CACrB,CAAC,GACMF;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as e } from "./util-BLYliuUK.js";
|
|
2
2
|
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
-
import { i as n } from "./pocketbase-
|
|
3
|
+
import { i as n } from "./pocketbase-uOpghyT5.js";
|
|
4
4
|
import r from "node:fs";
|
|
5
5
|
import i from "node:path";
|
|
6
6
|
//#region src/runtime/site.ts
|
|
@@ -146,4 +146,4 @@ async function b(n, i) {
|
|
|
146
146
|
//#endregion
|
|
147
147
|
export { d as a, p as i, y as n, s as o, f as r, a as s, b as t };
|
|
148
148
|
|
|
149
|
-
//# sourceMappingURL=site-
|
|
149
|
+
//# sourceMappingURL=site-CVtsbO_S.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site-VrqOvuiU.js","names":["languageFromPath","getLogger","withPocketbase","fs","path","sitePath","root","BUSINESS_KEYS","siteModule","declared","business","lines","key","propertyLines","properties","quote","name","url","entry","i","ensureComma","value","SUPPORTED_CURRENCIES","normalizeCurrency","raw","code","normalizeCountry","normalizeCurrencies","entries","codes","home","SITE_OBJECT","withSiteProperty","match","source","body","siteBusiness","text","shape","list","currency","country","m","existingName","options","appName","pb","pkg","ensureSiteFile","file","ensureSiteBusiness","wanted","existing","added","next"],"sources":["../../src/runtime/site.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options } from \"../core/types\";\nimport { getLogger } from \"../core/logger\";\nimport { languageFromPath } from \"../core/util\";\nimport { withPocketbase } from \"./pocketbase\";\n\n/** Where every VelaStack app keeps its name and public URL. */\nexport function sitePath(root: string): string {\n return path.join(root, \"src\", \"lib\", \"site.ts\");\n}\n\n/**\n * What a business declares about itself in `src/lib/site.ts`, next to the\n * app's name: the currency it prices in and is paid in, the country it is in\n * (prices format for it: `es-MX`, not `es`) and the other currencies it shows\n * prices in, as estimates. Every property is optional; a payments provider\n * asks for what it needs.\n */\nexport interface SiteBusiness {\n /** ISO 4217, e.g. `MXN`. */\n currency?: string;\n /** ISO 3166-1 alpha-2, e.g. `MX`. */\n country?: string;\n /** ISO 4217 codes the site also shows prices in; empty means the home currency only. */\n currencies?: string[];\n}\n\ntype BusinessKey = keyof SiteBusiness;\n\nconst BUSINESS_KEYS: BusinessKey[] = [\"currency\", \"country\", \"currencies\"];\n\n/**\n * `src/lib/site.ts` as the CLI templates ship it (`site.template.ts`), with\n * the placeholders filled in, plus whatever the business declares.\n */\nexport function siteModule(\n name: string,\n url = \"http://localhost:5173\",\n business: SiteBusiness | string = {},\n): string {\n // The old third argument was the currency alone.\n const declared: SiteBusiness =\n typeof business === \"string\" ? { currency: business } : business;\n const lines = BUSINESS_KEYS.filter((key) => declared[key] !== undefined).map(\n (key) => propertyLines(key, declared[key]!),\n );\n const properties = [\n `\\tname: ${quote(name)},`,\n `\\turl: ${quote(url)}`,\n ...lines.map((entry) => entry.join(\"\\n\")),\n ];\n return [\n \"/**\",\n \" * Site-wide metadata, and the one place the app's name and public URL live.\",\n \" *\",\n \" * Set `url` to where the site is deployed: canonical links, Open Graph images\",\n \" * and feeds are built from it, including in prerendered pages. With a backend,\",\n \" * `vela dev` and `vela deploy` copy `name` into PocketBase's application name\",\n \" * for the emails it sends, so change it here rather than in the admin panel.\",\n \" */\",\n \"export const site = {\",\n // Every property but the last ends in a comma.\n ...properties.map((entry, i) =>\n i < properties.length - 1 ? ensureComma(entry) : entry,\n ),\n \"};\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction ensureComma(entry: string): string {\n return entry.endsWith(\",\") ? entry : `${entry},`;\n}\n\n/** A property's lines: its doc comment, then `key: value` with no trailing comma. */\nfunction propertyLines(key: BusinessKey, value: string | string[]): string[] {\n switch (key) {\n case \"currency\":\n return [\n \"\\t/** ISO 4217: the currency the business prices in and is paid in. */\",\n `\\tcurrency: ${quote(value as string)}`,\n ];\n case \"country\":\n return [\n \"\\t/** ISO 3166-1: the country the business is in; prices format for it. */\",\n `\\tcountry: ${quote(value as string)}`,\n ];\n case \"currencies\":\n return [\n \"\\t/** Other currencies prices are shown in, as estimates at the day's rate. */\",\n `\\tcurrencies: [${(value as string[]).map(quote).join(\", \")}]`,\n ];\n }\n}\n\nconst SUPPORTED_CURRENCIES = (\n Intl as unknown as {\n supportedValuesOf: (key: \"currency\") => string[];\n }\n).supportedValuesOf(\"currency\");\n\n/** A three-letter code `Intl` knows, upper-cased; anything else is refused. */\nexport function normalizeCurrency(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{3}$/.test(code)) return null;\n // Any well-formed code formats, so ask for the list of real ones. Node has\n // had it since 18; the repo's ES2020 lib types just don't declare it.\n return SUPPORTED_CURRENCIES.includes(code) ? code : null;\n}\n\n/** A two-letter ISO 3166-1 code, upper-cased; anything else is refused. */\nexport function normalizeCountry(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{2}$/.test(code)) return null;\n // `Intl.DisplayNames` knows every region; an unknown one comes back as is.\n const names = new Intl.DisplayNames([\"en\"], { type: \"region\" });\n return names.of(code) !== code ? code : null;\n}\n\n/**\n * A list of currency codes, from an array or a comma-separated string,\n * upper-cased and deduplicated; `null` when any entry is not a currency.\n * `home` is left out: the business's own currency is never a display one.\n */\nexport function normalizeCurrencies(\n raw: unknown,\n home?: string,\n): string[] | null {\n const entries = Array.isArray(raw)\n ? raw\n : typeof raw === \"string\"\n ? raw.split(/[,\\s]+/)\n : null;\n if (!entries) return null;\n const codes: string[] = [];\n for (const entry of entries) {\n if (entry === \"\" || entry === undefined) continue;\n const code = normalizeCurrency(entry);\n if (!code) return null;\n if (code !== home && !codes.includes(code)) codes.push(code);\n }\n return codes;\n}\n\nconst SITE_OBJECT = /export const site = \\{\\n([\\s\\S]*?)\\n\\};/;\n\n/**\n * `src/lib/site.ts` with `key` added as the object's last property, or\n * `null` when it already has one (a project's declaration is never changed\n * behind its back) or has no `export const site = { ... };` to add it to.\n */\nexport function withSiteProperty(\n source: string,\n key: BusinessKey,\n value: string | string[],\n): string | null {\n const match = SITE_OBJECT.exec(source);\n if (!match || new RegExp(`^\\\\s*${key}\\\\s*:`, \"m\").test(match[1])) return null;\n const body = match[1].replace(/,?\\s*$/, \",\");\n return source.replace(\n match[0],\n `export const site = {\\n${body}\\n${propertyLines(key, value).join(\"\\n\")}\\n};`,\n );\n}\n\n/** `withSiteProperty` for the currency, as the Phase 1.5 code called it. */\nexport function withSiteCurrency(\n source: string,\n currency: string,\n): string | null {\n return withSiteProperty(source, \"currency\", currency);\n}\n\n/** What `src/lib/site.ts` declares about the business, if anything. */\nexport function siteBusiness(root: string): SiteBusiness {\n let source: string;\n try {\n source = fs.readFileSync(sitePath(root), \"utf8\");\n } catch {\n return {};\n }\n const text = (key: string, shape: string) =>\n new RegExp(`^\\\\s*${key}\\\\s*:\\\\s*['\"](${shape})['\"]`, \"m\").exec(source)?.[1];\n const list = /^\\s*currencies\\s*:\\s*\\[([^\\]]*)\\]/m.exec(source)?.[1];\n const business: SiteBusiness = {};\n const currency = text(\"currency\", \"[A-Za-z]{3}\");\n if (currency) business.currency = currency;\n const country = text(\"country\", \"[A-Za-z]{2}\");\n if (country) business.country = country;\n if (list !== undefined) {\n business.currencies = [...list.matchAll(/['\"]([A-Za-z]{3})['\"]/g)].map(\n (m) => m[1],\n );\n }\n return business;\n}\n\n/** The currency `src/lib/site.ts` declares, if any. */\nexport function siteCurrency(root: string): string | null {\n return siteBusiness(root).currency ?? null;\n}\n\n/** Single-quoted, as the templates write their strings. */\nfunction quote(value: string): string {\n return `'${value.replace(/\\\\/g, \"\\\\\\\\\").replace(/'/g, \"\\\\'\")}'`;\n}\n\n/**\n * The name a project created before `site.ts` existed already goes by.\n *\n * Those projects kept it in PocketBase's settings, so that is asked first; the\n * package name is the fallback for a project without a backend, or one whose\n * database can't be reached.\n */\nasync function existingName(options: Options): Promise<string> {\n if (options.features.backend) {\n try {\n let appName: unknown;\n await withPocketbase(options.root, async (pb) => {\n const settings = (await pb.settings.getAll()) as {\n meta?: { appName?: unknown };\n };\n appName = settings.meta?.appName;\n });\n if (typeof appName === \"string\" && appName.trim()) return appName;\n } catch {\n // No database to ask; fall through to package.json.\n }\n }\n\n try {\n const pkg = JSON.parse(\n fs.readFileSync(path.join(options.root, \"package.json\"), \"utf8\"),\n ) as { name?: unknown };\n if (typeof pkg.name === \"string\" && pkg.name.trim()) return pkg.name;\n } catch {\n // No package.json to name the site after; the placeholder stands.\n }\n return \"My App\";\n}\n\n/**\n * Create `src/lib/site.ts` for a pattern whose files import `#lib/site.js`, when\n * the project doesn't have one yet. Every template ships it; projects created\n * before that read the app name from `locals.meta` instead.\n *\n * Returns null when the file exists, so an existing one is never overwritten.\n */\nexport async function ensureSiteFile(options: Options): Promise<File | null> {\n const file = sitePath(options.root);\n if (fs.existsSync(file)) return null;\n\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options)),\n status: \"success\",\n };\n}\n\n/**\n * Make `src/lib/site.ts` declare what the business says about itself: create\n * the file with it, or add the properties an existing one lacks. A property\n * already there is kept, whatever `business` says; the result says what the\n * file declares after the call, and the file to write, if anything changed.\n */\nexport async function ensureSiteBusiness(\n options: Options,\n business: SiteBusiness,\n): Promise<{ file: File | null; business: SiteBusiness }> {\n const file = sitePath(options.root);\n const wanted = BUSINESS_KEYS.filter((key) => business[key] !== undefined);\n if (!fs.existsSync(file)) {\n if (wanted.length === 0) return { file: null, business: {} };\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options), undefined, business),\n status: \"success\",\n },\n business,\n };\n }\n\n const existing = siteBusiness(options.root);\n let source = fs.readFileSync(file, \"utf8\");\n const added: string[] = [];\n for (const key of wanted) {\n if (existing[key] !== undefined) continue;\n const next = withSiteProperty(source, key, business[key]!);\n if (next === null) continue;\n source = next;\n added.push(key);\n (existing as Record<string, unknown>)[key] = business[key];\n }\n if (added.length === 0) return { file: null, business: existing };\n getLogger(options).info(`Adding ${added.join(\", \")} to src/lib/site.ts`);\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: source,\n status: \"success\",\n },\n business: existing,\n };\n}\n\n/** `ensureSiteBusiness` for the currency alone, as the Phase 1.5 code called it. */\nexport async function ensureSiteCurrency(\n options: Options,\n currency: string,\n): Promise<{ file: File | null; currency: string }> {\n const { file, business } = await ensureSiteBusiness(options, { currency });\n return { file, currency: business.currency ?? currency };\n}\n"],"mappings":";;;;;;AAQA,SAAgBK,EAAS,GAAsB;CAC7C,OAAOD,EAAK,KAAKE,GAAM,OAAO,OAAO,SAAS;AAChD;AAoBA,IAAMC,IAA+B;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AASzC,EAAW,MAAMmC,EAAaC,CAAO,CAAC;EAC/C,QAAQ;CACV;AACF;AAQA,eAAsBM,EACpB,GACA,GACwD;CACxD,IAAMD,IAAO5C,EAASuC,EAAQ,IAAI,GAC5BO,IAAS5C,EAAc,QAAQ,MAAQG,EAASE,OAAS,KAAA,CAAS;CACxE,IAAI,CAACT,EAAG,WAAW8C,CAAI,GAGrB,OAFIE,EAAO,WAAW,IAAU;EAAE,MAAM;EAAM,UAAU,CAAC;CAAE,KAC3DlD,EAAU2C,CAAO,CAAC,CAAC,KAAK,0BAA0B,GAC3C;EACL,MAAM;GACJ,MAAMK;GACN,UAAUjD,EAAiBiD,CAAI;GAC/B,SAASzC,EAAW,MAAMmC,EAAaC,CAAO,GAAG,KAAA,GAAWlC,CAAQ;GACpE,QAAQ;EACV;EACA;CACF;CAGF,IAAM0C,IAAWhB,EAAaQ,EAAQ,IAAI,GACtCV,IAAS/B,EAAG,aAAa8C,GAAM,MAAM,GACnCI,IAAkB,CAAC;CACzB,KAAK,IAAMzC,KAAOuC,GAAQ;EACxB,IAAIC,EAASxC,OAAS,KAAA,GAAW;EACjC,IAAM0C,IAAOtB,EAAiBE,GAAQtB,GAAKF,EAASE,EAAK;EACzD,AAAI0C,MAAS,SACb,IAASA,GACTD,EAAM,KAAKzC,CAAG,GACd,EAAsCA,KAAOF,EAASE;CACxD;CAGA,OAFIyC,EAAM,WAAW,IAAU;EAAE,MAAM;EAAM,UAAUD;CAAS,KAChEnD,EAAU2C,CAAO,CAAC,CAAC,KAAK,UAAUS,EAAM,KAAK,IAAI,EAAE,oBAAoB,GAChE;EACL,MAAM;GACJ,MAAMJ;GACN,UAAUjD,EAAiBiD,CAAI;GAC/B,SAASf;GACT,QAAQ;EACV;EACA,UAAUkB;CACZ;AACF"}
|
|
1
|
+
{"version":3,"file":"site-CVtsbO_S.js","names":["languageFromPath","getLogger","withPocketbase","fs","path","sitePath","root","BUSINESS_KEYS","siteModule","declared","business","lines","key","propertyLines","properties","quote","name","url","entry","i","ensureComma","value","SUPPORTED_CURRENCIES","normalizeCurrency","raw","code","normalizeCountry","normalizeCurrencies","entries","codes","home","SITE_OBJECT","withSiteProperty","match","source","body","siteBusiness","text","shape","list","currency","country","m","existingName","options","appName","pb","pkg","ensureSiteFile","file","ensureSiteBusiness","wanted","existing","added","next"],"sources":["../../src/runtime/site.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options } from \"../core/types\";\nimport { getLogger } from \"../core/logger\";\nimport { languageFromPath } from \"../core/util\";\nimport { withPocketbase } from \"./pocketbase\";\n\n/** Where every VelaStack app keeps its name and public URL. */\nexport function sitePath(root: string): string {\n return path.join(root, \"src\", \"lib\", \"site.ts\");\n}\n\n/**\n * What a business declares about itself in `src/lib/site.ts`, next to the\n * app's name: the currency it prices in and is paid in, the country it is in\n * (prices format for it: `es-MX`, not `es`) and the other currencies it shows\n * prices in, as estimates. Every property is optional; a payments provider\n * asks for what it needs.\n */\nexport interface SiteBusiness {\n /** ISO 4217, e.g. `MXN`. */\n currency?: string;\n /** ISO 3166-1 alpha-2, e.g. `MX`. */\n country?: string;\n /** ISO 4217 codes the site also shows prices in; empty means the home currency only. */\n currencies?: string[];\n}\n\ntype BusinessKey = keyof SiteBusiness;\n\nconst BUSINESS_KEYS: BusinessKey[] = [\"currency\", \"country\", \"currencies\"];\n\n/**\n * `src/lib/site.ts` as the CLI templates ship it (`site.template.ts`), with\n * the placeholders filled in, plus whatever the business declares.\n */\nexport function siteModule(\n name: string,\n url = \"http://localhost:5173\",\n business: SiteBusiness | string = {},\n): string {\n // The old third argument was the currency alone.\n const declared: SiteBusiness =\n typeof business === \"string\" ? { currency: business } : business;\n const lines = BUSINESS_KEYS.filter((key) => declared[key] !== undefined).map(\n (key) => propertyLines(key, declared[key]!),\n );\n const properties = [\n `\\tname: ${quote(name)},`,\n `\\turl: ${quote(url)}`,\n ...lines.map((entry) => entry.join(\"\\n\")),\n ];\n return [\n \"/**\",\n \" * Site-wide metadata, and the one place the app's name and public URL live.\",\n \" *\",\n \" * Set `url` to where the site is deployed: canonical links, Open Graph images\",\n \" * and feeds are built from it, including in prerendered pages. With a backend,\",\n \" * `vela dev` and `vela deploy` copy `name` into PocketBase's application name\",\n \" * for the emails it sends, so change it here rather than in the admin panel.\",\n \" */\",\n \"export const site = {\",\n // Every property but the last ends in a comma.\n ...properties.map((entry, i) =>\n i < properties.length - 1 ? ensureComma(entry) : entry,\n ),\n \"};\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction ensureComma(entry: string): string {\n return entry.endsWith(\",\") ? entry : `${entry},`;\n}\n\n/** A property's lines: its doc comment, then `key: value` with no trailing comma. */\nfunction propertyLines(key: BusinessKey, value: string | string[]): string[] {\n switch (key) {\n case \"currency\":\n return [\n \"\\t/** ISO 4217: the currency the business prices in and is paid in. */\",\n `\\tcurrency: ${quote(value as string)}`,\n ];\n case \"country\":\n return [\n \"\\t/** ISO 3166-1: the country the business is in; prices format for it. */\",\n `\\tcountry: ${quote(value as string)}`,\n ];\n case \"currencies\":\n return [\n \"\\t/** Other currencies prices are shown in, as estimates at the day's rate. */\",\n `\\tcurrencies: [${(value as string[]).map(quote).join(\", \")}]`,\n ];\n }\n}\n\nconst SUPPORTED_CURRENCIES = (\n Intl as unknown as {\n supportedValuesOf: (key: \"currency\") => string[];\n }\n).supportedValuesOf(\"currency\");\n\n/** A three-letter code `Intl` knows, upper-cased; anything else is refused. */\nexport function normalizeCurrency(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{3}$/.test(code)) return null;\n // Any well-formed code formats, so ask for the list of real ones. Node has\n // had it since 18; the repo's ES2020 lib types just don't declare it.\n return SUPPORTED_CURRENCIES.includes(code) ? code : null;\n}\n\n/** A two-letter ISO 3166-1 code, upper-cased; anything else is refused. */\nexport function normalizeCountry(raw: unknown): string | null {\n if (typeof raw !== \"string\") return null;\n const code = raw.trim().toUpperCase();\n if (!/^[A-Z]{2}$/.test(code)) return null;\n // `Intl.DisplayNames` knows every region; an unknown one comes back as is.\n const names = new Intl.DisplayNames([\"en\"], { type: \"region\" });\n return names.of(code) !== code ? code : null;\n}\n\n/**\n * A list of currency codes, from an array or a comma-separated string,\n * upper-cased and deduplicated; `null` when any entry is not a currency.\n * `home` is left out: the business's own currency is never a display one.\n */\nexport function normalizeCurrencies(\n raw: unknown,\n home?: string,\n): string[] | null {\n const entries = Array.isArray(raw)\n ? raw\n : typeof raw === \"string\"\n ? raw.split(/[,\\s]+/)\n : null;\n if (!entries) return null;\n const codes: string[] = [];\n for (const entry of entries) {\n if (entry === \"\" || entry === undefined) continue;\n const code = normalizeCurrency(entry);\n if (!code) return null;\n if (code !== home && !codes.includes(code)) codes.push(code);\n }\n return codes;\n}\n\nconst SITE_OBJECT = /export const site = \\{\\n([\\s\\S]*?)\\n\\};/;\n\n/**\n * `src/lib/site.ts` with `key` added as the object's last property, or\n * `null` when it already has one (a project's declaration is never changed\n * behind its back) or has no `export const site = { ... };` to add it to.\n */\nexport function withSiteProperty(\n source: string,\n key: BusinessKey,\n value: string | string[],\n): string | null {\n const match = SITE_OBJECT.exec(source);\n if (!match || new RegExp(`^\\\\s*${key}\\\\s*:`, \"m\").test(match[1])) return null;\n const body = match[1].replace(/,?\\s*$/, \",\");\n return source.replace(\n match[0],\n `export const site = {\\n${body}\\n${propertyLines(key, value).join(\"\\n\")}\\n};`,\n );\n}\n\n/** `withSiteProperty` for the currency, as the Phase 1.5 code called it. */\nexport function withSiteCurrency(\n source: string,\n currency: string,\n): string | null {\n return withSiteProperty(source, \"currency\", currency);\n}\n\n/** What `src/lib/site.ts` declares about the business, if anything. */\nexport function siteBusiness(root: string): SiteBusiness {\n let source: string;\n try {\n source = fs.readFileSync(sitePath(root), \"utf8\");\n } catch {\n return {};\n }\n const text = (key: string, shape: string) =>\n new RegExp(`^\\\\s*${key}\\\\s*:\\\\s*['\"](${shape})['\"]`, \"m\").exec(source)?.[1];\n const list = /^\\s*currencies\\s*:\\s*\\[([^\\]]*)\\]/m.exec(source)?.[1];\n const business: SiteBusiness = {};\n const currency = text(\"currency\", \"[A-Za-z]{3}\");\n if (currency) business.currency = currency;\n const country = text(\"country\", \"[A-Za-z]{2}\");\n if (country) business.country = country;\n if (list !== undefined) {\n business.currencies = [...list.matchAll(/['\"]([A-Za-z]{3})['\"]/g)].map(\n (m) => m[1],\n );\n }\n return business;\n}\n\n/** The currency `src/lib/site.ts` declares, if any. */\nexport function siteCurrency(root: string): string | null {\n return siteBusiness(root).currency ?? null;\n}\n\n/** Single-quoted, as the templates write their strings. */\nfunction quote(value: string): string {\n return `'${value.replace(/\\\\/g, \"\\\\\\\\\").replace(/'/g, \"\\\\'\")}'`;\n}\n\n/**\n * The name a project created before `site.ts` existed already goes by.\n *\n * Those projects kept it in PocketBase's settings, so that is asked first; the\n * package name is the fallback for a project without a backend, or one whose\n * database can't be reached.\n */\nasync function existingName(options: Options): Promise<string> {\n if (options.features.backend) {\n try {\n let appName: unknown;\n await withPocketbase(options.root, async (pb) => {\n const settings = (await pb.settings.getAll()) as {\n meta?: { appName?: unknown };\n };\n appName = settings.meta?.appName;\n });\n if (typeof appName === \"string\" && appName.trim()) return appName;\n } catch {\n // No database to ask; fall through to package.json.\n }\n }\n\n try {\n const pkg = JSON.parse(\n fs.readFileSync(path.join(options.root, \"package.json\"), \"utf8\"),\n ) as { name?: unknown };\n if (typeof pkg.name === \"string\" && pkg.name.trim()) return pkg.name;\n } catch {\n // No package.json to name the site after; the placeholder stands.\n }\n return \"My App\";\n}\n\n/**\n * Create `src/lib/site.ts` for a pattern whose files import `#lib/site.js`, when\n * the project doesn't have one yet. Every template ships it; projects created\n * before that read the app name from `locals.meta` instead.\n *\n * Returns null when the file exists, so an existing one is never overwritten.\n */\nexport async function ensureSiteFile(options: Options): Promise<File | null> {\n const file = sitePath(options.root);\n if (fs.existsSync(file)) return null;\n\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options)),\n status: \"success\",\n };\n}\n\n/**\n * Make `src/lib/site.ts` declare what the business says about itself: create\n * the file with it, or add the properties an existing one lacks. A property\n * already there is kept, whatever `business` says; the result says what the\n * file declares after the call, and the file to write, if anything changed.\n */\nexport async function ensureSiteBusiness(\n options: Options,\n business: SiteBusiness,\n): Promise<{ file: File | null; business: SiteBusiness }> {\n const file = sitePath(options.root);\n const wanted = BUSINESS_KEYS.filter((key) => business[key] !== undefined);\n if (!fs.existsSync(file)) {\n if (wanted.length === 0) return { file: null, business: {} };\n getLogger(options).info(\"Creating src/lib/site.ts\");\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: siteModule(await existingName(options), undefined, business),\n status: \"success\",\n },\n business,\n };\n }\n\n const existing = siteBusiness(options.root);\n let source = fs.readFileSync(file, \"utf8\");\n const added: string[] = [];\n for (const key of wanted) {\n if (existing[key] !== undefined) continue;\n const next = withSiteProperty(source, key, business[key]!);\n if (next === null) continue;\n source = next;\n added.push(key);\n (existing as Record<string, unknown>)[key] = business[key];\n }\n if (added.length === 0) return { file: null, business: existing };\n getLogger(options).info(`Adding ${added.join(\", \")} to src/lib/site.ts`);\n return {\n file: {\n path: file,\n language: languageFromPath(file),\n content: source,\n status: \"success\",\n },\n business: existing,\n };\n}\n\n/** `ensureSiteBusiness` for the currency alone, as the Phase 1.5 code called it. */\nexport async function ensureSiteCurrency(\n options: Options,\n currency: string,\n): Promise<{ file: File | null; currency: string }> {\n const { file, business } = await ensureSiteBusiness(options, { currency });\n return { file, currency: business.currency ?? currency };\n}\n"],"mappings":";;;;;;AAQA,SAAgBK,EAAS,GAAsB;CAC7C,OAAOD,EAAK,KAAKE,GAAM,OAAO,OAAO,SAAS;AAChD;AAoBA,IAAMC,IAA+B;CAAC;CAAY;CAAW;AAAY;AAMzE,SAAgBC,EACd,GACA,IAAM,yBACN,IAAkC,CAAC,GAC3B;CAER,IAAMC,IACJ,OAAOC,KAAa,WAAW,EAAE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EAAQ,IAAI,GAC5BO,IAAS5C,EAAc,QAAQ,MAAQG,EAASE,OAAS,KAAA,CAAS;CACxE,IAAI,CAACT,EAAG,WAAW8C,CAAI,GAGrB,OAFIE,EAAO,WAAW,IAAU;EAAE,MAAM;EAAM,UAAU,CAAC;CAAE,KAC3DlD,EAAU2C,CAAO,CAAC,CAAC,KAAK,0BAA0B,GAC3C;EACL,MAAM;GACJ,MAAMK;GACN,UAAUjD,EAAiBiD,CAAI;GAC/B,SAASzC,EAAW,MAAMmC,EAAaC,CAAO,GAAG,KAAA,GAAWlC,CAAQ;GACpE,QAAQ;EACV;EACA;CACF;CAGF,IAAM0C,IAAWhB,EAAaQ,EAAQ,IAAI,GACtCV,IAAS/B,EAAG,aAAa8C,GAAM,MAAM,GACnCI,IAAkB,CAAC;CACzB,KAAK,IAAMzC,KAAOuC,GAAQ;EACxB,IAAIC,EAASxC,OAAS,KAAA,GAAW;EACjC,IAAM0C,IAAOtB,EAAiBE,GAAQtB,GAAKF,EAASE,EAAK;EACzD,AAAI0C,MAAS,SACb,IAASA,GACTD,EAAM,KAAKzC,CAAG,GACd,EAAsCA,KAAOF,EAASE;CACxD;CAGA,OAFIyC,EAAM,WAAW,IAAU;EAAE,MAAM;EAAM,UAAUD;CAAS,KAChEnD,EAAU2C,CAAO,CAAC,CAAC,KAAK,UAAUS,EAAM,KAAK,IAAI,EAAE,oBAAoB,GAChE;EACL,MAAM;GACJ,MAAMJ;GACN,UAAUjD,EAAiBiD,CAAI;GAC/B,SAASf;GACT,QAAQ;EACV;EACA,UAAUkB;CACZ;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./rolldown-runtime-5HNE8Q1r.js";
|
|
2
2
|
import { r as t, t as n } from "./errors-DR3gF_7a.js";
|
|
3
3
|
import { n as r } from "./lib-specifier-Cngo1zF_.js";
|
|
4
|
-
import {
|
|
4
|
+
import { p as i } from "./constants-8cLxGOB0.js";
|
|
5
5
|
import { existsSync as a, readFileSync as o } from "node:fs";
|
|
6
6
|
import s from "node:path";
|
|
7
7
|
var c = 1e4;
|
|
@@ -124,4 +124,4 @@ function T(e, t) {
|
|
|
124
124
|
//#endregion
|
|
125
125
|
export { f as a, u as i, v as n, _ as r, T as t };
|
|
126
126
|
|
|
127
|
-
//# sourceMappingURL=table-core-
|
|
127
|
+
//# sourceMappingURL=table-core-CUGp4Rf2.js.map
|