@velastack/patterns 0.14.3 → 0.15.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/README.md +28 -0
- package/dist/chunks/{_page-44USwLXO.js → _page-6d3DCr0p.js} +2 -2
- package/dist/chunks/{_page-44USwLXO.js.map → _page-6d3DCr0p.js.map} +1 -1
- package/dist/chunks/{auth-pages-BW3_yluN.js → auth-pages-DHzh31mw.js} +2 -2
- package/dist/chunks/{auth-pages-BW3_yluN.js.map → auth-pages-DHzh31mw.js.map} +1 -1
- package/dist/chunks/{collections-B_-NTtLW.js → collections-FKsKGtaH.js} +70 -73
- package/dist/chunks/collections-FKsKGtaH.js.map +1 -0
- package/dist/chunks/{constants-CTp-0HKk.js → constants-BHuzzsKu.js} +19 -19
- package/dist/chunks/constants-BHuzzsKu.js.map +1 -0
- package/dist/chunks/{currency.server-DOX4Rzyb.js → currency.server-DRuEFc6D.js} +4 -4
- package/dist/chunks/{currency.server-DOX4Rzyb.js.map → currency.server-DRuEFc6D.js.map} +1 -1
- package/dist/chunks/{env-vars-BbS_mWyP.js → env-vars-BcHu8247.js} +4 -4
- package/dist/chunks/{env-vars-BbS_mWyP.js.map → env-vars-BcHu8247.js.map} +1 -1
- package/dist/chunks/{generate-B4uDCW5D.js → generate-9O0VdZOl.js} +4 -4
- package/dist/chunks/{generate-B4uDCW5D.js.map → generate-9O0VdZOl.js.map} +1 -1
- package/dist/chunks/{generate-CKuUg3p-.js → generate-BDGmczK8.js} +2 -2
- package/dist/chunks/{generate-CKuUg3p-.js.map → generate-BDGmczK8.js.map} +1 -1
- package/dist/chunks/{generate-DYq5Oj58.js → generate-BrO9MOgL.js} +2 -2
- package/dist/chunks/{generate-DYq5Oj58.js.map → generate-BrO9MOgL.js.map} +1 -1
- package/dist/chunks/{generate-Bwkx_usZ.js → generate-CXAKf1Hh.js} +4 -4
- package/dist/chunks/{generate-Bwkx_usZ.js.map → generate-CXAKf1Hh.js.map} +1 -1
- package/dist/chunks/{generate-4iujJNAW.js → generate-CkfJrlEg.js} +5 -5
- package/dist/chunks/{generate-4iujJNAW.js.map → generate-CkfJrlEg.js.map} +1 -1
- package/dist/chunks/{generate-BJY8AtAp.js → generate-a3U8uDzW.js} +5 -5
- package/dist/chunks/{generate-BJY8AtAp.js.map → generate-a3U8uDzW.js.map} +1 -1
- package/dist/chunks/{generate-JkvSNTy-.js → generate-rcDj36TD.js} +31 -188
- package/dist/chunks/generate-rcDj36TD.js.map +1 -0
- package/dist/chunks/{generate.runtime-D0lI3Gt8.js → generate.runtime-4gS2ZHpj.js} +5 -5
- package/dist/chunks/{generate.runtime-D0lI3Gt8.js.map → generate.runtime-4gS2ZHpj.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BFX_8erf.js → generate.runtime-As1It8o7.js} +10 -9
- package/dist/chunks/{generate.runtime-BFX_8erf.js.map → generate.runtime-As1It8o7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-XT_JQlTk.js → generate.runtime-B5SP9iyN.js} +2 -2
- package/dist/chunks/{generate.runtime-XT_JQlTk.js.map → generate.runtime-B5SP9iyN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DiEiFoxR.js → generate.runtime-B8t8HtB6.js} +3 -3
- package/dist/chunks/{generate.runtime-DiEiFoxR.js.map → generate.runtime-B8t8HtB6.js.map} +1 -1
- package/dist/chunks/{generate.runtime-XpYi9SlM.js → generate.runtime-B9U3kzHD.js} +3 -3
- package/dist/chunks/{generate.runtime-XpYi9SlM.js.map → generate.runtime-B9U3kzHD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-RTGpwxcS.js → generate.runtime-BDVPJJbh.js} +6 -12
- package/dist/chunks/generate.runtime-BDVPJJbh.js.map +1 -0
- package/dist/chunks/{generate.runtime-CBVcsole.js → generate.runtime-BGLekCHZ.js} +2 -2
- package/dist/chunks/{generate.runtime-CBVcsole.js.map → generate.runtime-BGLekCHZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-PDnSxiek.js → generate.runtime-BKA41qV0.js} +6 -6
- package/dist/chunks/{generate.runtime-PDnSxiek.js.map → generate.runtime-BKA41qV0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DhSH1o8H.js → generate.runtime-BKsrh3ZN.js} +3 -3
- package/dist/chunks/{generate.runtime-DhSH1o8H.js.map → generate.runtime-BKsrh3ZN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BXNBWGYr.js → generate.runtime-BL7O2fy8.js} +2 -2
- package/dist/chunks/{generate.runtime-BXNBWGYr.js.map → generate.runtime-BL7O2fy8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-VMTLHWLk.js → generate.runtime-BOtYaNA5.js} +55 -60
- package/dist/chunks/generate.runtime-BOtYaNA5.js.map +1 -0
- package/dist/chunks/{generate.runtime-bsuqrKOm.js → generate.runtime-BY5VmBG4.js} +2 -2
- package/dist/chunks/{generate.runtime-bsuqrKOm.js.map → generate.runtime-BY5VmBG4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Dm7IEo2h.js → generate.runtime-BYhWm9JA.js} +5 -5
- package/dist/chunks/{generate.runtime-Dm7IEo2h.js.map → generate.runtime-BYhWm9JA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D9OC1RXu.js → generate.runtime-BmdO8oKV.js} +2 -2
- package/dist/chunks/{generate.runtime-D9OC1RXu.js.map → generate.runtime-BmdO8oKV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BROXlbeJ.js → generate.runtime-C7NexMXs.js} +3 -3
- package/dist/chunks/{generate.runtime-BROXlbeJ.js.map → generate.runtime-C7NexMXs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-wiWdXXPi.js → generate.runtime-CFSBH8yG.js} +6 -6
- package/dist/chunks/{generate.runtime-wiWdXXPi.js.map → generate.runtime-CFSBH8yG.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ZgLxGWuy.js → generate.runtime-CG3udLj8.js} +3 -3
- package/dist/chunks/{generate.runtime-ZgLxGWuy.js.map → generate.runtime-CG3udLj8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DuAYqKxl.js → generate.runtime-CGbSe_nd.js} +2 -2
- package/dist/chunks/{generate.runtime-DuAYqKxl.js.map → generate.runtime-CGbSe_nd.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BU-4sjyu.js → generate.runtime-CI_rUVZo.js} +110 -113
- package/dist/chunks/generate.runtime-CI_rUVZo.js.map +1 -0
- package/dist/chunks/{generate.runtime-CCaCaXNu.js → generate.runtime-COo85dGX.js} +2 -2
- package/dist/chunks/{generate.runtime-CCaCaXNu.js.map → generate.runtime-COo85dGX.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DLoYscQO.js → generate.runtime-CTQvLaU0.js} +3 -3
- package/dist/chunks/{generate.runtime-DLoYscQO.js.map → generate.runtime-CTQvLaU0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-TQmspB4Z.js → generate.runtime-Cc5Aw1zc.js} +27 -34
- package/dist/chunks/generate.runtime-Cc5Aw1zc.js.map +1 -0
- package/dist/chunks/{generate.runtime-B7XOa9_A.js → generate.runtime-CnGVlvxN.js} +3 -3
- package/dist/chunks/{generate.runtime-B7XOa9_A.js.map → generate.runtime-CnGVlvxN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-sjFAWbZc.js → generate.runtime-Cqbsn5Ov.js} +7 -7
- package/dist/chunks/{generate.runtime-sjFAWbZc.js.map → generate.runtime-Cqbsn5Ov.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cm75waRD.js → generate.runtime-CtV9Gn9T.js} +2 -2
- package/dist/chunks/{generate.runtime-Cm75waRD.js.map → generate.runtime-CtV9Gn9T.js.map} +1 -1
- package/dist/chunks/{generate.runtime-UtkANHk1.js → generate.runtime-Cxa24AOd.js} +3 -3
- package/dist/chunks/{generate.runtime-UtkANHk1.js.map → generate.runtime-Cxa24AOd.js.map} +1 -1
- package/dist/chunks/generate.runtime-CyteiEzT.js +169 -0
- package/dist/chunks/generate.runtime-CyteiEzT.js.map +1 -0
- package/dist/chunks/{generate.runtime-BlEy2fFF.js → generate.runtime-D7EETq9M.js} +3 -3
- package/dist/chunks/{generate.runtime-BlEy2fFF.js.map → generate.runtime-D7EETq9M.js.map} +1 -1
- package/dist/chunks/{generate.runtime-nXjFqHyb.js → generate.runtime-DaJ4gLPv.js} +4 -4
- package/dist/chunks/{generate.runtime-nXjFqHyb.js.map → generate.runtime-DaJ4gLPv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D6l6uLiY.js → generate.runtime-DcBEbV-k.js} +2 -2
- package/dist/chunks/{generate.runtime-D6l6uLiY.js.map → generate.runtime-DcBEbV-k.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B8-ORwxT.js → generate.runtime-DiAnQ9MW.js} +6 -6
- package/dist/chunks/{generate.runtime-B8-ORwxT.js.map → generate.runtime-DiAnQ9MW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Duw_JI_b.js → generate.runtime-Dp3x08St.js} +2 -2
- package/dist/chunks/{generate.runtime-Duw_JI_b.js.map → generate.runtime-Dp3x08St.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D77ueFKY.js → generate.runtime-DsW0Q5S5.js} +118 -134
- package/dist/chunks/generate.runtime-DsW0Q5S5.js.map +1 -0
- package/dist/chunks/{generate.runtime-27KTIg_o.js → generate.runtime-DtcKbzOm.js} +48 -53
- package/dist/chunks/generate.runtime-DtcKbzOm.js.map +1 -0
- package/dist/chunks/{generate.runtime-DxyQqNpu.js → generate.runtime-ICaKVEuW.js} +5 -11
- package/dist/chunks/generate.runtime-ICaKVEuW.js.map +1 -0
- package/dist/chunks/{generate.runtime-CuvdtjKc.js → generate.runtime-SZInujfP.js} +2 -2
- package/dist/chunks/{generate.runtime-CuvdtjKc.js.map → generate.runtime-SZInujfP.js.map} +1 -1
- package/dist/chunks/gitignore-CPardo4E.js +139 -0
- package/dist/chunks/gitignore-CPardo4E.js.map +1 -0
- package/dist/chunks/{i18n-mnzzcYhz.js → i18n-C8OfN_nr.js} +2 -2
- package/dist/chunks/{i18n-mnzzcYhz.js.map → i18n-C8OfN_nr.js.map} +1 -1
- package/dist/chunks/{modify-file-CgJIza72.js → modify-file-DvIwtj4o.js} +3 -3
- package/dist/chunks/{modify-file-CgJIza72.js.map → modify-file-DvIwtj4o.js.map} +1 -1
- package/dist/chunks/pocketbase-Ir-TPv7H.js +232 -0
- package/dist/chunks/pocketbase-Ir-TPv7H.js.map +1 -0
- package/dist/chunks/{providers-CDUFaOeQ.js → providers-B386TYCN.js} +3 -3
- package/dist/chunks/{providers-CDUFaOeQ.js.map → providers-B386TYCN.js.map} +1 -1
- package/dist/chunks/{providers-tjlFH5di.js → providers-DrK_hjSr.js} +2 -2
- package/dist/chunks/{providers-tjlFH5di.js.map → providers-DrK_hjSr.js.map} +1 -1
- package/dist/chunks/route-BJBV1DtX.js +162 -0
- package/dist/chunks/route-BJBV1DtX.js.map +1 -0
- package/dist/chunks/schema-DSNYWlel.js +116 -0
- package/dist/chunks/schema-DSNYWlel.js.map +1 -0
- package/dist/chunks/shared-BofFBVmT.js +1182 -0
- package/dist/chunks/shared-BofFBVmT.js.map +1 -0
- package/dist/chunks/{shared-BjTRQ5QH.js → shared-CZHopdly.js} +3 -3
- package/dist/chunks/{shared-BjTRQ5QH.js.map → shared-CZHopdly.js.map} +1 -1
- package/dist/chunks/{site-C8Wcg6LT.js → site-B9-emR6D.js} +3 -3
- package/dist/chunks/{site-C8Wcg6LT.js.map → site-B9-emR6D.js.map} +1 -1
- package/dist/chunks/{table-core-RvMjoXpT.js → table-core-CHsfbi-n.js} +3 -3
- package/dist/chunks/{table-core-RvMjoXpT.js.map → table-core-CHsfbi-n.js.map} +1 -1
- package/dist/chunks/test-setup-jqVMmL83.js +103 -0
- package/dist/chunks/test-setup-jqVMmL83.js.map +1 -0
- package/dist/chunks/{ui-CE-8llQS.js → ui-BUhkIHse.js} +3 -3
- package/dist/chunks/{ui-CE-8llQS.js.map → ui-BUhkIHse.js.map} +1 -1
- package/dist/chunks/{util-ILWdjRAd.js → util-mXrQ89nG.js} +8 -2
- package/dist/chunks/util-mXrQ89nG.js.map +1 -0
- package/dist/chunks/{whatsapp-DT10x76l.js → whatsapp-DFZUsKWe.js} +2 -2
- package/dist/chunks/{whatsapp-DT10x76l.js.map → whatsapp-DFZUsKWe.js.map} +1 -1
- package/dist/chunks/write-result-Bkdkp7u2.js +539 -0
- package/dist/chunks/write-result-Bkdkp7u2.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.js +2387 -3275
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/collections-B_-NTtLW.js.map +0 -1
- package/dist/chunks/constants-CTp-0HKk.js.map +0 -1
- package/dist/chunks/generate-JkvSNTy-.js.map +0 -1
- package/dist/chunks/generate.runtime-27KTIg_o.js.map +0 -1
- package/dist/chunks/generate.runtime-BU-4sjyu.js.map +0 -1
- package/dist/chunks/generate.runtime-D77ueFKY.js.map +0 -1
- package/dist/chunks/generate.runtime-Dn0_y2iV.js +0 -161
- package/dist/chunks/generate.runtime-Dn0_y2iV.js.map +0 -1
- package/dist/chunks/generate.runtime-DxyQqNpu.js.map +0 -1
- package/dist/chunks/generate.runtime-RTGpwxcS.js.map +0 -1
- package/dist/chunks/generate.runtime-TQmspB4Z.js.map +0 -1
- package/dist/chunks/generate.runtime-VMTLHWLk.js.map +0 -1
- package/dist/chunks/pocketbase-S8lUt0nI.js +0 -219
- package/dist/chunks/pocketbase-S8lUt0nI.js.map +0 -1
- package/dist/chunks/test-setup-CpjhQSl-.js +0 -176
- package/dist/chunks/test-setup-CpjhQSl-.js.map +0 -1
- package/dist/chunks/util-ILWdjRAd.js.map +0 -1
- package/dist/chunks/write-result-BguSfKV-.js +0 -499
- package/dist/chunks/write-result-BguSfKV-.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-D9OC1RXu.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","FAILURE_HINT","NOT_FOUND_HINT","NOT_FOUND_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","withInMemoryScript","ensureNamedImport","formatLikeSource","ensureImports","modifyLayoutServerLocale","ensureRootLayoutI18n","modifyPrettierignore","modifyAppDts","modifyPackageImportsI18n","dedent","addHandle","SvelteFile","APP_LAYOUT_PATH","modifyAppLayoutLanguageSelect","withTranslations","translateCatalog","entriesInProject","AUTH_TRANSLATIONS","withWuchaleJsFiles","TRANSLATED_LIB_FILES","fs","path","FAILURE_HINT$4","NOT_FOUND_HINT$3","modifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","el","I18N_HANDLE","HANDLE_BODY","types","indent","text","line","IMPORTS","STARTUP","UNTYPED_HANDLE","FAILURE_HINT$3","HOOKS_SERVER_SNIPPET","ensureNamespaceImport","moduleSpecifier","ns","modifyHooksServerI18n","hooksServerPath","original","composed","handleStmt","DELOCALIZE_HELPER","HOOKS_SNIPPET","FAILURE_HINT$2","NEGOTIATE_ONLY_REROUTE","hasOtherReroute","n","ensureDeLocalizeImports","modifyHooksI18n","hooksPath","rerouteDecl","init","target","s","FAILURE_HINT$1","NOT_FOUND_HINT$2","modifyAppHtml","appHtmlPath","updated","match","NOT_FOUND_HINT$1","modifyGitignore","gitignorePath","block","LANGUAGE_SELECT_SNIPPET","PLAIN_LANGUAGE_SELECT_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","PLAIN_FAILURE_HINT","PLAIN_NOT_FOUND_HINT","addImport","out","source","sf","modifyRootLayoutLanguageSelect","plain","ui","layoutPath","file","PAGE_PATH","CATALOG_PATH","WELCOME_PAGE","PAGE_ENTRIES","PLAIN_SELECT_ENTRY","HEADER","normalize","welcomePageCatalog","root","pagePath","entry","withLibraryTexts","present","creates","edited","generate","logger","options","modifies","pushResult","imports","appDtsPath","layoutServerPath","rootLayoutCandidates","resolveUi","rootLayoutPath","p","appLayoutPath","prettierignorePath","catalog","shipped","content","translated"],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/hooks.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/welcome-catalog.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\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() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/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 import(\"ts-morph\").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: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\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 { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\n\n/**\n * The handle's body: which language the request is in (the URL on a public\n * page, the visitor's preference elsewhere: see `src/lib/locale.ts`), and the\n * cookie that remembers the last public page opened.\n */\nconst HANDLE_BODY = (types: { locale: string; html: string }) => dedent`\n const urlLocale = deLocalizeDefault(event.url.pathname, locales)[1] as Locale | null;\n const localizedUrl = hasLocalizedUrl(event.url.pathname);\n const cookie${types.locale} = event.cookies.get(LOCALE_COOKIE);\n const locale = pickLocale({\n urlLocale,\n localizedUrl,\n cookie,\n acceptLanguage: event.request.headers.get('accept-language'),\n locales,\n defaultLocale\n });\n event.locals.locale = locale;\n\n const response${types.html ? \": Response\" : \"\"} = await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }${types.html}) => html.replace('%sveltekit.lang%', locale)\n })\n );\n\n // Opening a public page sets the language of the pages that have no\n // language in their URL. Only when the page itself is opened: a preload\n // (hovering a link) must not change it.\n if (localizedUrl && cookie !== locale && event.request.method === 'GET' && !event.isDataRequest) {\n try {\n response.headers.append('set-cookie', localeCookie(locale));\n } catch {\n // a response with immutable headers (a proxied file): nothing to remember\n }\n }\n return response;\n`;\n\nconst indent = (text: string) =>\n text\n .split(\"\\n\")\n .map((line) => (line ? ` ${line}` : line))\n .join(\"\\n\");\n\nconst IMPORTS = dedent`\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { deLocalizeDefault } from 'wuchale/url';\n import { locales, type Locale } from '#locales/data.js';\n import { defaultLocale, hasLocalizedUrl } from '#lib/url.js';\n import { LOCALE_COOKIE, localeCookie, pickLocale } from '#lib/locale.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n`;\n\nconst STARTUP = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n`;\n\n/** The handle as it is added to a file whose own handle is typed loosely. */\nconst UNTYPED_HANDLE = [\n `const ${I18N_HANDLE} = async ({ event, resolve }: any) => {`,\n indent(\n HANDLE_BODY({ locale: \": string | undefined\", html: \": { html: string }\" }),\n ),\n \"};\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Wrap your exported handle with the wuchale i18n handler:\",\n \"\",\n \"import { sequence } from '@sveltejs/kit/hooks';\",\n IMPORTS,\n \"\",\n STARTUP,\n \"\",\n UNTYPED_HANDLE,\n \"\",\n \"export const handle = sequence(handleWuchale, /* your existing handle */);\",\n].join(\"\\n\");\n\n/**\n * The whole file, for a project that had no server hooks: a fresh `sv create`\n * app or a static site. `disable-i18n` deletes it again once the i18n handle\n * is all that is left.\n */\nexport const HOOKS_SERVER_SNIPPET = [\n \"import type { Handle } from '@sveltejs/kit/hooks';\",\n IMPORTS,\n \"\",\n STARTUP,\n \"\",\n `const ${I18N_HANDLE}: Handle = async ({ event, resolve }) => {`,\n indent(HANDLE_BODY({ locale: \"\", html: \"\" })),\n \"};\",\n \"\",\n `export const handle = ${I18N_HANDLE};`,\n].join(\"\\n\");\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Composed first: an unsupported handle leaves the file untouched.\n const composed = addHandle(sourceFile, { expression: I18N_HANDLE });\n if (composed.status === \"unsupported\" || !composed.statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const handleStmt = composed.statement;\n\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"Locale\", true);\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"defaultLocale\");\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"hasLocalizedUrl\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"LOCALE_COOKIE\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"localeCookie\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"pickLocale\");\n ensureNamespaceImport(\n sourceFile,\n \"#locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"#locales/js.loader.server.js\", \"js\");\n\n // Above the handle and its JSDoc, so `handleWuchale` is declared before\n // the handle reads it.\n sourceFile.insertText(\n handleStmt.getStart(true),\n `${STARTUP}\\n\\n${UNTYPED_HANDLE}\\n\\n`,\n );\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = dedent`\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n`;\n\n/**\n * The whole file, for a project that had no universal hooks. `disable-i18n`\n * deletes it again once the de-localizing reroute is all that is left.\n */\nexport const HOOKS_SNIPPET = dedent`\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:\n\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));\n`;\n\n/** What `enable-content-negotiation` leaves behind, to the whitespace. */\nconst NEGOTIATE_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)$/;\n\n/** A `reroute` this modifier cannot compose with: not a variable declaration. */\nfunction hasOtherReroute(sourceFile: SourceFile): boolean {\n if (sourceFile.getFunction(\"reroute\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) =>\n d\n .getNamedExports()\n .some(\n (n) => (n.getAliasNode()?.getText() ?? n.getName()) === \"reroute\",\n ),\n );\n}\n\nfunction ensureDeLocalizeImports(sourceFile: SourceFile) {\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n}\n\n/**\n * Add the de-localizing reroute to `src/hooks.ts`, composing with the one\n * `enable-content-negotiation` wrote rather than replacing the file: either\n * pattern may be enabled first, and negotiation's `modifyHooksNegotiate`\n * composes the other way round.\n */\nexport function modifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, HOOKS_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"rerouteDeLocalize\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n // A reroute in a shape ts-morph cannot rewrite (a function declaration,\n // a re-export) would collide with the one added below.\n if (hasOtherReroute(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n ensureDeLocalizeImports(sourceFile);\n sourceFile.addStatements(\n `\\n${DELOCALIZE_HELPER}\\n\\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init || !NEGOTIATE_ONLY_REROUTE.test(init.getText())) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureDeLocalizeImports(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n\n // Last: inserting text forgets the nodes above, and the helper has to be\n // declared before the reroute that reads it.\n const target = sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"reroute\"))!;\n sourceFile.insertText(target.getStart(true), `${DELOCALIZE_HELPER}\\n\\n`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n // A static lang (the templates ship lang=\"en\") is replaced by the\n // placeholder so the server hook can fill in the negotiated locale.\n if (/\\slang\\s*=/i.test(match)) {\n return match.replace(\n /\\slang\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n ' lang=\"%sveltekit.lang%\"',\n );\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\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\";\nimport type { Ui } from \"../../../../core/field/ui\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst PLAIN_LANGUAGE_SELECT_SNIPPET = \"<LanguageSelect />\";\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '#lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_FAILURE_HINT = [\n \"Add the language select to your root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add wherever it should render, e.g. above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_NOT_FOUND_HINT = [\n \"Create a root layout that includes the language select.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nfunction addImport(file: SvelteFile): void {\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"#lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n}\n\n/**\n * A vela layout gets the select as the last `<Navbar.List>` item. A plain one\n * (a project vela did not create) has no navbar, so the select goes above the\n * layout's children.\n */\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n ui: Ui = \"shadcn\",\n): ModifyOutcome {\n const plain = ui === \"plain\";\n if (!fs.existsSync(layoutPath)) {\n return {\n status: \"not-found\",\n message: plain ? PLAIN_NOT_FOUND_HINT : NOT_FOUND_HINT,\n };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n if (plain) {\n // Without a <script> the import has nowhere to go, and the markup alone\n // would not compile.\n if (!file.getScript()) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n if (!file.insertBeforeChildren(PLAIN_LANGUAGE_SELECT_SNIPPET)) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n addImport(file);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n }\n\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n addImport(file);\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File } from \"../../../core/types\";\nimport type { Ui } from \"../../../core/field/ui\";\n\nconst PAGE_PATH = \"src/routes/+page.svelte\";\nconst CATALOG_PATH = \"src/locales/es.po\";\n\n/** `src/routes/+page.svelte` as `sv create` writes it. */\nconst WELCOME_PAGE = [\n \"<h1>Welcome to SvelteKit</h1>\",\n '<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>',\n].join(\"\\n\");\n\ninterface Entry {\n reference: string;\n msgid: string;\n msgstr: string;\n}\n\nconst PAGE_ENTRIES: Entry[] = [\n {\n reference: PAGE_PATH,\n msgid: \"Welcome to SvelteKit\",\n msgstr: \"Bienvenido a SvelteKit\",\n },\n {\n reference: PAGE_PATH,\n msgid: \"Visit <0>svelte.dev/docs/kit</0> to read the documentation\",\n msgstr: \"Visita <0>svelte.dev/docs/kit</0> para leer la documentación\",\n },\n];\n\n// The native <select>'s aria-label. The shadcn select has no text of its own:\n// locale names come from Intl.DisplayNames.\nconst PLAIN_SELECT_ENTRY: Entry = {\n reference: \"src/lib/components/language-select.svelte\",\n msgid: \"Language\",\n msgstr: \"Idioma\",\n};\n\n// What wuchale writes for `es`. It rewrites the file on the first extraction,\n// keeping these translations and adding the source locale's catalog.\nconst HEADER = [\n 'msgid \"\"',\n 'msgstr \"\"',\n '\"Source-Language: en\\\\n\"',\n '\"Language: es\\\\n\"',\n '\"MIME-Version: 1.0\\\\n\"',\n '\"Content-Type: text/plain; charset=utf-8\\\\n\"',\n '\"Content-Transfer-Encoding: 8bit\\\\n\"',\n '\"Plural-Forms: nplurals=3\\\\n\"',\n '\"X-Plurals-Order: one, many, other\\\\n\"',\n].join(\"\\n\");\n\n// Whitespace is ignored so a page prettier has rewrapped still counts.\nconst normalize = (source: string) => source.replace(/\\s+/g, \"\");\n\n/**\n * A Spanish catalog for the `sv create` welcome page, so the language select\n * visibly does something on a fresh project. Anything else in the project is\n * left for the user to translate. Null unless the page is untouched, and never\n * over an existing catalog.\n */\nexport function welcomePageCatalog(root: string, ui: Ui): File | null {\n if (fs.existsSync(path.join(root, CATALOG_PATH))) return null;\n\n const pagePath = path.join(root, PAGE_PATH);\n if (!fs.existsSync(pagePath)) return null;\n const page = fs.readFileSync(pagePath, \"utf8\");\n if (normalize(page) !== normalize(WELCOME_PAGE)) return null;\n\n const entries =\n ui === \"plain\" ? [...PAGE_ENTRIES, PLAIN_SELECT_ENTRY] : PAGE_ENTRIES;\n const blocks = entries.map((entry) =>\n [\n `#: ${entry.reference}`,\n `msgid \"${entry.msgid}\"`,\n `msgstr \"${entry.msgstr}\"`,\n ].join(\"\\n\"),\n );\n\n return {\n path: CATALOG_PATH,\n language: \"text\",\n content: [HEADER, ...blocks].join(\"\\n\\n\") + \"\\n\",\n status: \"success\",\n };\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 { resolveUi } from \"../../../core/field/ui\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifyPackageImportsI18n } from \"./modifies/package-imports\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyPrettierignore } from \"./modifies/prettierignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { modifyLayoutServerLocale } from \"./modifies/layout.server\";\nimport { modifyAppDts } from \"./modifies/app-d-ts\";\nimport {\n APP_LAYOUT_PATH,\n modifyAppLayoutLanguageSelect,\n} from \"./modifies/app-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\nimport {\n entriesInProject,\n translateCatalog,\n withTranslations,\n} from \"../../../runtime/wuchale-catalog\";\nimport { AUTH_TRANSLATIONS } from \"../auth/translations\";\nimport {\n TRANSLATED_LIB_FILES,\n withWuchaleJsFiles,\n} from \"../../../runtime/wuchale-config\";\n\n/**\n * The `wuchale.config.js` create, with the library modules that carry\n * visitor-facing text and already exist in the project (the WhatsApp order\n * message, say) listed for the js adapter. A pattern enabled later adds its\n * own module to the written config.\n */\nexport function withLibraryTexts(root: string, creates: File[]): File[] {\n const present = TRANSLATED_LIB_FILES.filter((file) =>\n fs.existsSync(path.join(root, file)),\n );\n if (present.length === 0) return creates;\n return creates.map((file) => {\n if (!file.path.endsWith(\"wuchale.config.js\")) return file;\n const edited = withWuchaleJsFiles(file.content, present);\n return edited?.changed ? { ...file, content: edited.source } : file;\n });\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\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 pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Adding #locales to package.json imports\");\n const imports = modifyPackageImportsI18n(options.root);\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksI18n(hooksPath)));\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Declaring the request's language in app.d.ts\");\n const appDtsPath = path.join(options.root, \"src\", \"app.d.ts\");\n pushResult(modifyOutcomeToFile(appDtsPath, modifyAppDts(appDtsPath)));\n\n logger.info(\"Modifying root +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServerLocale(layoutServerPath),\n ),\n );\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const ui = resolveUi(options);\n // With no layout at all, a plain project's not-found hint names the\n // +layout.svelte it would have rather than vela's root-layout.svelte.\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n (ui === \"plain\" ? rootLayoutCandidates[3] : rootLayoutCandidates[0]);\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath, ui),\n ),\n );\n\n // Signed-in pages have one URL for every language; the select is how a\n // visitor changes it there.\n const appLayoutPath = path.join(options.root, APP_LAYOUT_PATH);\n if (fs.existsSync(appLayoutPath)) {\n logger.info(\"Adding the language select to the signed-in layout\");\n pushResult(\n modifyOutcomeToFile(\n appLayoutPath,\n modifyAppLayoutLanguageSelect(appLayoutPath),\n ),\n );\n }\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n logger.info(\"Updating .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n modifyPrettierignore(prettierignorePath),\n ),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n // Spanish for the pages other patterns wrote before this one: without it\n // they stay in English, and nothing says so.\n const shipped = entriesInProject(options.root, AUTH_TRANSLATIONS);\n if (shipped.length > 0)\n logger.info(\"Translating the sign-in pages into Spanish\");\n const creates: File[] = [];\n if (catalog) {\n const content = withTranslations(catalog.content, shipped).source;\n creates.push({ ...catalog, content });\n } else {\n const translated = translateCatalog(options.root, shipped);\n if (translated.create) creates.push(translated.create);\n pushResult(translated.modify);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAKA,IAAMA,IAAe,oLAUfC,IAAiB;AAWvB,SAAgBkC,GAAiB,GAAuC;CACtE,IAAI,CAACJ,EAAG,WAAWK,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAASnC;CAAe;CAOxD,IAAMoC,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBH,CAAc,GAEzD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ACF,IAGFX,EAAO,KAAK,qBAAqB;CACjC,IAAMlC,IAAgB3D,EAAK,KAAK8F,EAAQ,MAAM,YAAY;CAK1D,AAJAE,EACExH,EAAoBmF,GAAeD,EAAgBC,CAAa,CAAC,CACnE,GAEAkC,EAAO,KAAK,0BAA0B;CACtC,IAAMY,IAAqBzG,EAAK,KAAK8F,EAAQ,MAAM,iBAAiB;CACpE,EACEtH,EACEiI,GACAxH,GAAqBwH,CAAkB,CACzC,CACF;CAEA,IAAMC,IAAUtB,GAAmBU,EAAQ,MAAMpB,CAAE;CACnD,AAAIgC,KAASb,EAAO,KAAK,2CAA2C;CAIpE,IAAMc,IAAUhH,GAAiBmG,EAAQ,MAAMlG,CAAiB;CAChE,AAAI+G,EAAQ,SAAS,KACnBd,EAAO,KAAK,4CAA4C;CAC1D,IAAMH,IAAkB,CAAC;CACzB,IAAIgB,GAAS;EACX,IAAME,IAAUnH,GAAiBiH,EAAQ,SAASC,CAAO,CAAC,CAAC;EAC3D,EAAQ,KAAK;GAAE,GAAGD;GAAS;EAAQ,CAAC;CACtC,OAAO;EACL,IAAMG,IAAanH,GAAiBoG,EAAQ,MAAMa,CAAO;EAEzD,AADIE,EAAW,UAAQnB,EAAQ,KAAKmB,EAAW,MAAM,GACrDb,EAAWa,EAAW,MAAM;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"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-BmdO8oKV.js","names":["FAILURE_HINT","NOT_FOUND_HINT","FAILURE_HINT","FAILURE_HINT","FAILURE_HINT","NOT_FOUND_HINT","NOT_FOUND_HINT","getLogger","modifyOutcomeToFile","probeFirstExisting","VITE_CONFIG_CANDIDATES","withInMemoryScript","ensureNamedImport","formatLikeSource","ensureImports","modifyLayoutServerLocale","ensureRootLayoutI18n","modifyPrettierignore","modifyAppDts","modifyPackageImportsI18n","dedent","addHandle","SvelteFile","APP_LAYOUT_PATH","modifyAppLayoutLanguageSelect","withTranslations","translateCatalog","entriesInProject","AUTH_TRANSLATIONS","withWuchaleJsFiles","TRANSLATED_LIB_FILES","fs","path","FAILURE_HINT$4","NOT_FOUND_HINT$3","modifyViteConfig","viteConfigPath","sourceFile","Project","QuoteKind","changed","failed","d","configArg","SyntaxKind","ce","configObj","pluginsProp","pluginsInit","arr","el","I18N_HANDLE","HANDLE_BODY","types","indent","text","line","IMPORTS","STARTUP","UNTYPED_HANDLE","FAILURE_HINT$3","HOOKS_SERVER_SNIPPET","ensureNamespaceImport","moduleSpecifier","ns","modifyHooksServerI18n","hooksServerPath","original","composed","handleStmt","DELOCALIZE_HELPER","HOOKS_SNIPPET","FAILURE_HINT$2","NEGOTIATE_ONLY_REROUTE","hasOtherReroute","n","ensureDeLocalizeImports","modifyHooksI18n","hooksPath","rerouteDecl","init","target","s","FAILURE_HINT$1","NOT_FOUND_HINT$2","modifyAppHtml","appHtmlPath","updated","match","NOT_FOUND_HINT$1","modifyGitignore","gitignorePath","block","LANGUAGE_SELECT_SNIPPET","PLAIN_LANGUAGE_SELECT_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","PLAIN_FAILURE_HINT","PLAIN_NOT_FOUND_HINT","addImport","out","source","sf","modifyRootLayoutLanguageSelect","plain","ui","layoutPath","file","PAGE_PATH","CATALOG_PATH","WELCOME_PAGE","PAGE_ENTRIES","PLAIN_SELECT_ENTRY","HEADER","normalize","welcomePageCatalog","root","pagePath","entry","withLibraryTexts","present","creates","edited","generate","logger","options","modifies","pushResult","imports","appDtsPath","layoutServerPath","rootLayoutCandidates","resolveUi","rootLayoutPath","p","appLayoutPath","prettierignorePath","catalog","shipped","content","translated"],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/hooks.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/welcome-catalog.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\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() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/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 import(\"ts-morph\").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: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\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 { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { addHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst I18N_HANDLE = \"handleWuchale\";\n\n/**\n * The handle's body: which language the request is in (the URL on a public\n * page, the visitor's preference elsewhere: see `src/lib/locale.ts`), and the\n * cookie that remembers the last public page opened.\n */\nconst HANDLE_BODY = (types: { locale: string; html: string }) => dedent`\n const urlLocale = deLocalizeDefault(event.url.pathname, locales)[1] as Locale | null;\n const localizedUrl = hasLocalizedUrl(event.url.pathname);\n const cookie${types.locale} = event.cookies.get(LOCALE_COOKIE);\n const locale = pickLocale({\n urlLocale,\n localizedUrl,\n cookie,\n acceptLanguage: event.request.headers.get('accept-language'),\n locales,\n defaultLocale\n });\n event.locals.locale = locale;\n\n const response${types.html ? \": Response\" : \"\"} = await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }${types.html}) => html.replace('%sveltekit.lang%', locale)\n })\n );\n\n // Opening a public page sets the language of the pages that have no\n // language in their URL. Only when the page itself is opened: a preload\n // (hovering a link) must not change it.\n if (localizedUrl && cookie !== locale && event.request.method === 'GET' && !event.isDataRequest) {\n try {\n response.headers.append('set-cookie', localeCookie(locale));\n } catch {\n // a response with immutable headers (a proxied file): nothing to remember\n }\n }\n return response;\n`;\n\nconst indent = (text: string) =>\n text\n .split(\"\\n\")\n .map((line) => (line ? ` ${line}` : line))\n .join(\"\\n\");\n\nconst IMPORTS = dedent`\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { deLocalizeDefault } from 'wuchale/url';\n import { locales, type Locale } from '#locales/data.js';\n import { defaultLocale, hasLocalizedUrl } from '#lib/url.js';\n import { LOCALE_COOKIE, localeCookie, pickLocale } from '#lib/locale.js';\n import * as main from '#locales/main.loader.server.svelte.js';\n import * as js from '#locales/js.loader.server.js';\n`;\n\nconst STARTUP = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n`;\n\n/** The handle as it is added to a file whose own handle is typed loosely. */\nconst UNTYPED_HANDLE = [\n `const ${I18N_HANDLE} = async ({ event, resolve }: any) => {`,\n indent(\n HANDLE_BODY({ locale: \": string | undefined\", html: \": { html: string }\" }),\n ),\n \"};\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Wrap your exported handle with the wuchale i18n handler:\",\n \"\",\n \"import { sequence } from '@sveltejs/kit/hooks';\",\n IMPORTS,\n \"\",\n STARTUP,\n \"\",\n UNTYPED_HANDLE,\n \"\",\n \"export const handle = sequence(handleWuchale, /* your existing handle */);\",\n].join(\"\\n\");\n\n/**\n * The whole file, for a project that had no server hooks: a fresh `sv create`\n * app or a static site. `disable-i18n` deletes it again once the i18n handle\n * is all that is left.\n */\nexport const HOOKS_SERVER_SNIPPET = [\n \"import type { Handle } from '@sveltejs/kit/hooks';\",\n IMPORTS,\n \"\",\n STARTUP,\n \"\",\n `const ${I18N_HANDLE}: Handle = async ({ event, resolve }) => {`,\n indent(HANDLE_BODY({ locale: \"\", html: \"\" })),\n \"};\",\n \"\",\n `export const handle = ${I18N_HANDLE};`,\n].join(\"\\n\");\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // SvelteKit loads the first `hooks.server.*` it finds, and `.js` sorts\n // first, so a new `.ts` beside it would never run.\n if (fs.existsSync(hooksServerPath.replace(/\\.ts$/, \".js\"))) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.mkdirSync(path.dirname(hooksServerPath), { recursive: true });\n fs.writeFileSync(hooksServerPath, HOOKS_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Composed first: an unsupported handle leaves the file untouched.\n const composed = addHandle(sourceFile, { expression: I18N_HANDLE });\n if (composed.status === \"unsupported\" || !composed.statement) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const handleStmt = composed.statement;\n\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"Locale\", true);\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"defaultLocale\");\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"hasLocalizedUrl\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"LOCALE_COOKIE\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"localeCookie\");\n ensureNamedImport(sourceFile, \"#lib/locale.js\", \"pickLocale\");\n ensureNamespaceImport(\n sourceFile,\n \"#locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"#locales/js.loader.server.js\", \"js\");\n\n // Above the handle and its JSDoc, so `handleWuchale` is declared before\n // the handle reads it.\n sourceFile.insertText(\n handleStmt.getStart(true),\n `${STARTUP}\\n\\n${UNTYPED_HANDLE}\\n\\n`,\n );\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst DELOCALIZE_HELPER = dedent`\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n`;\n\n/**\n * The whole file, for a project that had no universal hooks. `disable-i18n`\n * deletes it again once the de-localizing reroute is all that is left.\n */\nexport const HOOKS_SNIPPET = dedent`\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`;\n\nconst FAILURE_HINT = dedent`\n Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:\n\n import { deLocalizeDefault } from 'wuchale/url';\n import { matchUrl } from '#locales/main.url.js';\n import { locales } from '#locales/data.js';\n\n const rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n };\n\n export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));\n`;\n\n/** What `enable-content-negotiation` leaves behind, to the whitespace. */\nconst NEGOTIATE_ONLY_REROUTE =\n /^\\(\\s*\\{\\s*url\\s*\\}\\s*\\)\\s*=>\\s*negotiateReroute\\(\\s*url\\.pathname\\s*\\)$/;\n\n/** A `reroute` this modifier cannot compose with: not a variable declaration. */\nfunction hasOtherReroute(sourceFile: SourceFile): boolean {\n if (sourceFile.getFunction(\"reroute\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) =>\n d\n .getNamedExports()\n .some(\n (n) => (n.getAliasNode()?.getText() ?? n.getName()) === \"reroute\",\n ),\n );\n}\n\nfunction ensureDeLocalizeImports(sourceFile: SourceFile) {\n ensureNamedImport(sourceFile, \"wuchale/url\", \"deLocalizeDefault\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"#locales/data.js\", \"locales\");\n}\n\n/**\n * Add the de-localizing reroute to `src/hooks.ts`, composing with the one\n * `enable-content-negotiation` wrote rather than replacing the file: either\n * pattern may be enabled first, and negotiation's `modifyHooksNegotiate`\n * composes the other way round.\n */\nexport function modifyHooksI18n(hooksPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksPath)) {\n fs.mkdirSync(path.dirname(hooksPath), { recursive: true });\n fs.writeFileSync(hooksPath, HOOKS_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(hooksPath, \"utf8\");\n if (original.includes(\"rerouteDeLocalize\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksPath);\n\n const rerouteDecl = sourceFile.getVariableDeclaration(\"reroute\");\n\n if (!rerouteDecl) {\n // A reroute in a shape ts-morph cannot rewrite (a function declaration,\n // a re-export) would collide with the one added below.\n if (hasOtherReroute(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n ensureDeLocalizeImports(sourceFile);\n sourceFile.addStatements(\n `\\n${DELOCALIZE_HELPER}\\n\\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\\n`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const rerouteStmt = rerouteDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!rerouteStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const init = rerouteDecl.getInitializer();\n if (!init || !NEGOTIATE_ONLY_REROUTE.test(init.getText())) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureDeLocalizeImports(sourceFile);\n rerouteDecl.setInitializer(\n \"({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))\",\n );\n\n // Last: inserting text forgets the nodes above, and the helper has to be\n // declared before the reroute that reads it.\n const target = sourceFile\n .getVariableStatements()\n .find((s) => s.getDeclarations().some((d) => d.getName() === \"reroute\"))!;\n sourceFile.insertText(target.getStart(true), `${DELOCALIZE_HELPER}\\n\\n`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n // A static lang (the templates ship lang=\"en\") is replaced by the\n // placeholder so the server hook can fill in the negotiated locale.\n if (/\\slang\\s*=/i.test(match)) {\n return match.replace(\n /\\slang\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+)/i,\n ' lang=\"%sveltekit.lang%\"',\n );\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\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\";\nimport type { Ui } from \"../../../../core/field/ui\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst PLAIN_LANGUAGE_SELECT_SNIPPET = \"<LanguageSelect />\";\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '#lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_FAILURE_HINT = [\n \"Add the language select to your root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add wherever it should render, e.g. above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst PLAIN_NOT_FOUND_HINT = [\n \"Create a root layout that includes the language select.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup above {@render children()}:\",\n \"\",\n PLAIN_LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nfunction addImport(file: SvelteFile): void {\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"#lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n}\n\n/**\n * A vela layout gets the select as the last `<Navbar.List>` item. A plain one\n * (a project vela did not create) has no navbar, so the select goes above the\n * layout's children.\n */\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n ui: Ui = \"shadcn\",\n): ModifyOutcome {\n const plain = ui === \"plain\";\n if (!fs.existsSync(layoutPath)) {\n return {\n status: \"not-found\",\n message: plain ? PLAIN_NOT_FOUND_HINT : NOT_FOUND_HINT,\n };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n if (plain) {\n // Without a <script> the import has nowhere to go, and the markup alone\n // would not compile.\n if (!file.getScript()) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n if (!file.insertBeforeChildren(PLAIN_LANGUAGE_SELECT_SNIPPET)) {\n return { status: \"failed\", message: PLAIN_FAILURE_HINT };\n }\n addImport(file);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n }\n\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n addImport(file);\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File } from \"../../../core/types\";\nimport type { Ui } from \"../../../core/field/ui\";\n\nconst PAGE_PATH = \"src/routes/+page.svelte\";\nconst CATALOG_PATH = \"src/locales/es.po\";\n\n/** `src/routes/+page.svelte` as `sv create` writes it. */\nconst WELCOME_PAGE = [\n \"<h1>Welcome to SvelteKit</h1>\",\n '<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>',\n].join(\"\\n\");\n\ninterface Entry {\n reference: string;\n msgid: string;\n msgstr: string;\n}\n\nconst PAGE_ENTRIES: Entry[] = [\n {\n reference: PAGE_PATH,\n msgid: \"Welcome to SvelteKit\",\n msgstr: \"Bienvenido a SvelteKit\",\n },\n {\n reference: PAGE_PATH,\n msgid: \"Visit <0>svelte.dev/docs/kit</0> to read the documentation\",\n msgstr: \"Visita <0>svelte.dev/docs/kit</0> para leer la documentación\",\n },\n];\n\n// The native <select>'s aria-label. The shadcn select has no text of its own:\n// locale names come from Intl.DisplayNames.\nconst PLAIN_SELECT_ENTRY: Entry = {\n reference: \"src/lib/components/language-select.svelte\",\n msgid: \"Language\",\n msgstr: \"Idioma\",\n};\n\n// What wuchale writes for `es`. It rewrites the file on the first extraction,\n// keeping these translations and adding the source locale's catalog.\nconst HEADER = [\n 'msgid \"\"',\n 'msgstr \"\"',\n '\"Source-Language: en\\\\n\"',\n '\"Language: es\\\\n\"',\n '\"MIME-Version: 1.0\\\\n\"',\n '\"Content-Type: text/plain; charset=utf-8\\\\n\"',\n '\"Content-Transfer-Encoding: 8bit\\\\n\"',\n '\"Plural-Forms: nplurals=3\\\\n\"',\n '\"X-Plurals-Order: one, many, other\\\\n\"',\n].join(\"\\n\");\n\n// Whitespace is ignored so a page prettier has rewrapped still counts.\nconst normalize = (source: string) => source.replace(/\\s+/g, \"\");\n\n/**\n * A Spanish catalog for the `sv create` welcome page, so the language select\n * visibly does something on a fresh project. Anything else in the project is\n * left for the user to translate. Null unless the page is untouched, and never\n * over an existing catalog.\n */\nexport function welcomePageCatalog(root: string, ui: Ui): File | null {\n if (fs.existsSync(path.join(root, CATALOG_PATH))) return null;\n\n const pagePath = path.join(root, PAGE_PATH);\n if (!fs.existsSync(pagePath)) return null;\n const page = fs.readFileSync(pagePath, \"utf8\");\n if (normalize(page) !== normalize(WELCOME_PAGE)) return null;\n\n const entries =\n ui === \"plain\" ? [...PAGE_ENTRIES, PLAIN_SELECT_ENTRY] : PAGE_ENTRIES;\n const blocks = entries.map((entry) =>\n [\n `#: ${entry.reference}`,\n `msgid \"${entry.msgid}\"`,\n `msgstr \"${entry.msgstr}\"`,\n ].join(\"\\n\"),\n );\n\n return {\n path: CATALOG_PATH,\n language: \"text\",\n content: [HEADER, ...blocks].join(\"\\n\\n\") + \"\\n\",\n status: \"success\",\n };\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 { resolveUi } from \"../../../core/field/ui\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifyPackageImportsI18n } from \"./modifies/package-imports\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyPrettierignore } from \"./modifies/prettierignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { modifyLayoutServerLocale } from \"./modifies/layout.server\";\nimport { modifyAppDts } from \"./modifies/app-d-ts\";\nimport {\n APP_LAYOUT_PATH,\n modifyAppLayoutLanguageSelect,\n} from \"./modifies/app-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\nimport {\n entriesInProject,\n translateCatalog,\n withTranslations,\n} from \"../../../runtime/wuchale-catalog\";\nimport { AUTH_TRANSLATIONS } from \"../auth/translations\";\nimport {\n TRANSLATED_LIB_FILES,\n withWuchaleJsFiles,\n} from \"../../../runtime/wuchale-config\";\n\n/**\n * The `wuchale.config.js` create, with the library modules that carry\n * visitor-facing text and already exist in the project (the WhatsApp order\n * message, say) listed for the js adapter. A pattern enabled later adds its\n * own module to the written config.\n */\nexport function withLibraryTexts(root: string, creates: File[]): File[] {\n const present = TRANSLATED_LIB_FILES.filter((file) =>\n fs.existsSync(path.join(root, file)),\n );\n if (present.length === 0) return creates;\n return creates.map((file) => {\n if (!file.path.endsWith(\"wuchale.config.js\")) return file;\n const edited = withWuchaleJsFiles(file.content, present);\n return edited?.changed ? { ...file, content: edited.source } : file;\n });\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\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 pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Adding #locales to package.json imports\");\n const imports = modifyPackageImportsI18n(options.root);\n pushResult(modifyOutcomeToFile(imports.filePath, imports.outcome));\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying hooks.ts\");\n const hooksPath = path.join(options.root, \"src\", \"hooks.ts\");\n pushResult(modifyOutcomeToFile(hooksPath, modifyHooksI18n(hooksPath)));\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Declaring the request's language in app.d.ts\");\n const appDtsPath = path.join(options.root, \"src\", \"app.d.ts\");\n pushResult(modifyOutcomeToFile(appDtsPath, modifyAppDts(appDtsPath)));\n\n logger.info(\"Modifying root +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServerLocale(layoutServerPath),\n ),\n );\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const ui = resolveUi(options);\n // With no layout at all, a plain project's not-found hint names the\n // +layout.svelte it would have rather than vela's root-layout.svelte.\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n (ui === \"plain\" ? rootLayoutCandidates[3] : rootLayoutCandidates[0]);\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath, ui),\n ),\n );\n\n // Signed-in pages have one URL for every language; the select is how a\n // visitor changes it there.\n const appLayoutPath = path.join(options.root, APP_LAYOUT_PATH);\n if (fs.existsSync(appLayoutPath)) {\n logger.info(\"Adding the language select to the signed-in layout\");\n pushResult(\n modifyOutcomeToFile(\n appLayoutPath,\n modifyAppLayoutLanguageSelect(appLayoutPath),\n ),\n );\n }\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n logger.info(\"Updating .prettierignore\");\n const prettierignorePath = path.join(options.root, \".prettierignore\");\n pushResult(\n modifyOutcomeToFile(\n prettierignorePath,\n modifyPrettierignore(prettierignorePath),\n ),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n // Spanish for the pages other patterns wrote before this one: without it\n // they stay in English, and nothing says so.\n const shipped = entriesInProject(options.root, AUTH_TRANSLATIONS);\n if (shipped.length > 0)\n logger.info(\"Translating the sign-in pages into Spanish\");\n const creates: File[] = [];\n if (catalog) {\n const content = withTranslations(catalog.content, shipped).source;\n creates.push({ ...catalog, content });\n } else {\n const translated = translateCatalog(options.root, shipped);\n if (translated.create) creates.push(translated.create);\n pushResult(translated.modify);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAKA,IAAMA,IAAe,oLAUfC,IAAiB;AAWvB,SAAgBkC,GAAiB,GAAuC;CACtE,IAAI,CAACJ,EAAG,WAAWK,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAASnC;CAAe;CAOxD,IAAMoC,IAAa,IAJCC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBH,CAAc,GAEzDI,IAAU,IACVC,IAAS;CAMb,AAJkBJ,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAMK,EAAE,wBAAwB,MAAM,cAE1C,MACHL,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,CAAC,GACD,IAAU;CAOZ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IAAqBzG,EAAK,KAAK8F,EAAQ,MAAM,iBAAiB;CACpE,EACEtH,EACEiI,GACAxH,GAAqBwH,CAAkB,CACzC,CACF;CAEA,IAAMC,IAAUtB,GAAmBU,EAAQ,MAAMpB,CAAE;CACnD,AAAIgC,KAASb,EAAO,KAAK,2CAA2C;CAIpE,IAAMc,IAAUhH,GAAiBmG,EAAQ,MAAMlG,CAAiB;CAChE,AAAI+G,EAAQ,SAAS,KACnBd,EAAO,KAAK,4CAA4C;CAC1D,IAAMH,IAAkB,CAAC;CACzB,IAAIgB,GAAS;EACX,IAAME,IAAUnH,GAAiBiH,EAAQ,SAASC,CAAO,CAAC,CAAC;EAC3D,EAAQ,KAAK;GAAE,GAAGD;GAAS;EAAQ,CAAC;CACtC,OAAO;EACL,IAAMG,IAAanH,GAAiBoG,EAAQ,MAAMa,CAAO;EAEzD,AADIE,EAAW,UAAQnB,EAAQ,KAAKmB,EAAW,MAAM,GACrDb,EAAWa,EAAW,MAAM;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"}
|
|
@@ -1,10 +1,10 @@
|
|
|
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-DvIwtj4o.js";
|
|
3
3
|
import { t as n } from "./svelte-file-DfplF3BU.js";
|
|
4
4
|
import { _ as r, f as i, n as a, o, u as s } from "./ts-morph-helpers-B4KZXP44.js";
|
|
5
5
|
import { t as c } from "./unmodify-load-CdWXJ_Ac.js";
|
|
6
6
|
import { r as l } from "./lib-specifier-C3M0WTev.js";
|
|
7
|
-
import { t as u } from "./shared-
|
|
7
|
+
import { t as u } from "./shared-CZHopdly.js";
|
|
8
8
|
import d from "node:fs";
|
|
9
9
|
import f from "node:path";
|
|
10
10
|
import { SyntaxKind as p } from "ts-morph";
|
|
@@ -139,4 +139,4 @@ async function w(n) {
|
|
|
139
139
|
}
|
|
140
140
|
export { w as generate };
|
|
141
141
|
|
|
142
|
-
//# sourceMappingURL=generate.runtime-
|
|
142
|
+
//# sourceMappingURL=generate.runtime-C7NexMXs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-BROXlbeJ.js","names":["getLogger","modifyOutcomeToFile","SvelteFile","withInMemoryScript","removeNavItemFromScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","removeFromLoad","libModule","planDropsForCollections","fs","path","unmodifyNavUser","navUserPath","source","file","wasRemoved","tryRemove","run","result","src","fn","unmodifyLayoutServer","layoutServerPath","unmodifyAppLayoutSvelte","layoutPath","ORIGINAL_HEADER","LEGACY_NAME","TEAM_IMPORTS","TEAM_PROPS","markupOf","revertAppSidebarScript","out","decl","sf","init","nameNode","SyntaxKind","typeNode","member","literal","before","name","remaining","p","pattern","elements","kept","el","moduleSpecifier","markup","formatLikeSource","unmodifyAppSidebar","appSidebarPath","generate","logger","options","modifies","pushResult","navUserCandidates","appLayoutPath"],"sources":["../../src/patterns/disable/teams/modifies/modify-nav-user.ts","../../src/patterns/disable/teams/modifies/+layout.server.ts","../../src/patterns/disable/teams/modifies/modify-app-layout.ts","../../src/patterns/disable/teams/modifies/modify-app-sidebar.ts","../../src/patterns/disable/teams/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/teams\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Teams\",\n \"@lucide/svelte/icons/users\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\n\n/** Take the team loader back out of the (app) layout's load. */\nexport function unmodifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n return removeFromLoad(layoutServerPath, {\n variables: [\"team\", \"teams\"],\n dependsKeys: [\"app:team\"],\n returnProps: [\"team\", \"teams\"],\n });\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Drop the team props enable-teams passed to <AppSidebar>. */\nexport function unmodifyAppLayoutSvelte(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.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n\n file.removeAttribute(\"AppSidebar\", \"team\");\n file.removeAttribute(\"AppSidebar\", \"teams\");\n if (!file.hasChanged()) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\n/** The header enable-auth ships, which the team switcher replaced. */\nconst ORIGINAL_HEADER = `<Sidebar.Header>\n\t\t<Sidebar.Menu>\n\t\t\t<Sidebar.MenuItem>\n\t\t\t\t<Sidebar.MenuButton size=\"lg\">\n\t\t\t\t\t{#snippet child({ props })}\n\t\t\t\t\t\t<a href=\"/dashboard\" {...props}>\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclass=\"bg-sidebar-accent text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img src={favicon} alt=\"logo\" class=\"size-6\" />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class=\"grid flex-1 text-left text-sm leading-tight\">\n\t\t\t\t\t\t\t\t<span class=\"truncate font-medium\">{site.name}</span>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t{/snippet}\n\t\t\t\t</Sidebar.MenuButton>\n\t\t\t</Sidebar.MenuItem>\n\t\t</Sidebar.Menu>\n\t</Sidebar.Header>`;\n\n/**\n * A sidebar from before `#lib/site.js` names the app with a `meta` prop; the\n * header goes back to whichever the team switcher's fallback used.\n */\nconst LEGACY_NAME = \"{meta.appName}\";\n\n/** Imports enable-teams added, dropped once the markup no longer uses them. */\nconst TEAM_IMPORTS: [name: string, module: ModuleMatch][] = [\n [\"TeamSwitcher\", libModule(\"components/team-switcher.svelte\")],\n [\"ChevronsUpDownIcon\", \"@lucide/svelte/icons/chevrons-up-down\"],\n [\"Avatar\", libModule(\"components/ui/avatar\")],\n];\n\nconst TEAM_PROPS = [\"team\", \"teams\"];\n\nfunction markupOf(source: string): string {\n return source.replace(/<script[\\s\\S]*?<\\/script>/g, \"\");\n}\n\nfunction revertAppSidebarScript(source: string, markup: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n\n // Type first: rewriting the binding pattern shifts what follows.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n for (const member of typeNode\n .asKindOrThrow(SyntaxKind.IntersectionType)\n .getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const literal = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const before = literal.getProperties().length;\n for (const name of TEAM_PROPS) {\n literal.getProperty(name)?.remove();\n }\n if (literal.getProperties().length !== before) {\n // Collapse to one line, as enable-auth writes it; prettier keeps\n // whichever shape it finds.\n const remaining = literal\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n literal.replaceWithText(`{ ${remaining.join(\"; \")} }`);\n }\n }\n }\n\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const kept = elements\n .filter((el) => !TEAM_PROPS.includes(el.getName()))\n .map((el) => el.getText());\n if (kept.length !== elements.length) {\n pattern.replaceWithText(`{ ${kept.join(\", \")} }`);\n }\n }\n\n for (const [name, moduleSpecifier] of TEAM_IMPORTS) {\n if (!new RegExp(`\\\\b${name}\\\\b`).test(markup)) {\n removeImportByModuleSpecifier(sf, moduleSpecifier);\n }\n }\n formatLikeSource(sf);\n ensureBlankLineAfterImports(sf);\n });\n return out;\n}\n\n/** Put the plain app-name header back in place of the team switcher. */\nexport function unmodifyAppSidebar(appSidebarPath: string): ModifyOutcome {\n if (!fs.existsSync(appSidebarPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(appSidebarPath);\n if (!file.hasElement(\"TeamSwitcher\")) {\n return { status: \"success\", changed: false };\n }\n\n file.replaceElement(\n \"Sidebar.Header\",\n file.toString().includes(LEGACY_NAME)\n ? ORIGINAL_HEADER.replace(\"{site.name}\", LEGACY_NAME)\n : ORIGINAL_HEADER,\n );\n const markup = markupOf(file.toString());\n file.modifyScript((source) => revertAppSidebarScript(source, markup));\n file.writeTo(appSidebarPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyLayoutServer } from \"./modifies/+layout.server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\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 nav-user.svelte\");\n const navUserCandidates = [\n path.join(options.root, \"src\", \"lib\", \"components\", \"nav-user.svelte\"),\n ];\n const navUserPath =\n navUserCandidates.find((p) => fs.existsSync(p)) ?? navUserCandidates[0];\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting (app) +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServer(layoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, unmodifyAppLayoutSvelte(appLayoutPath)),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n const collectionDrops = await planDropsForCollections(\n // team_users is a view over teams, so it has to go first or PocketBase\n // refuses to drop teams (\"existing reference in team_users\").\n [\n \"team_users\",\n \"team_invite_links\",\n \"team_invites\",\n \"team_memberships\",\n \"teams\",\n ],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAKA,SAAgBY,EAAgB,GAAoC;CAClE,IAAI,CAACF,EAAG,WAAWG,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAASJ,EAAG,aAAaG,GAAa,MAAM;CAClD,IAAI,CAACC,EAAO,SAAS,QAAQ,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAO,IAAIb,EAAWY,CAAM,GAC9BE,IAAa,IAEXC,KAAa,MAAgD;EACjE,AAAID,KACJE,GAAK,MAAQ;GACX,IAAMC,IAASf,EACbgB,GACA,SACA,4BACF;GAEA,OADID,EAAO,eAAY,IAAa,KAC7BA,EAAO;EAChB,CAAC;CACH;CAUA,OARAF,GAAW,MAAOF,EAAK,mBAAmBM,CAAE,CAAC,GACxCL,KAAYC,GAAW,MAAOF,EAAK,aAAaM,CAAE,CAAC,GAEnDL,KAILN,EAAG,cAAcG,GAAaE,EAAK,SAAS,GAAG,MAAM,GAC9C;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAW,SAAS;CAAM;AAK/C;;ACpCA,SAAgBO,EAAqB,GAAyC;CAC5E,OAAOf,EAAegB,GAAkB;EACtC,WAAW,CAAC,QAAQ,OAAO;EAC3B,aAAa,CAAC,UAAU;EACxB,aAAa,CAAC,QAAQ,OAAO;CAC/B,CA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ACE;GACA;GACA;GACA;GACA;EACF,GACA+C,CACF;CAWA;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-C7NexMXs.js","names":["getLogger","modifyOutcomeToFile","SvelteFile","withInMemoryScript","removeNavItemFromScript","ensureBlankLineAfterImports","removeImportByModuleSpecifier","removeFromLoad","libModule","planDropsForCollections","fs","path","unmodifyNavUser","navUserPath","source","file","wasRemoved","tryRemove","run","result","src","fn","unmodifyLayoutServer","layoutServerPath","unmodifyAppLayoutSvelte","layoutPath","ORIGINAL_HEADER","LEGACY_NAME","TEAM_IMPORTS","TEAM_PROPS","markupOf","revertAppSidebarScript","out","decl","sf","init","nameNode","SyntaxKind","typeNode","member","literal","before","name","remaining","p","pattern","elements","kept","el","moduleSpecifier","markup","formatLikeSource","unmodifyAppSidebar","appSidebarPath","generate","logger","options","modifies","pushResult","navUserCandidates","appLayoutPath"],"sources":["../../src/patterns/disable/teams/modifies/modify-nav-user.ts","../../src/patterns/disable/teams/modifies/+layout.server.ts","../../src/patterns/disable/teams/modifies/modify-app-layout.ts","../../src/patterns/disable/teams/modifies/modify-app-sidebar.ts","../../src/patterns/disable/teams/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/teams\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Teams\",\n \"@lucide/svelte/icons/users\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import type { ModifyOutcome } from \"../../../../core/types\";\nimport { removeFromLoad } from \"../../../../runtime/unmodify-load\";\n\n/** Take the team loader back out of the (app) layout's load. */\nexport function unmodifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n return removeFromLoad(layoutServerPath, {\n variables: [\"team\", \"teams\"],\n dependsKeys: [\"app:team\"],\n returnProps: [\"team\", \"teams\"],\n });\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Drop the team props enable-teams passed to <AppSidebar>. */\nexport function unmodifyAppLayoutSvelte(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.hasElement(\"AppSidebar\")) {\n return { status: \"success\", changed: false };\n }\n\n file.removeAttribute(\"AppSidebar\", \"team\");\n file.removeAttribute(\"AppSidebar\", \"teams\");\n if (!file.hasChanged()) {\n return { status: \"success\", changed: false };\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n formatLikeSource,\n type ModuleMatch,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\n/** The header enable-auth ships, which the team switcher replaced. */\nconst ORIGINAL_HEADER = `<Sidebar.Header>\n\t\t<Sidebar.Menu>\n\t\t\t<Sidebar.MenuItem>\n\t\t\t\t<Sidebar.MenuButton size=\"lg\">\n\t\t\t\t\t{#snippet child({ props })}\n\t\t\t\t\t\t<a href=\"/dashboard\" {...props}>\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclass=\"bg-sidebar-accent text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<img src={favicon} alt=\"logo\" class=\"size-6\" />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class=\"grid flex-1 text-left text-sm leading-tight\">\n\t\t\t\t\t\t\t\t<span class=\"truncate font-medium\">{site.name}</span>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t{/snippet}\n\t\t\t\t</Sidebar.MenuButton>\n\t\t\t</Sidebar.MenuItem>\n\t\t</Sidebar.Menu>\n\t</Sidebar.Header>`;\n\n/**\n * A sidebar from before `#lib/site.js` names the app with a `meta` prop; the\n * header goes back to whichever the team switcher's fallback used.\n */\nconst LEGACY_NAME = \"{meta.appName}\";\n\n/** Imports enable-teams added, dropped once the markup no longer uses them. */\nconst TEAM_IMPORTS: [name: string, module: ModuleMatch][] = [\n [\"TeamSwitcher\", libModule(\"components/team-switcher.svelte\")],\n [\"ChevronsUpDownIcon\", \"@lucide/svelte/icons/chevrons-up-down\"],\n [\"Avatar\", libModule(\"components/ui/avatar\")],\n];\n\nconst TEAM_PROPS = [\"team\", \"teams\"];\n\nfunction markupOf(source: string): string {\n return source.replace(/<script[\\s\\S]*?<\\/script>/g, \"\");\n}\n\nfunction revertAppSidebarScript(source: string, markup: string): string {\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n\n // Type first: rewriting the binding pattern shifts what follows.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n for (const member of typeNode\n .asKindOrThrow(SyntaxKind.IntersectionType)\n .getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const literal = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const before = literal.getProperties().length;\n for (const name of TEAM_PROPS) {\n literal.getProperty(name)?.remove();\n }\n if (literal.getProperties().length !== before) {\n // Collapse to one line, as enable-auth writes it; prettier keeps\n // whichever shape it finds.\n const remaining = literal\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n literal.replaceWithText(`{ ${remaining.join(\"; \")} }`);\n }\n }\n }\n\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n const kept = elements\n .filter((el) => !TEAM_PROPS.includes(el.getName()))\n .map((el) => el.getText());\n if (kept.length !== elements.length) {\n pattern.replaceWithText(`{ ${kept.join(\", \")} }`);\n }\n }\n\n for (const [name, moduleSpecifier] of TEAM_IMPORTS) {\n if (!new RegExp(`\\\\b${name}\\\\b`).test(markup)) {\n removeImportByModuleSpecifier(sf, moduleSpecifier);\n }\n }\n formatLikeSource(sf);\n ensureBlankLineAfterImports(sf);\n });\n return out;\n}\n\n/** Put the plain app-name header back in place of the team switcher. */\nexport function unmodifyAppSidebar(appSidebarPath: string): ModifyOutcome {\n if (!fs.existsSync(appSidebarPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(appSidebarPath);\n if (!file.hasElement(\"TeamSwitcher\")) {\n return { status: \"success\", changed: false };\n }\n\n file.replaceElement(\n \"Sidebar.Header\",\n file.toString().includes(LEGACY_NAME)\n ? ORIGINAL_HEADER.replace(\"{site.name}\", LEGACY_NAME)\n : ORIGINAL_HEADER,\n );\n const markup = markupOf(file.toString());\n file.modifyScript((source) => revertAppSidebarScript(source, markup));\n file.writeTo(appSidebarPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyNavUser } from \"./modifies/modify-nav-user\";\nimport { unmodifyLayoutServer } from \"./modifies/+layout.server\";\nimport { unmodifyAppLayoutSvelte } from \"./modifies/modify-app-layout\";\nimport { unmodifyAppSidebar } from \"./modifies/modify-app-sidebar\";\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 nav-user.svelte\");\n const navUserCandidates = [\n path.join(options.root, \"src\", \"lib\", \"components\", \"nav-user.svelte\"),\n ];\n const navUserPath =\n navUserCandidates.find((p) => fs.existsSync(p)) ?? navUserCandidates[0];\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n logger.info(\"Reverting (app) +layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n unmodifyLayoutServer(layoutServerPath),\n ),\n );\n\n logger.info(\"Reverting (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, unmodifyAppLayoutSvelte(appLayoutPath)),\n );\n\n logger.info(\"Reverting app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, unmodifyAppSidebar(appSidebarPath)),\n );\n\n const collectionDrops = await planDropsForCollections(\n // team_users is a view over teams, so it has to go first or PocketBase\n // refuses to drop teams (\"existing reference in team_users\").\n [\n \"team_users\",\n \"team_invite_links\",\n \"team_invites\",\n \"team_memberships\",\n \"teams\",\n ],\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAKA,SAAgBY,EAAgB,GAAoC;CAClE,IAAI,CAACF,EAAG,WAAWG,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAASJ,EAAG,aAAaG,GAAa,MAAM;CAClD,IAAI,CAACC,EAAO,SAAS,QAAQ,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAO,IAAIb,EAAWY,CAAM,GAC9BE,IAAa,IAEXC,KAAa,MAAgD;EACjE,AAAID,KACJE,GAAK,MAAQ;GACX,IAAMC,IAASf,EACbgB,GACA,SACA,4BACF;GAEA,OADID,EAAO,eAAY,IAAa,KAC7BA,EAAO;EAChB,CAAC;CACH;CAUA,OARAF,GAAW,MAAOF,EAAK,mBAAmBM,CAAE,CAAC,GACxCL,KAAYC,GAAW,MAAOF,EAAK,aAAaM,CAAE,CAAC,GAEnDL,KAILN,EAAG,cAAcG,GAAaE,EAAK,SAAS,GAAG,MAAM,GAC9C;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAW,SAAS;CAAM;AAK/C;;ACpCA,SAAgBO,EAAqB,GAAyC;CAC5E,OAAOf,EAAegB,GAAkB;EACtC,WAAW,CAAC,QAAQ,OAAO;EAC3B,aAAa,CAAC,UAAU;EACxB,aAAa,CAAC,QAAQ,OAAO;CAC/B,CAAC;AACH;;ACLA,SAAgBC,EAAwB,GAAmC;CACzE,IAAI,CAACd,EAAG,WAAWe,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMV,IAAOb,EAAW,SAASuB,C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-
import { r as n } from "./modify-file-
|
|
2
|
+
import { a as t } from "./util-mXrQ89nG.js";
|
|
3
|
+
import { r as n } from "./modify-file-DvIwtj4o.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-
|
|
7
|
-
import { m as o, p as s, t as c } from "./generate-
|
|
8
|
-
import { SUCCESS_PAGE as l, t as u } from "./generate.runtime-
|
|
6
|
+
import { t as a } from "./shared-CZHopdly.js";
|
|
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-B9U3kzHD.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-CFSBH8yG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-CFSBH8yG.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,KAAKG,EAAQ,MAAMO,GAAcF,CAAI;EACvD,AAAKT,EAAG,WAAWO,CAAI,KAAKP,EAAG,aAAaO,GAAM,MAAM,MAAMG,KAG9DL,EAAS,KAAK;GACZ,MAAME;GACN,UAAUhB,EAAiBgB,CAAI;GAC/B;GACA,QAAQ;EACV,CAAC;CACH;CAEA,EAAO,KAAK,oCAAoC;CAChD,IAAMK,IAAcX,EAAK,KACvBG,EAAQ,MACR,OACA,OACA,cACA,iBACF;CACA,IAAIJ,EAAG,WAAWY,CAAW,GAAG;EAC9B,IAAMC,IAASb,EAAG,aAAaY,GAAa,MAAM;EAClD,IAAIC,EAAO,SAAS,WAAW,GAAG;GAChC,IAAMN,IAAO,IAAId,EAAWoB,CAAM,GAC9BC,IAAU,IACRC,KAAa,MAAgD;IACjE,AAAID,KACJE,GAAK,MAAQ;KACX,IAAMC,IAASvB,EACbwB,GACA,UACA,8BACF;KAEA,OADID,EAAO,eAAY,IAAU,KAC1BA,EAAO;IAChB,CAAC;GACH;GAGA,IAFAF,GAAW,MAAOR,EAAK,mBAAmBY,CAAE,CAAC,GACxCL,KAASC,GAAW,MAAOR,EAAK,aAAaY,CAAE,CAAC,GACjDL,GAAS;IACX,IAAMM,IAAUb,EAAK,SAAS;IAE9B,AADAP,EAAG,cAAcY,GAAaQ,GAAS,MAAM,GAC7Cf,EAAS,KAAK;KACZ,MAAMO;KACN,UAAUrB,EAAiBqB,CAAW;KACtC,SAASQ;KACT,QAAQ;IACV,CAAC;GACH;EACF;CACF;CASA,OAAO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BzB,EAC5B,CAAC,GAAGG,CAAiB,CAAC,CAAC,QAAQ,GAC/BM,CACF;CAWA;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
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-DvIwtj4o.js";
|
|
3
3
|
import { t as n } from "./dedent-CCUOcPFW.js";
|
|
4
4
|
import { o as r } from "./ts-morph-helpers-B4KZXP44.js";
|
|
5
|
-
import { modifyEnvVarsFiles as i } from "./env-vars-
|
|
5
|
+
import { modifyEnvVarsFiles as i } from "./env-vars-BcHu8247.js";
|
|
6
6
|
import { t as a } from "./env-vars-T3_7JNSg.js";
|
|
7
7
|
import o from "node:fs";
|
|
8
8
|
import s from "node:path";
|
|
@@ -83,4 +83,4 @@ async function g(n) {
|
|
|
83
83
|
}
|
|
84
84
|
export { g as generate };
|
|
85
85
|
|
|
86
|
-
//# sourceMappingURL=generate.runtime-
|
|
86
|
+
//# sourceMappingURL=generate.runtime-CG3udLj8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-CG3udLj8.js","names":["getLogger","modifyOutcomeToFile","dedent","formatLikeSource","WORKFLOWS_ENV_VARS","fs","path","INIT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","ensureNamedImport","existing","sourceFile","d","moduleSpecifier","ni","name","typeOnly","hasInitExport","modifyHooksServerWorkflows","hooksServerPath","Project","QuoteKind","generate","logger","options","creates","modifies","hooksFile","envVars","modifyEnvVarsFiles"],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit/hooks';\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"#lib/server/workflows.js\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n // SvelteKit 3 exposes only declared variables; the template declares these\n // already, an older project gets whichever it is missing.\n logger.info(\"Declaring the workflow variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, WORKFLOWS_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\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,IAAMO,IAAe,CAAM;;;GAKrBC,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;AAS7B,SAASC,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAMC,IAAWC,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAMC,EAAE,wBAAwB,MAAMC,CAAe;CAC9D,AAAKH,IAQDA,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAOI,EAAG,QAAQ,MAAMC,CAAI,KAGjEL,EAAS,eACPM,KAAY,CAACN,EAAS,WAAW,IAAI;EAAE;EAAM,YAAY;CAAK,IAAIK,CACpE,IAZEJ,EAAW,qBAAq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D,IAAMK,IAAUC,EAAmBL,EAAQ,MAAMrB,CAAkB;CAInE,OAHIyB,EAAQ,UAAQH,EAAQ,KAAKG,EAAQ,MAAM,GAC3CA,EAAQ,UAAQF,EAAS,KAAKE,EAAQ,MAAM,GAEzC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
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-DvIwtj4o.js";
|
|
3
3
|
import { t as n } from "./modify-utils--zro3IGe.js";
|
|
4
4
|
import { t as r } from "./dedent-CCUOcPFW.js";
|
|
5
5
|
import { o as i, t as a } from "./ts-morph-helpers-B4KZXP44.js";
|
|
@@ -152,4 +152,4 @@ async function y(r) {
|
|
|
152
152
|
}
|
|
153
153
|
export { y as generate };
|
|
154
154
|
|
|
155
|
-
//# sourceMappingURL=generate.runtime-
|
|
155
|
+
//# sourceMappingURL=generate.runtime-CGbSe_nd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-DuAYqKxl.js","names":["FAILURE_HINT","NOT_FOUND_HINT","getLogger","modifyOutcomeToFile","modifyUtils","dedent","formatLikeSource","addNavItemToScript","SvelteFile","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,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,kBAAkB;CAEnE,IAAI,CAACF,GACH,OAAO;EAAE,QAAQ;EAAU,SAASlB;CAAa;CAGnD,IAAMqB,IAAOH,EA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AAS,KAAKlB,CAAI;CAC9B;CAEA,EAAO,KAAK,2BAA2B;CACvC,IAAMpB,IAAkBJ,EAAK,KAAKyC,EAAQ,MAAM,OAAO,iBAAiB;CAKxE,AAJAE,EACElD,EAAoBW,GAAiBD,EAAkBC,CAAe,CAAC,CACzE,GAEAoC,EAAO,KAAK,oBAAoB;CAChC,IAAMH,IAAcrC,EAAK,KACvByC,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAWlD,EAAoB4C,GAAaD,EAAcC,CAAW,CAAC,CAAC,GAEvEG,EAAO,KAAK,oBAAoB;CAChC,IAAMI,IAAY5C,EAAK,KAAKyC,EAAQ,MAAM,OAAO,OAAO,UAAU;CAGlE,OAFAE,EAAWlD,EAAoBmD,GAAWlD,EAAYkD,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-CGbSe_nd.js","names":["FAILURE_HINT","NOT_FOUND_HINT","getLogger","modifyOutcomeToFile","modifyUtils","dedent","formatLikeSource","addNavItemToScript","SvelteFile","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,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,kBAAkB;CAEnE,IAAI,CAACF,GACH,OAAO;EAAE,QAAQ;EAAU,SAASlB;CAAa;CAGnD,IAAMqB,IAAOH,EAAS,aAAa;CACnC,IAAIG,EAAK,WAAW,GAMlB,OALAH,EAAS,YACP,wDACF,GACAZ,EAAiBU,CAAU,GAC3BA,EAAW,SA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