@velastack/patterns 0.15.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/_page-BFUn0CG1.js +5 -0
- package/dist/chunks/{_page-6d3DCr0p.js.map → _page-BFUn0CG1.js.map} +1 -1
- package/dist/chunks/auth-pages-D8n8gfCL.js +311 -0
- package/dist/chunks/auth-pages-D8n8gfCL.js.map +1 -0
- package/dist/chunks/{collections-FKsKGtaH.js → collections-Daxlnbm0.js} +2 -2
- package/dist/chunks/{collections-FKsKGtaH.js.map → collections-Daxlnbm0.js.map} +1 -1
- package/dist/chunks/{constants-BHuzzsKu.js → constants-E1I-__KI.js} +20 -20
- package/dist/chunks/{constants-BHuzzsKu.js.map → constants-E1I-__KI.js.map} +1 -1
- package/dist/chunks/{currency.server-DRuEFc6D.js → currency.server-BkzwY17R.js} +2 -2
- package/dist/chunks/{currency.server-DRuEFc6D.js.map → currency.server-BkzwY17R.js.map} +1 -1
- package/dist/chunks/{env-vars-BcHu8247.js → env-vars-C3TSZc4f.js} +3 -3
- package/dist/chunks/{env-vars-BcHu8247.js.map → env-vars-C3TSZc4f.js.map} +1 -1
- package/dist/chunks/{generate-CXAKf1Hh.js → generate-CAYM7OUF.js} +2 -2
- package/dist/chunks/{generate-CXAKf1Hh.js.map → generate-CAYM7OUF.js.map} +1 -1
- package/dist/chunks/{generate-rcDj36TD.js → generate-CL7wG0ZC.js} +3 -3
- package/dist/chunks/{generate-rcDj36TD.js.map → generate-CL7wG0ZC.js.map} +1 -1
- package/dist/chunks/{generate-CkfJrlEg.js → generate-CbchamhA.js} +3 -3
- package/dist/chunks/{generate-CkfJrlEg.js.map → generate-CbchamhA.js.map} +1 -1
- package/dist/chunks/{generate-9O0VdZOl.js → generate-DI58vuk1.js} +2 -2
- package/dist/chunks/{generate-9O0VdZOl.js.map → generate-DI58vuk1.js.map} +1 -1
- package/dist/chunks/{generate-a3U8uDzW.js → generate-DR2wkVPY.js} +2 -2
- package/dist/chunks/{generate-a3U8uDzW.js.map → generate-DR2wkVPY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BmdO8oKV.js → generate.runtime-B11mOr45.js} +3 -3
- package/dist/chunks/{generate.runtime-BmdO8oKV.js.map → generate.runtime-B11mOr45.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BDVPJJbh.js → generate.runtime-B1Y2JrGW.js} +5 -5
- package/dist/chunks/{generate.runtime-BDVPJJbh.js.map → generate.runtime-B1Y2JrGW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cxa24AOd.js → generate.runtime-B7VubPTW.js} +3 -3
- package/dist/chunks/{generate.runtime-Cxa24AOd.js.map → generate.runtime-B7VubPTW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DsW0Q5S5.js → generate.runtime-BCv4F1Wm.js} +5 -5
- package/dist/chunks/{generate.runtime-DsW0Q5S5.js.map → generate.runtime-BCv4F1Wm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-COo85dGX.js → generate.runtime-BEWp57Y7.js} +2 -2
- package/dist/chunks/{generate.runtime-COo85dGX.js.map → generate.runtime-BEWp57Y7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BKsrh3ZN.js → generate.runtime-BH6hHygm.js} +3 -3
- package/dist/chunks/{generate.runtime-BKsrh3ZN.js.map → generate.runtime-BH6hHygm.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D7EETq9M.js → generate.runtime-BL6DpWFI.js} +3 -3
- package/dist/chunks/{generate.runtime-D7EETq9M.js.map → generate.runtime-BL6DpWFI.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dp3x08St.js → generate.runtime-BRV9hIl5.js} +2 -2
- package/dist/chunks/{generate.runtime-Dp3x08St.js.map → generate.runtime-BRV9hIl5.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CGbSe_nd.js → generate.runtime-BRcP6sFt.js} +2 -2
- package/dist/chunks/{generate.runtime-CGbSe_nd.js.map → generate.runtime-BRcP6sFt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DcBEbV-k.js → generate.runtime-Bhs7ttZS.js} +2 -2
- package/dist/chunks/{generate.runtime-DcBEbV-k.js.map → generate.runtime-Bhs7ttZS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BGLekCHZ.js → generate.runtime-BjrtdoYE.js} +2 -2
- package/dist/chunks/{generate.runtime-BGLekCHZ.js.map → generate.runtime-BjrtdoYE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CtV9Gn9T.js → generate.runtime-Bo_s7gYB.js} +2 -2
- package/dist/chunks/{generate.runtime-CtV9Gn9T.js.map → generate.runtime-Bo_s7gYB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CnGVlvxN.js → generate.runtime-Bs77Oc8P.js} +3 -3
- package/dist/chunks/{generate.runtime-CnGVlvxN.js.map → generate.runtime-Bs77Oc8P.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B5SP9iyN.js → generate.runtime-C3IswX7B.js} +2 -2
- package/dist/chunks/{generate.runtime-B5SP9iyN.js.map → generate.runtime-C3IswX7B.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DtcKbzOm.js → generate.runtime-C90_2L-8.js} +3 -3
- package/dist/chunks/{generate.runtime-DtcKbzOm.js.map → generate.runtime-C90_2L-8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-As1It8o7.js → generate.runtime-CDY0Ot_t.js} +6 -6
- package/dist/chunks/{generate.runtime-As1It8o7.js.map → generate.runtime-CDY0Ot_t.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CI_rUVZo.js → generate.runtime-CZMVPVjS.js} +6 -6
- package/dist/chunks/{generate.runtime-CI_rUVZo.js.map → generate.runtime-CZMVPVjS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BYhWm9JA.js → generate.runtime-C_hrLPD4.js} +3 -3
- package/dist/chunks/{generate.runtime-BYhWm9JA.js.map → generate.runtime-C_hrLPD4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BKA41qV0.js → generate.runtime-CdZ3GzPS.js} +6 -6
- package/dist/chunks/{generate.runtime-BKA41qV0.js.map → generate.runtime-CdZ3GzPS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cqbsn5Ov.js → generate.runtime-ChSVP7cD.js} +6 -6
- package/dist/chunks/{generate.runtime-Cqbsn5Ov.js.map → generate.runtime-ChSVP7cD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BL7O2fy8.js → generate.runtime-Cs73i6Zf.js} +2 -2
- package/dist/chunks/{generate.runtime-BL7O2fy8.js.map → generate.runtime-Cs73i6Zf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C7NexMXs.js → generate.runtime-D7KYlnvb.js} +3 -3
- package/dist/chunks/{generate.runtime-C7NexMXs.js.map → generate.runtime-D7KYlnvb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CTQvLaU0.js → generate.runtime-DG9LRwbt.js} +3 -3
- package/dist/chunks/{generate.runtime-CTQvLaU0.js.map → generate.runtime-DG9LRwbt.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DiAnQ9MW.js → generate.runtime-DKL7VAAd.js} +6 -6
- package/dist/chunks/{generate.runtime-DiAnQ9MW.js.map → generate.runtime-DKL7VAAd.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DaJ4gLPv.js → generate.runtime-DP63Wwea.js} +4 -4
- package/dist/chunks/{generate.runtime-DaJ4gLPv.js.map → generate.runtime-DP63Wwea.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CFSBH8yG.js → generate.runtime-DRPxOLnB.js} +4 -4
- package/dist/chunks/{generate.runtime-CFSBH8yG.js.map → generate.runtime-DRPxOLnB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-SZInujfP.js → generate.runtime-DW9bqOtC.js} +2 -2
- package/dist/chunks/{generate.runtime-SZInujfP.js.map → generate.runtime-DW9bqOtC.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cc5Aw1zc.js → generate.runtime-DdY44Ulv.js} +6 -6
- package/dist/chunks/{generate.runtime-Cc5Aw1zc.js.map → generate.runtime-DdY44Ulv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BOtYaNA5.js → generate.runtime-DjEj-n6m.js} +7 -7
- package/dist/chunks/{generate.runtime-BOtYaNA5.js.map → generate.runtime-DjEj-n6m.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ICaKVEuW.js → generate.runtime-DlAJQ5Js.js} +4 -4
- package/dist/chunks/{generate.runtime-ICaKVEuW.js.map → generate.runtime-DlAJQ5Js.js.map} +1 -1
- package/dist/chunks/{generate.runtime-4gS2ZHpj.js → generate.runtime-JftBoKYS.js} +5 -5
- package/dist/chunks/{generate.runtime-4gS2ZHpj.js.map → generate.runtime-JftBoKYS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B8t8HtB6.js → generate.runtime-_426A1Ij.js} +3 -3
- package/dist/chunks/{generate.runtime-B8t8HtB6.js.map → generate.runtime-_426A1Ij.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CyteiEzT.js → generate.runtime-fs6GEMx-.js} +5 -5
- package/dist/chunks/{generate.runtime-CyteiEzT.js.map → generate.runtime-fs6GEMx-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B9U3kzHD.js → generate.runtime-jIlQ2GMh.js} +2 -2
- package/dist/chunks/{generate.runtime-B9U3kzHD.js.map → generate.runtime-jIlQ2GMh.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BY5VmBG4.js → generate.runtime-v3KCv1B6.js} +2 -2
- package/dist/chunks/{generate.runtime-BY5VmBG4.js.map → generate.runtime-v3KCv1B6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CG3udLj8.js → generate.runtime-xrxAElb3.js} +3 -3
- package/dist/chunks/{generate.runtime-CG3udLj8.js.map → generate.runtime-xrxAElb3.js.map} +1 -1
- package/dist/chunks/{gitignore-CPardo4E.js → gitignore-CBiWFRif.js} +3 -3
- package/dist/chunks/{gitignore-CPardo4E.js.map → gitignore-CBiWFRif.js.map} +1 -1
- package/dist/chunks/{i18n-C8OfN_nr.js → i18n-Ho8H91Ze.js} +3 -3
- package/dist/chunks/{i18n-C8OfN_nr.js.map → i18n-Ho8H91Ze.js.map} +1 -1
- package/dist/chunks/{modify-file-DvIwtj4o.js → modify-file-BOEKlIDw.js} +2 -2
- package/dist/chunks/{modify-file-DvIwtj4o.js.map → modify-file-BOEKlIDw.js.map} +1 -1
- package/dist/chunks/{pocketbase-Ir-TPv7H.js → pocketbase-B2ksFrvH.js} +2 -2
- package/dist/chunks/{pocketbase-Ir-TPv7H.js.map → pocketbase-B2ksFrvH.js.map} +1 -1
- package/dist/chunks/{providers-B386TYCN.js → providers-BEjDonyG.js} +2 -2
- package/dist/chunks/{providers-B386TYCN.js.map → providers-BEjDonyG.js.map} +1 -1
- package/dist/chunks/{route-BJBV1DtX.js → route-9ZVJZkYu.js} +23 -19
- package/dist/chunks/route-9ZVJZkYu.js.map +1 -0
- package/dist/chunks/{schema-DSNYWlel.js → schema-DnMqw2Hn.js} +3 -3
- package/dist/chunks/{schema-DSNYWlel.js.map → schema-DnMqw2Hn.js.map} +1 -1
- package/dist/chunks/{shared-CZHopdly.js → shared-CSwGWMcN.js} +2 -2
- package/dist/chunks/{shared-CZHopdly.js.map → shared-CSwGWMcN.js.map} +1 -1
- package/dist/chunks/{shared-BofFBVmT.js → shared-Cdwm_-Nl.js} +40 -40
- package/dist/chunks/{shared-BofFBVmT.js.map → shared-Cdwm_-Nl.js.map} +1 -1
- package/dist/chunks/{site-B9-emR6D.js → site-B5zrFba9.js} +2 -2
- package/dist/chunks/{site-B9-emR6D.js.map → site-B5zrFba9.js.map} +1 -1
- package/dist/chunks/{table-core-CHsfbi-n.js → table-core-ux1xEJxN.js} +2 -2
- package/dist/chunks/{table-core-CHsfbi-n.js.map → table-core-ux1xEJxN.js.map} +1 -1
- package/dist/chunks/{translations-CiJnl574.js → translations-B5hX0Qq-.js} +5 -2
- package/dist/chunks/{translations-CiJnl574.js.map → translations-B5hX0Qq-.js.map} +1 -1
- package/dist/chunks/{ui-BUhkIHse.js → ui-CpjUq_lm.js} +3 -3
- package/dist/chunks/{ui-BUhkIHse.js.map → ui-CpjUq_lm.js.map} +1 -1
- package/dist/chunks/{whatsapp-DFZUsKWe.js → whatsapp-DOSZ_zwn.js} +2 -2
- package/dist/chunks/{whatsapp-DFZUsKWe.js.map → whatsapp-DOSZ_zwn.js.map} +1 -1
- package/dist/chunks/{write-result-Bkdkp7u2.js → write-result-DlB-id5k.js} +50 -26
- package/dist/chunks/write-result-DlB-id5k.js.map +1 -0
- package/dist/index.js +1864 -1842
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/_page-6d3DCr0p.js +0 -5
- package/dist/chunks/auth-pages-DHzh31mw.js +0 -285
- package/dist/chunks/auth-pages-DHzh31mw.js.map +0 -1
- package/dist/chunks/route-BJBV1DtX.js.map +0 -1
- package/dist/chunks/write-result-Bkdkp7u2.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
|
-
import { r as t } from "./modify-file-
|
|
2
|
+
import { r as t } from "./modify-file-BOEKlIDw.js";
|
|
3
3
|
import { a as n, t as r } from "./config-target-DJbVHwHl.js";
|
|
4
|
-
import { n as i } from "./generate-
|
|
4
|
+
import { n as i } from "./generate-DR2wkVPY.js";
|
|
5
5
|
import { _ as a, o, r as s } from "./ts-morph-helpers-B4KZXP44.js";
|
|
6
6
|
import { t as c } from "./dedent-CCUOcPFW.js";
|
|
7
7
|
import { a as l, c as u, i as d, l as f, n as p, o as m, r as h, s as g, t as _ } from "./load-function-BFvIVsh7.js";
|
|
@@ -297,4 +297,4 @@ async function K(a) {
|
|
|
297
297
|
}
|
|
298
298
|
export { K as generate };
|
|
299
299
|
|
|
300
|
-
//# sourceMappingURL=generate.runtime-
|
|
300
|
+
//# sourceMappingURL=generate.runtime-DG9LRwbt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-CTQvLaU0.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","resolveMode","withInMemoryScript","ensureImports","dedent","hasProperty","newProject","findLoadFunction","returnedObject","ensureNamedImports","hasSpreadOf","findFinalReturn","inspectEventParameter","ensureImportSpec","SvelteFile","fs","path","FAILURE_HINT$3","NOT_FOUND_HINT$1","elementName","text","modifyViteConfig","call","pluginArgs","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","elements","el","sveltekitIndex","formatLikeSource","DEFAULT_LOCALE","REQUEST_LOCALE","eventName","WUCHALE_LOCALE","cmsSnippet","locale","importLine","parts","spec","createdLayoutServer","imports","snippet","FAILURE_HINT$2","modifyLayoutServer","layoutServerPath","fn","body","Node","event","returned","object","spreadIndex","property","returnIndex","destructuring","typeText","FAILURE_HINT$1","modifyLayoutUniversal","layoutPath","dataExpression","expression","element","IMPORT_SNIPPET","MARKUP_SNIPPET","NOT_FOUND_HINT","FAILURE_HINT","modifyLayoutSvelte","file","out","source","sf","readWuchaleLocales","configPath","root","match","locales","m","vitePluginArgs","mode","list","generate","logger","options","modifies","i18n","pushResult","requestLocale","layoutUniversalPath","layoutSveltePath"],"sources":["../../src/patterns/enable/cms/modifies/vite-config.ts","../../src/patterns/enable/cms/modifies/layout.server.ts","../../src/patterns/enable/cms/modifies/layout.ts","../../src/patterns/enable/cms/modifies/layout.svelte.ts","../../src/patterns/enable/cms/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the CMS plugin to your Vite config, ahead of sveltekit():\",\n \"\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the CMS plugin ahead of sveltekit():\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit()],\",\n \"});\",\n].join(\"\\n\");\n\nfunction elementName(text: string): string {\n return text.replace(/\\s/g, \"\");\n}\n\n/**\n * Registers `cms(...)` from `@velastack/cms/vite` in the Vite plugin list, just\n * ahead of `sveltekit()`. Only the plugin array is touched, so the inline\n * `sveltekit({ ... })` shape the templates use is left alone.\n */\nexport function modifyViteConfig(\n viteConfigPath: string,\n pluginArgs = \"\",\n): ModifyOutcome {\n const call = `cms(${pluginArgs})`;\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"@velastack/cms/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"cms\"],\n moduleSpecifier: \"@velastack/cms/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: `[${call}]`,\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (pluginsProp as PropertyAssignment).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as PropertyAssignment).setInitializer(`[${call}]`);\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as ArrayLiteralExpression;\n const elements = arr.getElements();\n const hasCms = elements.some((el) =>\n elementName(el.getText()).startsWith(\"cms(\"),\n );\n\n if (!hasCms) {\n const sveltekitIndex = elements.findIndex((el) =>\n elementName(el.getText()).startsWith(\"sveltekit(\"),\n );\n arr.insertElement(sveltekitIndex === -1 ? 0 : sveltekitIndex, call);\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n ensureImportSpec,\n ensureNamedImports,\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport interface LayoutServerLocale {\n /**\n * Expression passed as `locale` to `loadCms`, given the name of the load's\n * event parameter: `() => \"'en'\"` or `(event) => \\`getLocale(${event}.url)\\``.\n */\n expression: (eventName: string) => string;\n /** Imports the expression depends on. */\n imports?: ImportSpec[];\n}\n\n/** A single-locale site: the literal default locale. */\nexport const DEFAULT_LOCALE: LayoutServerLocale = {\n expression: () => \"'en'\",\n};\n\n/**\n * A wuchale site: the language enable-i18n's handle chose for the request,\n * from the URL on a public page and the visitor's preference elsewhere, so\n * the content is in the language the rest of the page is in.\n */\nexport const REQUEST_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `${eventName}.locals.locale`,\n};\n\n/**\n * A wuchale site enabled before the handle set `locals.locale`: the locale\n * its reroute resolved from the URL.\n */\nexport const WUCHALE_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `getLocale(${eventName}.url)`,\n imports: [\n { namedImports: [\"getLocale\"], moduleSpecifier: \"#locales/main.url.js\" },\n ],\n};\n\nfunction cmsSnippet(eventName: string, locale: string): string {\n return dedent`\n const { cms, notFound, gone, redirectTo } = await loadCms(${eventName}, { locale: ${locale} });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n `;\n}\n\nfunction importLine(spec: ImportSpec): string {\n const parts: string[] = [];\n if (spec.defaultImport) parts.push(spec.defaultImport);\n if (spec.namespaceImport) parts.push(`* as ${spec.namespaceImport}`);\n if (spec.namedImports?.length)\n parts.push(`{ ${spec.namedImports.join(\", \")} }`);\n return `import ${parts.join(\", \")} from '${spec.moduleSpecifier}';`;\n}\n\n/**\n * A root `+layout.server.ts` written from scratch, for a project that has\n * none — the static template keeps its layout load universal.\n */\nexport function createdLayoutServer(locale: LayoutServerLocale): string {\n const imports = [\n \"import { error, redirect } from '@sveltejs/kit';\",\n \"import { loadCms } from '#lib/cms.js';\",\n ...(locale.imports ?? []).map(importLine),\n \"import type { LayoutServerLoad } from './$types';\",\n ].join(\"\\n\");\n const snippet = cmsSnippet(\"event\", locale.expression(\"event\"))\n .split(\"\\n\")\n .join(\"\\n\\t\");\n\n return dedent`\n ${imports}\n\n export const load: LayoutServerLoad = async (event) => {\n \t${snippet}\n\n \treturn { cms };\n };\n `.concat(\"\\n\");\n}\n\nconst FAILURE_HINT = [\n \"Call loadCms from the root +layout.server.ts load and return `cms`:\",\n \"\",\n createdLayoutServer(DEFAULT_LOCALE).trimEnd(),\n \"\",\n \"loadCms needs the whole event, so a destructured parameter has to become\",\n \"`event` with the destructuring moved into the body.\",\n].join(\"\\n\");\n\n/**\n * Wires `loadCms` into the root `+layout.server.ts`, creating the file when\n * the project has none:\n *\n * - `loadCms` needs the whole request event, so a destructured parameter is\n * renamed to `event` and the destructuring becomes the first statement.\n * - The tombstone triple (`redirectTo`, `gone`, `notFound`) is handled just\n * before the return.\n * - `cms` is added to the returned object, ahead of any spread so nothing\n * later can shadow it.\n *\n * Anything else — no exported `load`, an expression-bodied arrow, several\n * returns, a non-literal return — is reported as `failed` with the snippet to\n * paste, and the file is left exactly as it was.\n */\nexport function modifyLayoutServer(\n layoutServerPath: string,\n locale: LayoutServerLocale = DEFAULT_LOCALE,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, createdLayoutServer(locale));\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"loadCms(\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n\n // --- Inspect everything before touching anything. ---\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"failed\", message: FAILURE_HINT };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n const object = returned && returnedObject(returned);\n if (!returned || !object) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const eventName = event.kind === \"identifier\" ? event.name : \"event\";\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n if (!hasProperty(object, \"cms\")) {\n const spreadIndex = object\n .getProperties()\n .findIndex((property) => Node.isSpreadAssignment(property));\n if (spreadIndex === -1) {\n object.addShorthandPropertyAssignment({ name: \"cms\" });\n } else {\n object.insertShorthandPropertyAssignment(spreadIndex, { name: \"cms\" });\n }\n }\n\n // insertStatements counts comment lines, which getStatements() skips.\n const returnIndex = body.getStatementsWithComments().indexOf(returned);\n body.insertStatements(\n returnIndex,\n `\\n${cmsSnippet(eventName, locale.expression(eventName))}\\n`,\n );\n\n if (event.kind === \"binding\") {\n const destructuring = event.pattern.getText();\n body.insertStatements(0, `const ${destructuring} = ${eventName};`);\n const typeText = event.param.getTypeNode()?.getText();\n event.param.replaceWithText(\n typeText ? `${eventName}: ${typeText}` : eventName,\n );\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: eventName });\n }\n\n if (!fn.isAsync()) fn.setIsAsync(true);\n\n ensureNamedImports(sourceFile, \"@sveltejs/kit\", [\"error\", \"redirect\"]);\n ensureNamedImports(sourceFile, \"#lib/cms.js\", [\"loadCms\"]);\n for (const spec of locale.imports ?? []) {\n ensureImportSpec(sourceFile, spec);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasSpreadOf,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Forward the server load's data through the root +layout.ts, so \\`cms\\` reaches\n the page:\n\n export const load = async ({ url, data }) => {\n // ...existing code...\n return { ...data, /* existing keys */ };\n };\n`;\n\n/**\n * Make a universal root \\`+layout.ts\\` forward its server load's data.\n *\n * SvelteKit hands a universal load the server load's result as \\`data\\`, and\n * only what the universal load returns reaches the page. A layout that\n * returns its own object without spreading \\`data\\` — the static template\n * does — would drop \\`cms\\` on the floor once \\`+layout.server.ts\\` exists.\n *\n * No file, or a file without a \\`load\\`, needs nothing: server data flows\n * through on its own.\n */\nexport function modifyLayoutUniversal(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutPath);\n\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"success\", changed: false };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n if (!returned) return { status: \"failed\", message: FAILURE_HINT };\n\n const dataExpression =\n event.kind === \"identifier\" ? `${event.name}.data` : \"data\";\n\n // `return data;` already forwards everything.\n const expression = returned.getExpression();\n if (expression && expression.getText() === dataExpression) {\n return { status: \"success\", changed: false };\n }\n\n const object = returnedObject(returned);\n if (!object) return { status: \"failed\", message: FAILURE_HINT };\n if (hasSpreadOf(object, dataExpression)) {\n return { status: \"success\", changed: false };\n }\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n // First, so the layout's own keys still win over anything the server sent.\n object.insertSpreadAssignment(0, { expression: dataExpression });\n\n if (event.kind === \"binding\") {\n const hasData = event.pattern\n .getElements()\n .some((element) => element.getName() === \"data\");\n if (!hasData) {\n const text = event.pattern.getText();\n event.pattern.replaceWithText(text.replace(/^\\{\\s*/, \"{ data, \"));\n }\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ data }\" });\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { AdminBar } from '@velastack/cms';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<AdminBar />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <AdminBar /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<AdminBar />` at the top level of the root layout, ahead of\n * `{@render children()}` so the bar is in the DOM before the page content.\n * Falls back to appending when the layout has no render tag or slot.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"AdminBar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { namedImports: [\"AdminBar\"], moduleSpecifier: \"@velastack/cms\" },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { resolveMode, type CmsMode } from \"./generate\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport {\n DEFAULT_LOCALE,\n REQUEST_LOCALE,\n WUCHALE_LOCALE,\n modifyLayoutServer,\n} from \"./modifies/layout.server\";\nimport { modifyLayoutUniversal } from \"./modifies/layout\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\n/** The locale list from `wuchale.config.js`, or null when it cannot be read. */\nexport function readWuchaleLocales(root: string): string[] | null {\n const configPath = path.join(root, \"wuchale.config.js\");\n if (!fs.existsSync(configPath)) return null;\n const match = fs\n .readFileSync(configPath, \"utf8\")\n .match(/locales:\\s*\\[([^\\]]*)\\]/);\n if (!match) return null;\n const locales = [...match[1].matchAll(/['\"]([^'\"]+)['\"]/g)].map((m) => m[1]);\n return locales.length > 0 ? locales : null;\n}\n\n/**\n * Arguments for the `cms()` Vite plugin.\n *\n * A hosted CMS needs the endpoint and locales at build time so media can be\n * downloaded into the prerendered site. An app hosting the backend itself\n * needs nothing: the media steps are no-ops without an endpoint.\n */\nexport function vitePluginArgs(mode: CmsMode, locales: string[]): string {\n if (mode.local) return \"\";\n const list = locales.map((locale) => `'${locale}'`).join(\", \");\n return `{ endpoint: '${mode.endpoint}', locales: [${list}] }`;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const mode = resolveMode(options);\n const i18n = options.features.i18n;\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n const locales = (i18n && readWuchaleLocales(options.root)) || [\"en\"];\n pushResult(\n modifyOutcomeToFile(\n viteConfigPath,\n modifyViteConfig(viteConfigPath, vitePluginArgs(mode, locales)),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n // `src/lib/locale.ts` came with the handle that sets `locals.locale`.\n const requestLocale = fs.existsSync(\n path.join(options.root, \"src\", \"lib\", \"locale.ts\"),\n );\n const locale = !i18n\n ? DEFAULT_LOCALE\n : requestLocale\n ? REQUEST_LOCALE\n : WUCHALE_LOCALE;\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServer(layoutServerPath, locale),\n ),\n );\n\n // A universal root layout has to pass the server load's data along, or\n // `cms` never reaches the page. The static template has one.\n logger.info(\"Modifying src/routes/+layout.ts\");\n const layoutUniversalPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutUniversalPath,\n modifyLayoutUniversal(layoutUniversalPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutSveltePath, modifyLayoutSvelte(layoutSveltePath)),\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":";;;;;;;;;;;;AAYA,IAAMA,IAAe,kNAUfC,IAAiB;AAYvB,SAASyB,EAAY,GAAsB;CACzC,OAAOC,EAAK,QAAQ,OAAO,EAAE;AAC/B;AAOA,SAAgBC,EACd,GACA,IAAa,IACE;CACf,IAAMC,IAAO,OAAOC,EAAW;CAC/B,IAAI,CAACR,EAAG,WAAWS,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS9B;CAAe;CAOxD,IAAM+B,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW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CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-DG9LRwbt.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","resolveMode","withInMemoryScript","ensureImports","dedent","hasProperty","newProject","findLoadFunction","returnedObject","ensureNamedImports","hasSpreadOf","findFinalReturn","inspectEventParameter","ensureImportSpec","SvelteFile","fs","path","FAILURE_HINT$3","NOT_FOUND_HINT$1","elementName","text","modifyViteConfig","call","pluginArgs","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","elements","el","sveltekitIndex","formatLikeSource","DEFAULT_LOCALE","REQUEST_LOCALE","eventName","WUCHALE_LOCALE","cmsSnippet","locale","importLine","parts","spec","createdLayoutServer","imports","snippet","FAILURE_HINT$2","modifyLayoutServer","layoutServerPath","fn","body","Node","event","returned","object","spreadIndex","property","returnIndex","destructuring","typeText","FAILURE_HINT$1","modifyLayoutUniversal","layoutPath","dataExpression","expression","element","IMPORT_SNIPPET","MARKUP_SNIPPET","NOT_FOUND_HINT","FAILURE_HINT","modifyLayoutSvelte","file","out","source","sf","readWuchaleLocales","configPath","root","match","locales","m","vitePluginArgs","mode","list","generate","logger","options","modifies","i18n","pushResult","requestLocale","layoutUniversalPath","layoutSveltePath"],"sources":["../../src/patterns/enable/cms/modifies/vite-config.ts","../../src/patterns/enable/cms/modifies/layout.server.ts","../../src/patterns/enable/cms/modifies/layout.ts","../../src/patterns/enable/cms/modifies/layout.svelte.ts","../../src/patterns/enable/cms/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the CMS plugin to your Vite config, ahead of sveltekit():\",\n \"\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the CMS plugin ahead of sveltekit():\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit()],\",\n \"});\",\n].join(\"\\n\");\n\nfunction elementName(text: string): string {\n return text.replace(/\\s/g, \"\");\n}\n\n/**\n * Registers `cms(...)` from `@velastack/cms/vite` in the Vite plugin list, just\n * ahead of `sveltekit()`. Only the plugin array is touched, so the inline\n * `sveltekit({ ... })` shape the templates use is left alone.\n */\nexport function modifyViteConfig(\n viteConfigPath: string,\n pluginArgs = \"\",\n): ModifyOutcome {\n const call = `cms(${pluginArgs})`;\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"@velastack/cms/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"cms\"],\n moduleSpecifier: \"@velastack/cms/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: `[${call}]`,\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (pluginsProp as PropertyAssignment).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as PropertyAssignment).setInitializer(`[${call}]`);\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as ArrayLiteralExpression;\n const elements = arr.getElements();\n const hasCms = elements.some((el) =>\n elementName(el.getText()).startsWith(\"cms(\"),\n );\n\n if (!hasCms) {\n const sveltekitIndex = elements.findIndex((el) =>\n elementName(el.getText()).startsWith(\"sveltekit(\"),\n );\n arr.insertElement(sveltekitIndex === -1 ? 0 : sveltekitIndex, call);\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n ensureImportSpec,\n ensureNamedImports,\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport interface LayoutServerLocale {\n /**\n * Expression passed as `locale` to `loadCms`, given the name of the load's\n * event parameter: `() => \"'en'\"` or `(event) => \\`getLocale(${event}.url)\\``.\n */\n expression: (eventName: string) => string;\n /** Imports the expression depends on. */\n imports?: ImportSpec[];\n}\n\n/** A single-locale site: the literal default locale. */\nexport const DEFAULT_LOCALE: LayoutServerLocale = {\n expression: () => \"'en'\",\n};\n\n/**\n * A wuchale site: the language enable-i18n's handle chose for the request,\n * from the URL on a public page and the visitor's preference elsewhere, so\n * the content is in the language the rest of the page is in.\n */\nexport const REQUEST_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `${eventName}.locals.locale`,\n};\n\n/**\n * A wuchale site enabled before the handle set `locals.locale`: the locale\n * its reroute resolved from the URL.\n */\nexport const WUCHALE_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `getLocale(${eventName}.url)`,\n imports: [\n { namedImports: [\"getLocale\"], moduleSpecifier: \"#locales/main.url.js\" },\n ],\n};\n\nfunction cmsSnippet(eventName: string, locale: string): string {\n return dedent`\n const { cms, notFound, gone, redirectTo } = await loadCms(${eventName}, { locale: ${locale} });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n `;\n}\n\nfunction importLine(spec: ImportSpec): string {\n const parts: string[] = [];\n if (spec.defaultImport) parts.push(spec.defaultImport);\n if (spec.namespaceImport) parts.push(`* as ${spec.namespaceImport}`);\n if (spec.namedImports?.length)\n parts.push(`{ ${spec.namedImports.join(\", \")} }`);\n return `import ${parts.join(\", \")} from '${spec.moduleSpecifier}';`;\n}\n\n/**\n * A root `+layout.server.ts` written from scratch, for a project that has\n * none — the static template keeps its layout load universal.\n */\nexport function createdLayoutServer(locale: LayoutServerLocale): string {\n const imports = [\n \"import { error, redirect } from '@sveltejs/kit';\",\n \"import { loadCms } from '#lib/cms.js';\",\n ...(locale.imports ?? []).map(importLine),\n \"import type { LayoutServerLoad } from './$types';\",\n ].join(\"\\n\");\n const snippet = cmsSnippet(\"event\", locale.expression(\"event\"))\n .split(\"\\n\")\n .join(\"\\n\\t\");\n\n return dedent`\n ${imports}\n\n export const load: LayoutServerLoad = async (event) => {\n \t${snippet}\n\n \treturn { cms };\n };\n `.concat(\"\\n\");\n}\n\nconst FAILURE_HINT = [\n \"Call loadCms from the root +layout.server.ts load and return `cms`:\",\n \"\",\n createdLayoutServer(DEFAULT_LOCALE).trimEnd(),\n \"\",\n \"loadCms needs the whole event, so a destructured parameter has to become\",\n \"`event` with the destructuring moved into the body.\",\n].join(\"\\n\");\n\n/**\n * Wires `loadCms` into the root `+layout.server.ts`, creating the file when\n * the project has none:\n *\n * - `loadCms` needs the whole request event, so a destructured parameter is\n * renamed to `event` and the destructuring becomes the first statement.\n * - The tombstone triple (`redirectTo`, `gone`, `notFound`) is handled just\n * before the return.\n * - `cms` is added to the returned object, ahead of any spread so nothing\n * later can shadow it.\n *\n * Anything else — no exported `load`, an expression-bodied arrow, several\n * returns, a non-literal return — is reported as `failed` with the snippet to\n * paste, and the file is left exactly as it was.\n */\nexport function modifyLayoutServer(\n layoutServerPath: string,\n locale: LayoutServerLocale = DEFAULT_LOCALE,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, createdLayoutServer(locale));\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"loadCms(\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n\n // --- Inspect everything before touching anything. ---\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"failed\", message: FAILURE_HINT };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n const object = returned && returnedObject(returned);\n if (!returned || !object) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const eventName = event.kind === \"identifier\" ? event.name : \"event\";\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n if (!hasProperty(object, \"cms\")) {\n const spreadIndex = object\n .getProperties()\n .findIndex((property) => Node.isSpreadAssignment(property));\n if (spreadIndex === -1) {\n object.addShorthandPropertyAssignment({ name: \"cms\" });\n } else {\n object.insertShorthandPropertyAssignment(spreadIndex, { name: \"cms\" });\n }\n }\n\n // insertStatements counts comment lines, which getStatements() skips.\n const returnIndex = body.getStatementsWithComments().indexOf(returned);\n body.insertStatements(\n returnIndex,\n `\\n${cmsSnippet(eventName, locale.expression(eventName))}\\n`,\n );\n\n if (event.kind === \"binding\") {\n const destructuring = event.pattern.getText();\n body.insertStatements(0, `const ${destructuring} = ${eventName};`);\n const typeText = event.param.getTypeNode()?.getText();\n event.param.replaceWithText(\n typeText ? `${eventName}: ${typeText}` : eventName,\n );\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: eventName });\n }\n\n if (!fn.isAsync()) fn.setIsAsync(true);\n\n ensureNamedImports(sourceFile, \"@sveltejs/kit\", [\"error\", \"redirect\"]);\n ensureNamedImports(sourceFile, \"#lib/cms.js\", [\"loadCms\"]);\n for (const spec of locale.imports ?? []) {\n ensureImportSpec(sourceFile, spec);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasSpreadOf,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Forward the server load's data through the root +layout.ts, so \\`cms\\` reaches\n the page:\n\n export const load = async ({ url, data }) => {\n // ...existing code...\n return { ...data, /* existing keys */ };\n };\n`;\n\n/**\n * Make a universal root \\`+layout.ts\\` forward its server load's data.\n *\n * SvelteKit hands a universal load the server load's result as \\`data\\`, and\n * only what the universal load returns reaches the page. A layout that\n * returns its own object without spreading \\`data\\` — the static template\n * does — would drop \\`cms\\` on the floor once \\`+layout.server.ts\\` exists.\n *\n * No file, or a file without a \\`load\\`, needs nothing: server data flows\n * through on its own.\n */\nexport function modifyLayoutUniversal(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutPath);\n\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"success\", changed: false };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n if (!returned) return { status: \"failed\", message: FAILURE_HINT };\n\n const dataExpression =\n event.kind === \"identifier\" ? `${event.name}.data` : \"data\";\n\n // `return data;` already forwards everything.\n const expression = returned.getExpression();\n if (expression && expression.getText() === dataExpression) {\n return { status: \"success\", changed: false };\n }\n\n const object = returnedObject(returned);\n if (!object) return { status: \"failed\", message: FAILURE_HINT };\n if (hasSpreadOf(object, dataExpression)) {\n return { status: \"success\", changed: false };\n }\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n // First, so the layout's own keys still win over anything the server sent.\n object.insertSpreadAssignment(0, { expression: dataExpression });\n\n if (event.kind === \"binding\") {\n const hasData = event.pattern\n .getElements()\n .some((element) => element.getName() === \"data\");\n if (!hasData) {\n const text = event.pattern.getText();\n event.pattern.replaceWithText(text.replace(/^\\{\\s*/, \"{ data, \"));\n }\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ data }\" });\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst IMPORT_SNIPPET = dedent`\n import { AdminBar } from '@velastack/cms';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<AdminBar />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <AdminBar /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<AdminBar />` at the top level of the root layout, ahead of\n * `{@render children()}` so the bar is in the DOM before the page content.\n * Falls back to appending when the layout has no render tag or slot.\n */\nexport function modifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"AdminBar\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { namedImports: [\"AdminBar\"], moduleSpecifier: \"@velastack/cms\" },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { resolveMode, type CmsMode } from \"./generate\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport {\n DEFAULT_LOCALE,\n REQUEST_LOCALE,\n WUCHALE_LOCALE,\n modifyLayoutServer,\n} from \"./modifies/layout.server\";\nimport { modifyLayoutUniversal } from \"./modifies/layout\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\n/** The locale list from `wuchale.config.js`, or null when it cannot be read. */\nexport function readWuchaleLocales(root: string): string[] | null {\n const configPath = path.join(root, \"wuchale.config.js\");\n if (!fs.existsSync(configPath)) return null;\n const match = fs\n .readFileSync(configPath, \"utf8\")\n .match(/locales:\\s*\\[([^\\]]*)\\]/);\n if (!match) return null;\n const locales = [...match[1].matchAll(/['\"]([^'\"]+)['\"]/g)].map((m) => m[1]);\n return locales.length > 0 ? locales : null;\n}\n\n/**\n * Arguments for the `cms()` Vite plugin.\n *\n * A hosted CMS needs the endpoint and locales at build time so media can be\n * downloaded into the prerendered site. An app hosting the backend itself\n * needs nothing: the media steps are no-ops without an endpoint.\n */\nexport function vitePluginArgs(mode: CmsMode, locales: string[]): string {\n if (mode.local) return \"\";\n const list = locales.map((locale) => `'${locale}'`).join(\", \");\n return `{ endpoint: '${mode.endpoint}', locales: [${list}] }`;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const mode = resolveMode(options);\n const i18n = options.features.i18n;\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n const locales = (i18n && readWuchaleLocales(options.root)) || [\"en\"];\n pushResult(\n modifyOutcomeToFile(\n viteConfigPath,\n modifyViteConfig(viteConfigPath, vitePluginArgs(mode, locales)),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n // `src/lib/locale.ts` came with the handle that sets `locals.locale`.\n const requestLocale = fs.existsSync(\n path.join(options.root, \"src\", \"lib\", \"locale.ts\"),\n );\n const locale = !i18n\n ? DEFAULT_LOCALE\n : requestLocale\n ? REQUEST_LOCALE\n : WUCHALE_LOCALE;\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServer(layoutServerPath, locale),\n ),\n );\n\n // A universal root layout has to pass the server load's data along, or\n // `cms` never reaches the page. The static template has one.\n logger.info(\"Modifying src/routes/+layout.ts\");\n const layoutUniversalPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutUniversalPath,\n modifyLayoutUniversal(layoutUniversalPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutSveltePath, modifyLayoutSvelte(layoutSveltePath)),\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":";;;;;;;;;;;;AAYA,IAAMA,IAAe,kNAUfC,IAAiB;AAYvB,SAASyB,EAAY,GAAsB;CACzC,OAAOC,EAAK,QAAQ,OAAO,EAAE;AAC/B;AAOA,SAAgBC,EACd,GACA,IAAa,IACE;CACf,IAAMC,IAAO,OAAOC,EAAW;CAC/B,IAAI,CAACR,EAAG,WAAWS,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS9B;CAAe;CAOxD,IAAM+B,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBA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,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
2
|
import { n as t } from "./env-AxyRWcC_.js";
|
|
3
|
-
import { t as n } from "./modify-file-
|
|
4
|
-
import { n as r } from "./shared-
|
|
5
|
-
import { o as i } from "./generate-
|
|
6
|
-
import { n as a, r as o, t as s } from "./generate-
|
|
7
|
-
import { unmodifyEnvVarsFiles as c } from "./env-vars-
|
|
3
|
+
import { t as n } from "./modify-file-BOEKlIDw.js";
|
|
4
|
+
import { n as r } from "./shared-CSwGWMcN.js";
|
|
5
|
+
import { o as i } from "./generate-CL7wG0ZC.js";
|
|
6
|
+
import { n as a, r as o, t as s } from "./generate-CbchamhA.js";
|
|
7
|
+
import { unmodifyEnvVarsFiles as c } from "./env-vars-C3TSZc4f.js";
|
|
8
8
|
import l from "node:fs";
|
|
9
9
|
import u from "node:path";
|
|
10
10
|
// src/patterns/disable/ai/generate.runtime.ts
|
|
@@ -31,4 +31,4 @@ async function d(d) {
|
|
|
31
31
|
}
|
|
32
32
|
export { d as generate };
|
|
33
33
|
|
|
34
|
-
//# sourceMappingURL=generate.runtime-
|
|
34
|
+
//# sourceMappingURL=generate.runtime-DKL7VAAd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-DKL7VAAd.js","names":["getLogger","modifyEnvRemove","envRevertOutcomeToFile","toDeleteEntry","demoDir","allEnvNames","demoDirs","allEnvEdits","fs","path","generate","logger","options","modifies","deletes","current","dir","page","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/ai/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 { modifyEnvRemove } from \"../../../runtime/env\";\nimport { envRevertOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { toDeleteEntry } from \"../../destroy/shared\";\nimport { demoDir } from \"../../enable/ai/generate\";\nimport { allEnvEdits, allEnvNames, demoDirs } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n\n // The base result names the page in the current default group; a page\n // generated before auth was enabled sits in the other one.\n const current = demoDir(options);\n for (const dir of demoDirs(options)) {\n const page = `${dir}/+page.svelte`;\n if (dir !== current && fs.existsSync(path.join(options.root, page))) {\n deletes.push(toDeleteEntry(page));\n }\n }\n\n // Which provider was chosen is not recorded, so every one's key goes; the\n // file goes too when these were all it declared.\n logger.info(\"Removing the AI provider's API key from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n if (envVars.modify) modifies.push(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing the AI provider's API key from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n if (env.modify) modifies.push(env.modify);\n if (env.delete) deletes.push(env.delete);\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":";;;;;;;;;;AAWA,eAAsBU,EAAS,GAAkB;CAC/C,IAAMC,IAASX,EAAUY,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GAInBC,IAAUX,EAAQQ,CAAO;CAC/B,KAAK,IAAMI,KAAOV,EAASM,CAAO,GAAG;EACnC,IAAMK,IAAO,GAAGD,EAAI;EACpB,AAAIA,MAAQD,KAAWP,EAAG,WAAWC,EAAK,KAAKG,EAAQ,MAAMK,CAAI,CAAC,KAChEH,EAAQ,KAAKX,EAAcc,CAAI,CAAC;CAEpC;CAIA,EAAO,KAAK,oDAAoD;CAChE,IAAMC,IAAUC,EAAqBP,EAAQ,MAAMP,EAAY,CAAC;CAIhE,AAHIa,EAAQ,UAAQL,EAAS,KAAKK,EAAQ,MAAM,GAC5CA,EAAQ,UAAQJ,EAAQ,KAAKI,EAAQ,MAAM,GAE/CP,EAAO,KAAK,8CAA8C;CAC1D,IAAMS,IAAUX,EAAK,KAAKG,EAAQ,MAAM,MAAM,GACxCS,IAAMnB,EACVkB,GACAnB,EAAgBmB,GAASb,EAAY,CAAC,CACxC;CAIA,OAHIc,EAAI,UAAQR,EAAS,KAAKQ,EAAI,MAAM,GACpCA,EAAI,UAAQP,EAAQ,KAAKO,EAAI,MAAM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
2
|
import { n as t } from "./env-AxyRWcC_.js";
|
|
3
|
-
import { r as n, t as r } from "./modify-file-
|
|
4
|
-
import { n as i, t as a } from "./generate-
|
|
5
|
-
import { unmodifyEnvVarsFiles as o } from "./env-vars-
|
|
3
|
+
import { r as n, t as r } from "./modify-file-BOEKlIDw.js";
|
|
4
|
+
import { n as i, t as a } from "./generate-CAYM7OUF.js";
|
|
5
|
+
import { unmodifyEnvVarsFiles as o } from "./env-vars-C3TSZc4f.js";
|
|
6
6
|
import { t as s } from "./svelte-file-DfplF3BU.js";
|
|
7
7
|
import { _ as c, n as l, u } from "./ts-morph-helpers-B4KZXP44.js";
|
|
8
8
|
import { r as d } from "./lib-specifier-C3M0WTev.js";
|
|
@@ -60,4 +60,4 @@ async function g(s) {
|
|
|
60
60
|
}
|
|
61
61
|
export { g as generate };
|
|
62
62
|
|
|
63
|
-
//# sourceMappingURL=generate.runtime-
|
|
63
|
+
//# sourceMappingURL=generate.runtime-DP63Wwea.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-DP63Wwea.js","names":["getLogger","modifyEnvRemove","modifyOutcomeToFile","envRevertOutcomeToFile","allEnvNames","allEnvEdits","SvelteFile","withInMemoryScript","ensureBlankLineAfterImports","libModule","fs","path","MODULE","unmodifyLayoutSvelte","layoutPath","original","file","out","source","removeImportByModuleSpecifier","sf","updated","generate","logger","options","modifies","deletes","pushResult","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/analytics/modifies/layout.svelte.ts","../../src/patterns/disable/analytics/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst MODULE = \"components/analytics/analytics.svelte\";\n\n/**\n * Takes `<Analytics />` and its import back out of the root layout. The\n * element goes with its whole line, since enable-analytics put it on one of\n * its own. A layout without it, or no layout at all, is left alone.\n */\nexport function unmodifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(MODULE) && !original.includes(\"<Analytics\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(sf, libModule(MODULE));\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(/[ \\t]*<Analytics\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(layoutPath, updated, \"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 { modifyEnvRemove } from \"../../../runtime/env\";\nimport {\n envRevertOutcomeToFile,\n modifyOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { allEnvEdits, allEnvNames } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { unmodifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, unmodifyLayoutSvelte(layoutPath)));\n\n // Which provider was chosen is not recorded, so every one's variables go;\n // the file goes too when these were all it declared.\n logger.info(\"Removing analytics variables from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n pushResult(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing analytics variables from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n pushResult(env.modify);\n if (env.delete) deletes.push(env.delete);\n\n return {\n creates: [],\n modifies,\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAMY,IAAS;AAOf,SAAgBC,EAAqB,GAAmC;CACtE,IAAI,CAACH,EAAG,WAAWI,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWL,EAAG,aAAaI,GAAY,MAAM;CACnD,IAAI,CAACC,EAAS,SAASH,CAAM,KAAK,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AM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
2
|
import { a as t } from "./util-mXrQ89nG.js";
|
|
3
|
-
import { r as n } from "./modify-file-
|
|
3
|
+
import { r as n } from "./modify-file-BOEKlIDw.js";
|
|
4
4
|
import { t as r } from "./svelte-file-DfplF3BU.js";
|
|
5
5
|
import { f as i } from "./ts-morph-helpers-B4KZXP44.js";
|
|
6
|
-
import { t as a } from "./shared-
|
|
6
|
+
import { t as a } from "./shared-CSwGWMcN.js";
|
|
7
7
|
import { m as o, p as s, t as c } from "./generate-BrO9MOgL.js";
|
|
8
|
-
import { SUCCESS_PAGE as l, t as u } from "./generate.runtime-
|
|
8
|
+
import { SUCCESS_PAGE as l, t as u } from "./generate.runtime-jIlQ2GMh.js";
|
|
9
9
|
import d from "node:fs";
|
|
10
10
|
import f from "node:path";
|
|
11
11
|
// src/patterns/disable/orders/generate.runtime.ts
|
|
@@ -60,4 +60,4 @@ async function p(p) {
|
|
|
60
60
|
}
|
|
61
61
|
export { p as generate };
|
|
62
62
|
|
|
63
|
-
//# sourceMappingURL=generate.runtime-
|
|
63
|
+
//# sourceMappingURL=generate.runtime-DRPxOLnB.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-DRPxOLnB.js","names":["successServer","successSvelte","getLogger","languageFromPath","modifyOutcomeToFile","SvelteFile","removeNavItemFromScript","planDropsForCollections","_page_server_default","_page_default","ORDER_COLLECTIONS","unmodifyWebhookServer","fs","path","generate","logger","options","modifies","pushResult","file","dispatchPath","name","content","SUCCESS_PAGE","navUserPath","source","removed","tryRemove","run","result","src","fn","updated"],"sources":["../../src/patterns/disable/orders/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 { languageFromPath } from \"../../../core/util\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { SvelteFile } from \"../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../runtime/ts-morph-helpers\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { ORDER_COLLECTIONS } from \"../../enable/orders/generate\";\nimport { SUCCESS_PAGE } from \"../../enable/orders/generate.runtime\";\nimport { unmodifyWebhookServer } from \"../../enable/orders/modifies/modify-webhook-server\";\n// The success page as enable-ecommerce wrote it, before orders rewrote it.\nimport successServer from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.server.ts?raw\";\nimport successSvelte from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.svelte?raw\";\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 webhooks/stripe/handlers/dispatch.ts\");\n const dispatchPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(dispatchPath, unmodifyWebhookServer(dispatchPath)),\n );\n\n // Back to Stripe's summary alone, as enable-ecommerce wrote the page; a\n // project without the cart has no page to restore.\n logger.info(\"Reverting /checkout/success\");\n for (const [name, content] of [\n [\"+page.server.ts\", successServer],\n [\"+page.svelte\", successSvelte],\n ] as const) {\n const file = path.join(options.root, SUCCESS_PAGE, name);\n if (!fs.existsSync(file) || fs.readFileSync(file, \"utf8\") === content) {\n continue;\n }\n modifies.push({\n path: file,\n language: languageFromPath(file),\n content,\n status: \"success\",\n });\n }\n\n logger.info(\"Removing Orders from the user menu\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n if (fs.existsSync(navUserPath)) {\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (source.includes(\"'/orders'\")) {\n const file = new SvelteFile(source);\n let removed = false;\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (removed) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Orders\",\n \"@lucide/svelte/icons/package\",\n );\n if (result.wasRemoved) removed = true;\n return result.source;\n });\n };\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!removed) tryRemove((fn) => file.modifyScript(fn));\n if (removed) {\n const updated = file.toString();\n fs.writeFileSync(navUserPath, updated, \"utf8\");\n modifies.push({\n path: navUserPath,\n language: languageFromPath(navUserPath),\n content: updated,\n status: \"success\",\n });\n }\n }\n }\n\n // Lines before orders: PocketBase refuses to drop a collection another\n // relation still points at. One never created is planned as missing.\n const collectionDrops = await planDropsForCollections(\n [...ORDER_COLLECTIONS].reverse(),\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,eAAsBc,EAAS,GAAkB;CAC/C,IAAMC,IAASb,EAAUc,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIC,KAAMF,EAAS,KAAKE,CAAI;CAC9B;CAEA,EAAO,KAAK,gDAAgD;CAC5D,IAAMC,IAAeP,EAAK,KACxBG,EAAQ,MACR,OACA,UACA,YACA,UACA,YACA,aACF;CAOA,AANAE,EACEd,EAAoBgB,GAAcT,EAAsBS,CAAY,CAAC,CACvE,GAIAL,EAAO,KAAK,6BAA6B;CACzC,KAAK,IAAM,CAACM,GAAMC,MAAY,CAC5B,CAAC,mBAAmBtB,CAAa,GACjC,CAAC,gBAAgBC,CAAa,CAChC,GAAY;EACV,IAAMkB,IAAON,EAAK,K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r as t } from "./modify-file-
|
|
2
|
+
import { r as t } from "./modify-file-BOEKlIDw.js";
|
|
3
3
|
import { t as n } from "./svelte-file-DfplF3BU.js";
|
|
4
4
|
import { _ as r, n as i, u as a } from "./ts-morph-helpers-B4KZXP44.js";
|
|
5
5
|
import { n as o, t as s } from "./layout.svelte-B6wOQ7SM.js";
|
|
@@ -45,4 +45,4 @@ async function f(n) {
|
|
|
45
45
|
}
|
|
46
46
|
export { f as generate };
|
|
47
47
|
|
|
48
|
-
//# sourceMappingURL=generate.runtime-
|
|
48
|
+
//# sourceMappingURL=generate.runtime-DW9bqOtC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-DW9bqOtC.js","names":["getLogger","modifyOutcomeToFile","SvelteFile","withInMemoryScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","findMetaTagsDerived","MODULE_SPECIFIER","fs","path","unmodifyLayoutSvelte","layoutPath","file","out","source","call","sf","Node","generate","logger","options","modifies"],"sources":["../../src/patterns/disable/og/modifies/layout.svelte.ts","../../src/patterns/disable/og/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Node } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findMetaTagsDerived,\n MODULE_SPECIFIER,\n} from \"../../../enable/og/modifies/layout.svelte\";\n\n/**\n * Takes `withCard(..., page.url)` back off the root layout's `metaTags`, and\n * its import with it. `page` stays imported: the layout used it before.\n */\nexport function unmodifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.getScript()?.content.includes(\"withCard\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n const call = findMetaTagsDerived(sf)?.getArguments()[0];\n if (\n call &&\n Node.isCallExpression(call) &&\n call.getExpression().getText() === \"withCard\"\n ) {\n call.replaceWithText(call.getArguments()[0].getText());\n }\n removeImportByModuleSpecifier(sf, MODULE_SPECIFIER);\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Reverting src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n const file = modifyOutcomeToFile(\n layoutPath,\n unmodifyLayoutSvelte(layoutPath),\n );\n if (file) modifies.push(file);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgBU,EAAqB,GAAmC;CACtE,IAAI,CAACF,EAAG,WAAWG,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOV,EAAW,SAASS,CAAU;CAsB3C,OArBKC,EAAK,UAAU,CAAC,EAAE,QAAQ,SAAS,UAAU,KAIlDA,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQC,MAAQV,EAAmBW,IAAS,MAAO;GACzD,IAAMC,IAAOT,EAAoBU,CAAE,CAAC,EAAE,aAAa,CAAC,CAAC;GASrD,AAPED,KACAE,EAAK,iBAAiBF,CAAI,KAC1BA,EAAK,cAAc,CAAC,CAAC,QAAQ,MAAM,cAEnCA,EAAK,gBAAgBA,EAAK,aAAa,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAEvDV,EAA8BW,GAAIT,CAAgB,GAClDH,EAA4BY,CAAE;EAChC,CAAC;EACD,OAAOH;CACT,CAAC,GAEDD,EAAK,QAAQD,CAAU,GAChB;EAAE,QAAQ;EAAW,SAASC,EAAK,WAAW;CAAE,KApB9C;EAAE,QAAQ;EAAW,SAAS;CAAM;AAqB/C;;ACxCA,eAAsBM,EAAS,GAAkB;CAC/C,IAAMC,IAASnB,EAAUoB,CAAO,GAC1BC,IAAmB,CAAC;CAE1B,EAAO,KAAK,qCAAqC;CACjD,IAAMV,IAAaF,EAAK,KAAKW,EAAQ,MAAM,OAAO,UAAU,gBAAgB,GACtER,IAAOX,EACXU,GACAD,EAAqBC,CAAU,CACjC;CAGA,OAFIC,KAAMS,EAAS,KAAKT,CAAI,GAErB;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,9 +1,9 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
|
-
import { a as t } from "./collections-
|
|
3
|
-
import { i as n, n as r, t as i } from "./pocketbase-
|
|
4
|
-
import { r as a } from "./modify-file-
|
|
5
|
-
import { a as o, i as s, o as c, r as l, t as u } from "./whatsapp-
|
|
6
|
-
import { swapAuthPages as d } from "./auth-pages-
|
|
2
|
+
import { a as t } from "./collections-Daxlnbm0.js";
|
|
3
|
+
import { i as n, n as r, t as i } from "./pocketbase-B2ksFrvH.js";
|
|
4
|
+
import { r as a } from "./modify-file-BOEKlIDw.js";
|
|
5
|
+
import { a as o, i as s, o as c, r as l, t as u } from "./whatsapp-DOSZ_zwn.js";
|
|
6
|
+
import { swapAuthPages as d } from "./auth-pages-D8n8gfCL.js";
|
|
7
7
|
import f from "node:fs";
|
|
8
8
|
import p from "node:path";
|
|
9
9
|
// src/patterns/enable/whatsapp/modifies/modify-test-setup.ts
|
|
@@ -56,4 +56,4 @@ async function g(f) {
|
|
|
56
56
|
}
|
|
57
57
|
export { g as generate };
|
|
58
58
|
|
|
59
|
-
//# sourceMappingURL=generate.runtime-
|
|
59
|
+
//# sourceMappingURL=generate.runtime-DdY44Ulv.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-DdY44Ulv.js","names":["getLogger","readMigration","withPocketbase","migrationDelay","getMigrationFile","modifyOutcomeToFile","setupWhatsAppFields","hasWhatsAppPlugin","writeWhatsAppConfigMigration","enableWhatsAppAuth","MIN_POCKETBASE_SERVER","fs","path","modifyTestSetup","setupPath","original","content","indent","head","tail","bodyIndent","value","fieldIndent","DOCS_URL","generate","logger","options","creates","pb","file","configMigration","modifies","outcomes","swapAuthPages","filePath","outcome","testSetup","testSetupFile"],"sources":["../../src/patterns/enable/whatsapp/modifies/modify-test-setup.ts","../../src/patterns/enable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * `email` turns optional on `users`, which the generated types follow, so a\n * test setup from before enable-backend handled that no longer type-checks:\n * its `authenticateUser` takes `{ email: string }` and it signs the test\n * user in with `context.user.email`. Brings those two spots up to the\n * current setup; anything else in the file is the project's own.\n */\nexport function modifyTestSetup(setupPath: string): ModifyOutcome {\n if (!fs.existsSync(setupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(setupPath, \"utf8\");\n let content = original;\n\n content = content.replace(\n /^([ \\t]*)(async function authenticateUser\\(agent: Agent, user: \\{ )email: string( \\}\\) \\{\\n)([ \\t]*)/m,\n (_, indent, head, tail, bodyIndent) =>\n `${indent}${head}email?: string${tail}` +\n `${bodyIndent}// Logs in with the password, so it needs the email (made optional by\\n` +\n `${bodyIndent}// enable-whatsapp, for accounts that sign in with a phone number).\\n` +\n `${bodyIndent}if (!user.email) {\\n` +\n `${bodyIndent}${bodyIndent.includes(\"\\t\") ? \"\\t\" : \" \"}throw new Error('authenticateUser needs a user with an email');\\n` +\n `${bodyIndent}}\\n` +\n bodyIndent,\n );\n\n // The user is made with a known email: sign in with that.\n content = content.replace(\n /^([ \\t]*)context\\.user = await context\\.admin\\.collection\\('users'\\)\\.create\\(\\{\\n([ \\t]*)email: (`test-\\$\\{Math\\.random\\(\\)\\.toString\\(36\\)\\.slice\\(2\\)\\}@example\\.com`),/m,\n (_, indent, fieldIndent, value) =>\n `${indent}const email = ${value};\\n` +\n `${indent}context.user = await context.admin.collection('users').create({\\n` +\n `${fieldIndent}email,`,\n );\n if (content.includes(\"const email = `test-\")) {\n content = content.replace(\n \".authWithPassword(context.user.email, testUserPassword)\",\n \".authWithPassword(email, testUserPassword)\",\n );\n }\n\n if (content === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(setupPath, content, \"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 { readMigration } from \"../../../runtime/collections\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n MIN_POCKETBASE_SERVER,\n enableWhatsAppAuth,\n hasWhatsAppPlugin,\n setupWhatsAppFields,\n writeWhatsAppConfigMigration,\n} from \"./runtime/whatsapp\";\nimport { swapAuthPages } from \"./modifies/auth-pages\";\nimport { modifyTestSetup } from \"./modifies/modify-test-setup\";\n\nexport const DOCS_URL = \"https://velastack.dev/docs/enable/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 if (!(await hasWhatsAppPlugin(pb))) {\n throw new Error(\n `This PocketBase has no WhatsApp sign-in. It comes with pocketbase-server ${MIN_POCKETBASE_SERVER} and later: run \\`npm install -D pocketbase-server@^${MIN_POCKETBASE_SERVER}\\`, then \\`vela enable whatsapp\\` again.`,\n );\n }\n\n logger.info(\"Adding the phone fields to users and making email optional\");\n if (await setupWhatsAppFields(pb)) {\n await migrationDelay();\n const file = getMigrationFile(\"users\", \"updated\", options);\n if (file) creates.push(await readMigration(file, options));\n }\n\n logger.info(\"Turning on WhatsApp sign-in for users\");\n await enableWhatsAppAuth(pb);\n await migrationDelay();\n const configMigration = writeWhatsAppConfigMigration(options, true);\n if (configMigration) {\n creates.push(await readMigration(configMigration, options));\n }\n });\n\n logger.info(\"Adding WhatsApp to the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"enable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-auth wrote, so it was left as it is. Add the WhatsApp option to 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 logger.info(\"Updating test/setup.ts for an optional email\");\n const testSetup = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetup,\n modifyTestSetup(testSetup),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgBa,EAAgB,GAAkC;CAChE,IAAI,CAACF,EAAG,WAAWG,CAAS,GAC1B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAW,MAAM,GAC9CE,IAAUD;CAiCd,OA/BA,IAAUC,EAAQ,QAChB,0GACC,GAAG,GAAQ,GAAM,GAAM,MACtB,GAAGC,IAASC,EAAK,gBAAgB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,MACR,WACC,MACC,GAAGd,EAAK,SAASc,EAAQ,MAAMQ,CAAQ,EAAE,sGAAsGX,GACnJ;CACA,KAAK,IAAM,CAACW,GAAUC,MAAYH,GAAU;EAC1C,IAAMH,IAAOxB,EAAoB6B,GAAUC,CAAO;EAClD,AAAIN,KAAME,EAAS,KAAKF,CAAI;CAC9B;CAEA,EAAO,KAAK,8CAA8C;CAC1D,IAAMO,IAAYxB,EAAK,KAAKc,EAAQ,MAAM,QAAQ,UAAU,GACtDW,IAAgBhC,EACpB+B,GACAvB,EAAgBuB,CAAS,CAC3B;CAGA,OAFIC,KAAeN,EAAS,KAAKM,CAAa,GAEvC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { a as e, n as t, r as n, t as r } from "./currency.server-
|
|
1
|
+
import { a as e, n as t, r as n, t as r } from "./currency.server-BkzwY17R.js";
|
|
2
2
|
import { n as i } from "./logger-t1HxmpG2.js";
|
|
3
3
|
import { a, c as o, l as s } from "./providers-DrK_hjSr.js";
|
|
4
4
|
import { o as c, r as l } from "./util-mXrQ89nG.js";
|
|
5
|
-
import { modifyEnvVarsFiles as u } from "./env-vars-
|
|
6
|
-
import { r as d } from "./modify-file-
|
|
5
|
+
import { modifyEnvVarsFiles as u } from "./env-vars-C3TSZc4f.js";
|
|
6
|
+
import { r as d } from "./modify-file-BOEKlIDw.js";
|
|
7
7
|
import { t as f } from "./env-AxyRWcC_.js";
|
|
8
|
-
import { a as p, i as m, r as h, s as g, t as _ } from "./site-
|
|
8
|
+
import { a as p, i as m, r as h, s as g, t as _ } from "./site-B5zrFba9.js";
|
|
9
9
|
import { a as v, r as y, s as b, t as x } from "./root-layout.svelte-DE0c_y-T.js";
|
|
10
10
|
import { a as S, i as C, r as w } from "./collections-CFW9ZqUE.js";
|
|
11
11
|
import { t as T } from "./dedent-CCUOcPFW.js";
|
|
12
|
-
import { i as E, n as D, t as O } from "./pocketbase-
|
|
13
|
-
import { a as k, i as A, r as j } from "./collections-
|
|
12
|
+
import { i as E, n as D, t as O } from "./pocketbase-B2ksFrvH.js";
|
|
13
|
+
import { a as k, i as A, r as j } from "./collections-Daxlnbm0.js";
|
|
14
14
|
import { n as M } from "./modify-nav-user-D42kWyU6.js";
|
|
15
15
|
import { t as N } from "./modify-user-signup-ENhadGKH.js";
|
|
16
16
|
import { t as P } from "./taggedTemplateLiteral-CLenToGE.js";
|
|
@@ -489,4 +489,4 @@ async function $(t) {
|
|
|
489
489
|
}
|
|
490
490
|
export { $ as generate, Q as hasVitest };
|
|
491
491
|
|
|
492
|
-
//# sourceMappingURL=generate.runtime-
|
|
492
|
+
//# sourceMappingURL=generate.runtime-DjEj-n6m.js.map
|