@velastack/patterns 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/_page-CiazQY4O.js +5 -0
- package/dist/chunks/{_page-DkCd_o3E.js.map → _page-CiazQY4O.js.map} +1 -1
- package/dist/chunks/{auth-pages-mZeR1WIj.js → auth-pages-B8H3kQPW.js} +2 -2
- package/dist/chunks/{auth-pages-mZeR1WIj.js.map → auth-pages-B8H3kQPW.js.map} +1 -1
- package/dist/chunks/{collections-Daxlnbm0.js → collections-CFTIAty-.js} +2 -2
- package/dist/chunks/{collections-Daxlnbm0.js.map → collections-CFTIAty-.js.map} +1 -1
- package/dist/chunks/{env-vars-C3TSZc4f.js → env-vars--fyhY-ew.js} +3 -3
- package/dist/chunks/{env-vars-C3TSZc4f.js.map → env-vars--fyhY-ew.js.map} +1 -1
- package/dist/chunks/{generate-CbchamhA.js → generate-B2z0kA5C.js} +2 -2
- package/dist/chunks/{generate-CbchamhA.js.map → generate-B2z0kA5C.js.map} +1 -1
- package/dist/chunks/{generate-CAYM7OUF.js → generate-BSCDKlyL.js} +2 -2
- package/dist/chunks/{generate-CAYM7OUF.js.map → generate-BSCDKlyL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CZMVPVjS.js → generate.runtime-2T2j6Cgc.js} +5 -5
- package/dist/chunks/{generate.runtime-CZMVPVjS.js.map → generate.runtime-2T2j6Cgc.js.map} +1 -1
- package/dist/chunks/{generate.runtime-_426A1Ij.js → generate.runtime-7rRHLyjy.js} +3 -3
- package/dist/chunks/{generate.runtime-_426A1Ij.js.map → generate.runtime-7rRHLyjy.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bo_s7gYB.js → generate.runtime-9wfx5sJK.js} +2 -2
- package/dist/chunks/{generate.runtime-Bo_s7gYB.js.map → generate.runtime-9wfx5sJK.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B7VubPTW.js → generate.runtime-B6Tce286.js} +3 -3
- package/dist/chunks/{generate.runtime-B7VubPTW.js.map → generate.runtime-B6Tce286.js.map} +1 -1
- package/dist/chunks/{generate.runtime-B11mOr45.js → generate.runtime-B9nqVvxO.js} +2 -2
- package/dist/chunks/{generate.runtime-B11mOr45.js.map → generate.runtime-B9nqVvxO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BL6DpWFI.js → generate.runtime-BCa20dNN.js} +3 -3
- package/dist/chunks/{generate.runtime-BL6DpWFI.js.map → generate.runtime-BCa20dNN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DP63Wwea.js → generate.runtime-BFyTIABc.js} +4 -4
- package/dist/chunks/{generate.runtime-DP63Wwea.js.map → generate.runtime-BFyTIABc.js.map} +1 -1
- package/dist/chunks/{generate.runtime-VZIxJWlr.js → generate.runtime-B_md4EZa.js} +15 -15
- package/dist/chunks/{generate.runtime-VZIxJWlr.js.map → generate.runtime-B_md4EZa.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BjTZ2Ls-.js → generate.runtime-BpXoagaq.js} +3 -3
- package/dist/chunks/{generate.runtime-BjTZ2Ls-.js.map → generate.runtime-BpXoagaq.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DW9bqOtC.js → generate.runtime-C1zb2WxI.js} +2 -2
- package/dist/chunks/{generate.runtime-DW9bqOtC.js.map → generate.runtime-C1zb2WxI.js.map} +1 -1
- package/dist/chunks/{generate.runtime-373mTxeo.js → generate.runtime-C4R919oE.js} +2 -2
- package/dist/chunks/{generate.runtime-373mTxeo.js.map → generate.runtime-C4R919oE.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BCv4F1Wm.js → generate.runtime-C4qZ7Q30.js} +4 -4
- package/dist/chunks/{generate.runtime-BCv4F1Wm.js.map → generate.runtime-C4qZ7Q30.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C90_2L-8.js → generate.runtime-C8xFPEgP.js} +2 -2
- package/dist/chunks/{generate.runtime-C90_2L-8.js.map → generate.runtime-C8xFPEgP.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cs73i6Zf.js → generate.runtime-CC4XoTnb.js} +2 -2
- package/dist/chunks/{generate.runtime-Cs73i6Zf.js.map → generate.runtime-CC4XoTnb.js.map} +1 -1
- package/dist/chunks/{generate.runtime-jIlQ2GMh.js → generate.runtime-CCL_doqr.js} +2 -2
- package/dist/chunks/{generate.runtime-jIlQ2GMh.js.map → generate.runtime-CCL_doqr.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BEWp57Y7.js → generate.runtime-CKyi82cZ.js} +2 -2
- package/dist/chunks/{generate.runtime-BEWp57Y7.js.map → generate.runtime-CKyi82cZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DgKiFemb.js → generate.runtime-CNHEuhx4.js} +3 -3
- package/dist/chunks/{generate.runtime-DgKiFemb.js.map → generate.runtime-CNHEuhx4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DIIeK2w9.js → generate.runtime-CPF0TcjM.js} +3 -3
- package/dist/chunks/{generate.runtime-DIIeK2w9.js.map → generate.runtime-CPF0TcjM.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DmbDEjMA.js → generate.runtime-CWNIo1xQ.js} +3 -3
- package/dist/chunks/{generate.runtime-DmbDEjMA.js.map → generate.runtime-CWNIo1xQ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CDY0Ot_t.js → generate.runtime-Cb2u0ft4.js} +5 -5
- package/dist/chunks/{generate.runtime-CDY0Ot_t.js.map → generate.runtime-Cb2u0ft4.js.map} +1 -1
- package/dist/chunks/{generate.runtime-ChSVP7cD.js → generate.runtime-CdpLsiqC.js} +4 -4
- package/dist/chunks/{generate.runtime-ChSVP7cD.js.map → generate.runtime-CdpLsiqC.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DVZUNxtv.js → generate.runtime-ChstrVRw.js} +4 -4
- package/dist/chunks/{generate.runtime-DVZUNxtv.js.map → generate.runtime-ChstrVRw.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bhs7ttZS.js → generate.runtime-CpDUk3Ev.js} +2 -2
- package/dist/chunks/{generate.runtime-Bhs7ttZS.js.map → generate.runtime-CpDUk3Ev.js.map} +1 -1
- package/dist/chunks/{generate.runtime-xrxAElb3.js → generate.runtime-Ctd_522e.js} +3 -3
- package/dist/chunks/{generate.runtime-xrxAElb3.js.map → generate.runtime-Ctd_522e.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Bn17HK_S.js → generate.runtime-CviYhOWW.js} +198 -115
- package/dist/chunks/generate.runtime-CviYhOWW.js.map +1 -0
- package/dist/chunks/{generate.runtime-BRV9hIl5.js → generate.runtime-CxJaHusI.js} +2 -2
- package/dist/chunks/{generate.runtime-BRV9hIl5.js.map → generate.runtime-CxJaHusI.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DRPxOLnB.js → generate.runtime-D0acTMRF.js} +4 -4
- package/dist/chunks/{generate.runtime-DRPxOLnB.js.map → generate.runtime-D0acTMRF.js.map} +1 -1
- package/dist/chunks/{generate.runtime-fs6GEMx-.js → generate.runtime-D6vRzBoU.js} +4 -4
- package/dist/chunks/{generate.runtime-fs6GEMx-.js.map → generate.runtime-D6vRzBoU.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BRcP6sFt.js → generate.runtime-D7aGjoTD.js} +2 -2
- package/dist/chunks/{generate.runtime-BRcP6sFt.js.map → generate.runtime-D7aGjoTD.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DG9LRwbt.js → generate.runtime-DPtjvhGr.js} +2 -2
- package/dist/chunks/{generate.runtime-DG9LRwbt.js.map → generate.runtime-DPtjvhGr.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BjrtdoYE.js → generate.runtime-DmHZZz4Z.js} +2 -2
- package/dist/chunks/{generate.runtime-BjrtdoYE.js.map → generate.runtime-DmHZZz4Z.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DXqBku2y.js → generate.runtime-O5eQdhHV.js} +4 -4
- package/dist/chunks/{generate.runtime-DXqBku2y.js.map → generate.runtime-O5eQdhHV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DKL7VAAd.js → generate.runtime-Uq_L7TtO.js} +5 -5
- package/dist/chunks/{generate.runtime-DKL7VAAd.js.map → generate.runtime-Uq_L7TtO.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C_hrLPD4.js → generate.runtime-VWQfzXXv.js} +3 -3
- package/dist/chunks/{generate.runtime-C_hrLPD4.js.map → generate.runtime-VWQfzXXv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-v3KCv1B6.js → generate.runtime-WL1mm8gp.js} +2 -2
- package/dist/chunks/{generate.runtime-v3KCv1B6.js.map → generate.runtime-WL1mm8gp.js.map} +1 -1
- package/dist/chunks/{generate.runtime-sey-wxXB.js → generate.runtime-vJFz9Q7V.js} +7 -7
- package/dist/chunks/{generate.runtime-sey-wxXB.js.map → generate.runtime-vJFz9Q7V.js.map} +1 -1
- package/dist/chunks/{gitignore-CBiWFRif.js → gitignore-DUzIQXIo.js} +2 -2
- package/dist/chunks/{gitignore-CBiWFRif.js.map → gitignore-DUzIQXIo.js.map} +1 -1
- package/dist/chunks/{i18n-Ho8H91Ze.js → i18n-BoYcqVBi.js} +2 -2
- package/dist/chunks/{i18n-Ho8H91Ze.js.map → i18n-BoYcqVBi.js.map} +1 -1
- package/dist/chunks/{modify-file-BOEKlIDw.js → modify-file-DRdmZIvW.js} +2 -2
- package/dist/chunks/{modify-file-BOEKlIDw.js.map → modify-file-DRdmZIvW.js.map} +1 -1
- package/dist/chunks/{pocketbase-CvsJYXj-.js → pocketbase-BrDs1_84.js} +23 -7
- package/dist/chunks/pocketbase-BrDs1_84.js.map +1 -0
- package/dist/chunks/{providers-BEjDonyG.js → providers-Dhr_mzm6.js} +2 -2
- package/dist/chunks/{providers-BEjDonyG.js.map → providers-Dhr_mzm6.js.map} +1 -1
- package/dist/chunks/{schema-DnMqw2Hn.js → schema-C16iVOAG.js} +2 -2
- package/dist/chunks/{schema-DnMqw2Hn.js.map → schema-C16iVOAG.js.map} +1 -1
- package/dist/chunks/{shared-CSwGWMcN.js → shared-D7-ZAoqr.js} +2 -2
- package/dist/chunks/{shared-CSwGWMcN.js.map → shared-D7-ZAoqr.js.map} +1 -1
- package/dist/chunks/{ui-CpjUq_lm.js → ui-BI9OQpuR.js} +2 -2
- package/dist/chunks/{ui-CpjUq_lm.js.map → ui-BI9OQpuR.js.map} +1 -1
- package/dist/chunks/{write-result-DlB-id5k.js → write-result-Do8AcYbL.js} +2 -2
- package/dist/chunks/{write-result-DlB-id5k.js.map → write-result-Do8AcYbL.js.map} +1 -1
- package/dist/index.js +2161 -2152
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/_page-DkCd_o3E.js +0 -5
- package/dist/chunks/generate.runtime-Bn17HK_S.js.map +0 -1
- package/dist/chunks/pocketbase-CvsJYXj-.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-B11mOr45.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,IAAMM,IAJmBN,EACtB,qBAAqBO,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,cAE/B,CAAA,EAAkB,aAAa,CAAC,GAAG,IAC/CC,IACJH,GAAW,QAAQ,MAAMC,EAAW,0BAC/BD,IACD;CAEN,IAAI,CAACG,GACH,IAAS;MACJ;EACL,IAAMC,IAAcD,EAAU,YAAY,SAAS;EACnD,IAAI,CAACC,GAKH,AAJAD,EAAU,sBAAsB;GAC9B,MAAM;GACN,aAAa;EACf,CAAC,GACD,IAAU;OACL,IAAIC,EAAY,QAAQ,M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,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-B9nqVvxO.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,IAAMM,IAJmBN,EACtB,qBAAqBO,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAOC,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,cAE/B,CAAA,EAAkB,aAAa,CAAC,GAAG,IAC/CC,IACJH,GAAW,QAAQ,MAAMC,EAAW,0BAC/BD,IACD;CAEN,IAAI,CAACG,GACH,IAAS;MACJ;EACL,IAAMC,IAAcD,EAAU,YAAY,SAAS;EACnD,IAAI,CAACC,GAKH,AAJAD,EAAU,sBAAsB;GAC9B,MAAM;GACN,aAAa;EACf,CAAC,GACD,IAAU;OACL,IAAIC,EAAY,QAAQ,MAAMH,EAAW,oBAC9C,IAAS;OACJ;GACL,IAAMI,IACJD,EACA,eAAe;GAEjB,IAAI,CAACC,GAIH,AAHAD,EAAuD,eACrD,aACF,GACA,IAAU;QACL,IAAIC,EAAY,QAAQ,MAAMJ,EAAW,wBAC9C,IAAS;QACJ;IACL,IAAMK,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,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,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-DRdmZIvW.js";
|
|
3
3
|
import { f as n, o as r } from "./ts-morph-helpers-B4KZXP44.js";
|
|
4
4
|
import { t as i } from "./svelte-file-DfplF3BU.js";
|
|
5
|
-
import { t as a } from "./shared-
|
|
5
|
+
import { t as a } from "./shared-D7-ZAoqr.js";
|
|
6
6
|
import o from "node:fs";
|
|
7
7
|
import s from "node:path";
|
|
8
8
|
import { Project as c, SyntaxKind as l } from "ts-morph";
|
|
@@ -88,4 +88,4 @@ async function f(n) {
|
|
|
88
88
|
}
|
|
89
89
|
export { f as generate };
|
|
90
90
|
|
|
91
|
-
//# sourceMappingURL=generate.runtime-
|
|
91
|
+
//# sourceMappingURL=generate.runtime-BCa20dNN.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-BCa20dNN.js","names":["apiObj","getLogger","modifyOutcomeToFile","removeNavItemFromScript","formatLikeSource","SvelteFile","planDropsForCollections","fs","path","unmodifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","firstArg","apiProp","apiInit","apiKeysProp","unmodifyNavUser","navUserPath","source","file","wasRemoved","tryRemove","run","result","src","fn","generate","logger","options","modifies","pushResult"],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;AAKA,SAAgBS,EAAoB,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t } from "./env-AxyRWcC_.js";
|
|
3
|
-
import { r as n, t as r } from "./modify-file-
|
|
4
|
-
import { n as i, t as a } from "./generate-
|
|
5
|
-
import { unmodifyEnvVarsFiles as o } from "./env-vars-
|
|
3
|
+
import { r as n, t as r } from "./modify-file-DRdmZIvW.js";
|
|
4
|
+
import { n as i, t as a } from "./generate-BSCDKlyL.js";
|
|
5
|
+
import { unmodifyEnvVarsFiles as o } from "./env-vars--fyhY-ew.js";
|
|
6
6
|
import { t as s } from "./svelte-file-DfplF3BU.js";
|
|
7
7
|
import { _ as c, n as l, u } from "./ts-morph-helpers-B4KZXP44.js";
|
|
8
8
|
import { r as d } from "./lib-specifier-C3M0WTev.js";
|
|
@@ -60,4 +60,4 @@ async function g(s) {
|
|
|
60
60
|
}
|
|
61
61
|
export { g as generate };
|
|
62
62
|
|
|
63
|
-
//# sourceMappingURL=generate.runtime-
|
|
63
|
+
//# sourceMappingURL=generate.runtime-BFyTIABc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-BFyTIABc.js","names":["getLogger","modifyEnvRemove","modifyOutcomeToFile","envRevertOutcomeToFile","allEnvNames","allEnvEdits","SvelteFile","withInMemoryScript","ensureBlankLineAfterImports","libModule","fs","path","MODULE","unmodifyLayoutSvelte","layoutPath","original","file","out","source","removeImportByModuleSpecifier","sf","updated","generate","logger","options","modifies","deletes","pushResult","envVars","unmodifyEnvVarsFiles","envPath","env"],"sources":["../../src/patterns/disable/analytics/modifies/layout.svelte.ts","../../src/patterns/disable/analytics/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureBlankLineAfterImports,\n removeImportByModuleSpecifier,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { libModule } from \"../../../../runtime/lib-specifier\";\n\nconst MODULE = \"components/analytics/analytics.svelte\";\n\n/**\n * Takes `<Analytics />` and its import back out of the root layout. The\n * element goes with its whole line, since enable-analytics put it on one of\n * its own. A layout without it, or no layout at all, is left alone.\n */\nexport function unmodifyLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(layoutPath, \"utf8\");\n if (!original.includes(MODULE) && !original.includes(\"<Analytics\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n removeImportByModuleSpecifier(sf, libModule(MODULE));\n ensureBlankLineAfterImports(sf);\n });\n return out;\n });\n\n const updated = file\n .toString()\n .replace(/[ \\t]*<Analytics\\s*\\/>[ \\t]*\\r?\\n?/g, \"\");\n\n if (updated === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(layoutPath, updated, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyEnvRemove } from \"../../../runtime/env\";\nimport {\n envRevertOutcomeToFile,\n modifyOutcomeToFile,\n} from \"../../../runtime/modify-file\";\nimport { allEnvEdits, allEnvNames } from \"./generate\";\nimport { unmodifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { unmodifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const deletes: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, unmodifyLayoutSvelte(layoutPath)));\n\n // Which provider was chosen is not recorded, so every one's variables go;\n // the file goes too when these were all it declared.\n logger.info(\"Removing analytics variables from src/env.ts\");\n const envVars = unmodifyEnvVarsFiles(options.root, allEnvNames());\n pushResult(envVars.modify);\n if (envVars.delete) deletes.push(envVars.delete);\n\n logger.info(\"Removing analytics variables from .env\");\n const envPath = path.join(options.root, \".env\");\n const env = envRevertOutcomeToFile(\n envPath,\n modifyEnvRemove(envPath, allEnvEdits()),\n );\n pushResult(env.modify);\n if (env.delete) deletes.push(env.delete);\n\n return {\n creates: [],\n modifies,\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAMY,IAAS;AAOf,SAAgBC,EAAqB,GAAmC;CACtE,IAAI,CAACH,EAAG,WAAWI,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWL,EAAG,aAAaI,GAAY,MAAM;CACnD,IAAI,CAACC,EAAS,SAASH,CAAM,KAAK,CAACG,EAAS,SAAS,YAAY,GAC/D,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOV,EAAW,SAASQ,CAAU;CAC3C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQG,MAAQV,EAAmBW,IAAS,MAAO;GAEzD,AADAC,EAA8BC,GAAIX,EAAUG,CAAM,CAAC,GACnDJ,EAA4BY,CAAE;EAChC,CAAC;EACD,OAAOH;CACT,CAAC;CAED,IAAMI,IAAUL,EACb,SAAS,CAAC,CACV,QAAQ,uCAAuC,EAAE;CAMpD,OAJIK,MAAYN,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAE7CL,EAAG,cAAcI,GAAYO,GAAS,MAAM,GACrC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;ACjCA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,IAAkB,CAAC,GACnBC,KAAc,MAAsB;EACxC,AAAIX,KAAMS,EAAS,KAAKT,CAAI;CAC9B;CAEA,EAAO,KAAK,qCAAqC;CACjD,IAAMF,IAAaH,EAAK,KAAKa,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAK5E,AAJAG,EAAWzB,EAAoBY,GAAYD,EAAqBC,CAAU,CAAC,CAAC,GAI5ES,EAAO,KAAK,8CAA8C;CAC1D,IAAMK,IAAUC,EAAqBL,EAAQ,MAAMpB,EAAY,CAAC;CAIhE,AAHAuB,EAAWC,EAAQ,MAAM,GACrBA,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAE/CL,EAAO,KAAK,wCAAwC;CACpD,IAAMO,IAAUnB,EAAK,KAAKa,EAAQ,MAAM,MAAM,GACxCO,IAAM5B,EACV2B,GACA7B,EAAgB6B,GAASzB,EAAY,CAAC,CACxC;CAIA,OAHAsB,EAAWI,EAAI,MAAM,GACjBA,EAAI,UAAQL,EAAQ,KAAKK,EAAI,MAAM,GAEhC;EACL,SAAS,CAAC;EACV;EACA;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
|
-
import {
|
|
2
|
+
import { i as t, n, o as r } from "./collections-CFTIAty-.js";
|
|
3
3
|
import { i, n as a, t as o } from "./pocketbase-B2ksFrvH.js";
|
|
4
|
-
import { r as s } from "./modify-file-
|
|
4
|
+
import { r as s } from "./modify-file-DRdmZIvW.js";
|
|
5
5
|
import { t as c } from "./modify-utils--zro3IGe.js";
|
|
6
6
|
import { t as l } from "./dedent-CCUOcPFW.js";
|
|
7
7
|
import { t as u } from "./svelte-file-DfplF3BU.js";
|
|
@@ -200,16 +200,16 @@ function A(e) {
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
// src/patterns/enable/notifications/generate.runtime.ts
|
|
203
|
-
async function j(e,
|
|
203
|
+
async function j(e, t, n, i = !0) {
|
|
204
204
|
if (!i) return;
|
|
205
205
|
await a();
|
|
206
|
-
let s = o(
|
|
207
|
-
s && e.push(await
|
|
206
|
+
let s = o(t, "created", n);
|
|
207
|
+
s && e.push(await r(s, n));
|
|
208
208
|
}
|
|
209
|
-
async function M(
|
|
210
|
-
let a = e(
|
|
211
|
-
await i(
|
|
212
|
-
let i = await e.collections.getOne("users"), s = (
|
|
209
|
+
async function M(r) {
|
|
210
|
+
let a = e(r), o = [];
|
|
211
|
+
await i(r.root, async (e) => {
|
|
212
|
+
let i = await e.collections.getOne("users"), s = (n) => t(e, n, a);
|
|
213
213
|
a.info("Creating notifications collection");
|
|
214
214
|
let c = await s({
|
|
215
215
|
name: "notifications",
|
|
@@ -262,19 +262,19 @@ async function M(t) {
|
|
|
262
262
|
],
|
|
263
263
|
indexes: ["CREATE INDEX `idx_notifications_user_read_created` ON `notifications` (`user`, `read`, `created` DESC)"]
|
|
264
264
|
});
|
|
265
|
-
await j(o, "notifications",
|
|
266
|
-
let l = await
|
|
265
|
+
await j(o, "notifications", r, c.created), a.info("Applying notifications rule patches");
|
|
266
|
+
let l = await n(e, h, r, a);
|
|
267
267
|
o.push(...l);
|
|
268
268
|
});
|
|
269
269
|
let l = [], u = (e) => {
|
|
270
270
|
e && l.push(e);
|
|
271
271
|
};
|
|
272
272
|
a.info("Modifying (app) +layout.svelte");
|
|
273
|
-
let d = _.join(
|
|
273
|
+
let d = _.join(r.root, "src", "routes", "(app)", "+layout.svelte");
|
|
274
274
|
u(s(d, w(d))), a.info("Modifying (app) +layout.server.ts");
|
|
275
|
-
let f = _.join(
|
|
275
|
+
let f = _.join(r.root, "src", "routes", "(app)", "+layout.server.ts");
|
|
276
276
|
u(s(f, A(f))), a.info("Modifying utils.ts");
|
|
277
|
-
let p = _.join(
|
|
277
|
+
let p = _.join(r.root, "src", "lib", "utils.ts");
|
|
278
278
|
return u(s(p, c(p))), {
|
|
279
279
|
creates: o,
|
|
280
280
|
modifies: l,
|
|
@@ -288,4 +288,4 @@ async function M(t) {
|
|
|
288
288
|
}
|
|
289
289
|
export { M as generate };
|
|
290
290
|
|
|
291
|
-
//# sourceMappingURL=generate.runtime-
|
|
291
|
+
//# sourceMappingURL=generate.runtime-B_md4EZa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-VZIxJWlr.js","names":["getLogger","readMigration","createCollectionIdempotent","applyCollectionRulePatches","migrationDelay","getMigrationFile","modifyOutcomeToFile","modifyUtils","dedent","SvelteFile","withInMemoryScript","ensureNamedImport","formatLikeSource","ensureImports","NOTIFICATION_RULE_PATCHES","fs","path","BELL_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyAppLayout","layoutPath","file","out","source","sf","AUTH_MODULE","USER_STATEMENT","FETCH_STATEMENT","NOTIFICATIONS_STATEMENT","DEPENDS_STATEMENT","modifyLayoutServer","layoutServerPath","snippet","originalSource","sourceFile","Project","addProperty","obj","name","initializer","loadArrow","loadFn","varDecl","SyntaxKind","directArrow","init","innerArrow","innerFnExpr","maybeFn","fnLike","params","first","original","nameNode","obp","elementNames","el","hasDepends","hasLocals","existingParts","parts","currentName","body","blockBody","statements","declaresVar","stmt","d","hasDependsCall","ce","args","argText","hasNotificationsList","hasNotifications","current","returnIdx","s","insertAt","augmentReturnObject","augmentReturns","expr","ret","inner","arrowBody","bodyExpr","fnBody","pushMigrationCreates","created","migrationFile","collectionName","options","creates","generate","logger","withPocketbase","userCollection","pb","create","spec","result","ruleMigrations","modifies","pushResult","appLayoutPath","appLayoutServerPath","utilsPath"],"sources":["../../src/patterns/enable/notifications/modifies/modify-app-layout.ts","../../src/patterns/enable/notifications/modifies/+layout.server.ts","../../src/patterns/enable/notifications/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst BELL_SNIPPET = `\n\t\t<div class=\"ml-auto px-4\">\n\t\t\t<NotificationsBell />\n\t\t</div>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import NotificationsBell from '#lib/components/notifications-bell.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the notifications bell inside the (app) layout's <header>.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <header>:\",\n BELL_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.svelte with a <header> that includes the bell.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <header>:\",\n BELL_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyAppLayout(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"header\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"NotificationsBell\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"NotificationsBell\",\n moduleSpecifier: \"#lib/components/notifications-bell.svelte\",\n },\n ]);\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"header\", BELL_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst AUTH_MODULE = \"@velastack/pocketbase/auth\";\n\n/** For a load that has no `user` yet: the stock (app) layout declares one. */\nconst USER_STATEMENT = \"const user = requireUser();\";\n\nconst FETCH_STATEMENT = dedent`\n const notificationsList = await locals.pb\n .collection(\"notifications\")\n .getList(1, 5, {\n filter: locals.pb.filter(\"user = {:user} && read = false\", {\n user: user.id,\n }),\n sort: \"-created\",\n });\n`;\n\nconst NOTIFICATIONS_STATEMENT =\n \"const notifications = { count: notificationsList.totalItems, items: notificationsList.items };\";\n\nconst DEPENDS_STATEMENT = 'depends(\"app:notifications\");';\n\nexport function modifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n const snippet = dedent`\n import { requireUser } from \"${AUTH_MODULE}\";\n\n export const load = async ({ locals, depends }) => {\n ${USER_STATEMENT}\n ${FETCH_STATEMENT}\n ${NOTIFICATIONS_STATEMENT}\n ${DEPENDS_STATEMENT}\n return { notifications };\n };\n `;\n fs.writeFileSync(layoutServerPath, snippet);\n return { status: \"success\", changed: true };\n }\n\n const originalSource = fs.readFileSync(layoutServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutServerPath);\n\n const addProperty = (\n obj: import(\"ts-morph\").ObjectLiteralExpression,\n name: string,\n initializer: string,\n ) => {\n if (obj.getProperty(name)) return;\n if (name === initializer) {\n obj.addShorthandPropertyAssignment({ name });\n } else {\n obj.addPropertyAssignment({ name, initializer });\n }\n };\n\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n if (vs?.hasExportKeyword()) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n\n if (!loadArrow && !loadFn) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) loadFn = maybeFn;\n }\n\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals, depends }\" }],\n statements: [\n USER_STATEMENT,\n FETCH_STATEMENT,\n NOTIFICATIONS_STATEMENT,\n DEPENDS_STATEMENT,\n \"return { notifications };\",\n ],\n });\n ensureNamedImport(sourceFile, AUTH_MODULE, \"requireUser\");\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const fnLike = (loadArrow ?? loadFn!) as\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression;\n\n // Ensure first param destructures { locals, depends }\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals, depends }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const elementNames = obp.getElements().map((el) => el.getName());\n const hasDepends = elementNames.includes(\"depends\");\n const hasLocals = elementNames.includes(\"locals\");\n\n if (!hasDepends || !hasLocals) {\n const existingParts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const parts: string[] = hasLocals ? [] : [\"locals\"];\n parts.push(...existingParts);\n if (!hasDepends) parts.push(\"depends\");\n first.set({\n name: `{ ${parts.join(\", \")} }`,\n type: original.type,\n initializer: (original as { initializer?: string }).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, depends, ...${currentName} }`,\n type: original.type,\n initializer: (original as { initializer?: string }).initializer,\n });\n } else {\n first.set({\n name: `{ locals, depends }`,\n type: original.type,\n initializer: (original as { initializer?: string }).initializer,\n });\n }\n }\n }\n\n if (loadArrow && !loadArrow.isAsync()) loadArrow.setIsAsync(true);\n else if (loadFn && !loadFn.isAsync()) loadFn.setIsAsync(true);\n\n const body = fnLike.getBody();\n if (body && body.getKind() === SyntaxKind.Block) {\n const blockBody = body as import(\"ts-morph\").Block;\n const statements = blockBody.getStatements();\n\n const declaresVar = (name: string) =>\n statements.some((stmt) => {\n if (stmt.getKind() !== SyntaxKind.VariableStatement) return false;\n return (stmt as import(\"ts-morph\").VariableStatement)\n .getDeclarations()\n .some((d) => d.getName() === name);\n });\n\n const hasDependsCall = statements.some(\n (stmt) =>\n stmt.getKind() === SyntaxKind.ExpressionStatement &&\n stmt.getDescendantsOfKind(SyntaxKind.CallExpression).some((ce) => {\n if (ce.getExpression().getText() !== \"depends\") return false;\n const args = ce.getArguments();\n const argText = args[0]?.getText() ?? \"\";\n return (\n args.length === 1 &&\n (argText === \"'app:notifications'\" ||\n argText === '\"app:notifications\"')\n );\n }),\n );\n\n const hasNotificationsList = declaresVar(\"notificationsList\");\n const hasNotifications = declaresVar(\"notifications\");\n\n // The query filters on `user.id`. A load written by enable-auth has the\n // user already, by either name for it (`requireUser()` now,\n // `locals.pb.authStore.record!` before); any other gets it first.\n if (!hasNotificationsList && !declaresVar(\"user\")) {\n blockBody.insertStatements(0, USER_STATEMENT);\n ensureNamedImport(sourceFile, AUTH_MODULE, \"requireUser\");\n }\n\n const current = blockBody.getStatements();\n const returnIdx = current.findIndex(\n (s) => s.getKind() === SyntaxKind.ReturnStatement,\n );\n let insertAt = returnIdx >= 0 ? returnIdx : current.length;\n\n if (!hasNotificationsList) {\n blockBody.insertStatements(insertAt, FETCH_STATEMENT);\n insertAt++;\n }\n if (!hasNotifications) {\n blockBody.insertStatements(insertAt, NOTIFICATIONS_STATEMENT);\n insertAt++;\n }\n if (!hasDependsCall) {\n blockBody.insertStatements(insertAt, DEPENDS_STATEMENT);\n }\n }\n\n const augmentReturnObject = (\n obj: import(\"ts-morph\").ObjectLiteralExpression,\n ) => {\n addProperty(obj, \"notifications\", \"notifications\");\n };\n\n const augmentReturns = (target: import(\"ts-morph\").Node) => {\n const returns = target.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(\n inner as import(\"ts-morph\").ObjectLiteralExpression,\n );\n }\n }\n });\n };\n\n if (loadArrow) {\n const arrowBody = loadArrow.getBody();\n if (arrowBody.getKind() === SyntaxKind.Block) {\n augmentReturns(arrowBody);\n } else {\n const bodyExpr = arrowBody as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(\n inner as import(\"ts-morph\").ObjectLiteralExpression,\n );\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(\n bodyExpr as import(\"ts-morph\").ObjectLiteralExpression,\n );\n }\n }\n } else if (loadFn) {\n const fnBody = loadFn.getBody();\n if (fnBody) augmentReturns(fnBody);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n applyCollectionRulePatches,\n createCollectionIdempotent,\n readMigration,\n} from \"../../../runtime/collections\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyUtils } from \"../../../runtime/modify-utils\";\nimport { modifyAppLayout } from \"./modifies/modify-app-layout\";\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { NOTIFICATION_RULE_PATCHES } from \"./runtime/pocketbase\";\n\nasync function pushMigrationCreates(\n creates: File[],\n collectionName: string,\n options: Options,\n created = true,\n) {\n if (!created) return;\n await migrationDelay();\n const migrationFile = getMigrationFile(collectionName, \"created\", options);\n if (!migrationFile) return;\n creates.push(await readMigration(migrationFile, options));\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n const userCollection = await pb.collections.getOne(\"users\");\n const create = (spec: Parameters<typeof createCollectionIdempotent>[1]) =>\n createCollectionIdempotent(pb, spec, logger);\n\n logger.info(\"Creating notifications collection\");\n const result = await create({\n name: \"notifications\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n type: \"text\",\n primaryKey: true,\n autogeneratePattern: \"[a-z0-9]{15}\",\n max: 15,\n min: 15,\n pattern: \"^[a-z0-9]+$\",\n required: true,\n },\n {\n name: \"user\",\n type: \"relation\",\n cascadeDelete: true,\n collectionId: userCollection.id,\n maxSelect: 1,\n minSelect: 0,\n required: true,\n },\n {\n name: \"title\",\n type: \"text\",\n required: true,\n },\n {\n name: \"body\",\n type: \"text\",\n },\n {\n name: \"read\",\n type: \"bool\",\n },\n {\n name: \"created\",\n type: \"autodate\",\n onCreate: true,\n onUpdate: false,\n },\n {\n name: \"updated\",\n type: \"autodate\",\n onCreate: true,\n onUpdate: true,\n },\n ],\n indexes: [\n \"CREATE INDEX `idx_notifications_user_read_created` ON `notifications` (`user`, `read`, `created` DESC)\",\n ],\n });\n await pushMigrationCreates(\n creates,\n \"notifications\",\n options,\n result.created,\n );\n\n logger.info(\"Applying notifications rule patches\");\n const ruleMigrations = await applyCollectionRulePatches(\n pb,\n NOTIFICATION_RULE_PATCHES,\n options,\n logger,\n );\n creates.push(...ruleMigrations);\n });\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, modifyAppLayout(appLayoutPath)),\n );\n\n logger.info(\"Modifying (app) +layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n modifyLayoutServer(appLayoutServerPath),\n ),\n );\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":";;;;;;;;;;;;;AASA,IAAMiB,IAAe,2EAMfC,IAAiB,CAAM;;GAIvBC,IAAe;CACnB;CACA;CACA;CACA;CACAD;CACA;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI,GAELG,IAAiB;CACrB;CACA;CACA;CACA;CACAF;CACA;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgBI,EAAgB,GAAmC;CACjE,IAAI,CAACN,EAAG,WAAWO,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAGxD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AU;IACZ;IACA;KACE,MAAM;KACN,MAAM;KACN,UAAU;KACV,UAAU;IACZ;GACF;GACA,SAAS,CACP,wGACF;EACF,CAAC;EAQD,AAPA,MAAMT,EACJK,GACA,iBACAD,GACAS,EAAO,OACT,GAEAN,EAAO,KAAK,qCAAqC;EACjD,IAAMO,IAAiB,MAAMnG,EAC3B+F,GACApF,GACA8E,GACAG,CACF;EACA,EAAQ,KAAK,GAAGO,CAAc;CAChC,CAAC;CAED,IAAMC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIjF,KAAMgF,EAAS,KAAKhF,CAAI;CAC9B;CAEA,EAAO,KAAK,gCAAgC;CAC5C,IAAMkF,IAAgBzF,EAAK,KACzB4E,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAKA,AAJAY,EACElG,EAAoBmG,GAAepF,EAAgBoF,CAAa,CAAC,CACnE,GAEAV,EAAO,KAAK,mCAAmC;CAC/C,IAAMW,IAAsB1F,EAAK,KAC/B4E,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAQA,AAPAY,EACElG,EACEoG,GACA1E,EAAmB0E,CAAmB,CACxC,CACF,GAEAX,EAAO,KAAK,oBAAoB;CAChC,IAAMY,IAAY3F,EAAK,KAAK4E,EAAQ,MAAM,OAAO,OAAO,UAAU;CAGlE,OAFAY,EAAWlG,EAAoBqG,GAAWpG,EAAYoG,CAAS,CAAC,CAAC,GAE1D;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-B_md4EZa.js","names":["getLogger","createCollectionIdempotent","readMigration","migrationDelay","getMigrationFile","modifyOutcomeToFile","modifyUtils","dedent","SvelteFile","withInMemoryScript","ensureNamedImport","formatLikeSource","ensureImports","NOTIFICATION_RULE_PATCHES","fs","path","BELL_SNIPPET","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyAppLayout","layoutPath","file","out","source","sf","AUTH_MODULE","USER_STATEMENT","FETCH_STATEMENT","NOTIFICATIONS_STATEMENT","DEPENDS_STATEMENT","modifyLayoutServer","layoutServerPath","snippet","originalSource","sourceFile","Project","addProperty","obj","name","initializer","loadArrow","loadFn","varDecl","SyntaxKind","directArrow","init","innerArrow","innerFnExpr","maybeFn","fnLike","params","first","original","nameNode","obp","elementNames","el","hasDepends","hasLocals","existingParts","parts","currentName","body","blockBody","statements","declaresVar","stmt","d","hasDependsCall","ce","args","argText","hasNotificationsList","hasNotifications","current","returnIdx","s","insertAt","augmentReturnObject","augmentReturns","expr","ret","inner","arrowBody","bodyExpr","fnBody","pushMigrationCreates","created","migrationFile","collectionName","options","creates","generate","logger","withPocketbase","userCollection","pb","create","spec","result","ruleMigrations","applyCollectionRulePatches","modifies","pushResult","appLayoutPath","appLayoutServerPath","utilsPath"],"sources":["../../src/patterns/enable/notifications/modifies/modify-app-layout.ts","../../src/patterns/enable/notifications/modifies/+layout.server.ts","../../src/patterns/enable/notifications/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst BELL_SNIPPET = `\n\t\t<div class=\"ml-auto px-4\">\n\t\t\t<NotificationsBell />\n\t\t</div>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import NotificationsBell from '#lib/components/notifications-bell.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the notifications bell inside the (app) layout's <header>.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <header>:\",\n BELL_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.svelte with a <header> that includes the bell.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <header>:\",\n BELL_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyAppLayout(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"header\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"NotificationsBell\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"NotificationsBell\",\n moduleSpecifier: \"#lib/components/notifications-bell.svelte\",\n },\n ]);\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"header\", BELL_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst AUTH_MODULE = \"@velastack/pocketbase/auth\";\n\n/** For a load that has no `user` yet: the stock (app) layout declares one. */\nconst USER_STATEMENT = \"const user = requireUser();\";\n\nconst FETCH_STATEMENT = dedent`\n const notificationsList = await locals.pb\n .collection(\"notifications\")\n .getList(1, 5, {\n filter: locals.pb.filter(\"user = {:user} && read = false\", {\n user: user.id,\n }),\n sort: \"-created\",\n });\n`;\n\nconst NOTIFICATIONS_STATEMENT =\n \"const notifications = { count: notificationsList.totalItems, items: notificationsList.items };\";\n\nconst DEPENDS_STATEMENT = 'depends(\"app:notifications\");';\n\nexport function modifyLayoutServer(layoutServerPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n const snippet = dedent`\n import { requireUser } from \"${AUTH_MODULE}\";\n\n export const load = async ({ locals, depends }) => {\n ${USER_STATEMENT}\n ${FETCH_STATEMENT}\n ${NOTIFICATIONS_STATEMENT}\n ${DEPENDS_STATEMENT}\n return { notifications };\n };\n `;\n fs.writeFileSync(layoutServerPath, snippet);\n return { status: \"success\", changed: true };\n }\n\n const originalSource = fs.readFileSync(layoutServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutServerPath);\n\n const addProperty = (\n obj: import(\"ts-morph\").ObjectLiteralExpression,\n name: string,\n initializer: string,\n ) => {\n if (obj.getProperty(name)) return;\n if (name === initializer) {\n obj.addShorthandPropertyAssignment({ name });\n } else {\n obj.addPropertyAssignment({ name, initializer });\n }\n };\n\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n if (vs?.hasExportKeyword()) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n\n if (!loadArrow && !loadFn) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) loadFn = maybeFn;\n }\n\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals, depends }\" }],\n statements: [\n USER_STATEMENT,\n FETCH_STATEMENT,\n NOTIFICATIONS_STATEMENT,\n DEPENDS_STATEMENT,\n \"return { notifications };\",\n ],\n });\n ensureNamedImport(sourceFile, AUTH_MODULE, \"requireUser\");\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const fnLike = (loadArrow ?? loadFn!) as\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression;\n\n // Ensure first param destructures { locals, depends }\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals, depends }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const elementNames = obp.getElements().map((el) => el.getName());\n const hasDepends = elementNames.includes(\"depends\");\n const hasLocals = elementNames.includes(\"locals\");\n\n if (!hasDepends || !hasLocals) {\n const existingParts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const parts: string[] = hasLocals ? [] : [\"locals\"];\n parts.push(...existingParts);\n if (!hasDepends) parts.push(\"depends\");\n first.set({\n name: `{ ${parts.join(\", \")} }`,\n type: original.type,\n initializer: (original as { initializer?: string }).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, depends, ...${currentName} }`,\n type: original.type,\n initializer: (original as { initializer?: string }).initializer,\n });\n } else {\n first.set({\n name: `{ locals, depends }`,\n type: original.type,\n initializer: (original as { initializer?: string }).initializer,\n });\n }\n }\n }\n\n if (loadArrow && !loadArrow.isAsync()) loadArrow.setIsAsync(true);\n else if (loadFn && !loadFn.isAsync()) loadFn.setIsAsync(true);\n\n const body = fnLike.getBody();\n if (body && body.getKind() === SyntaxKind.Block) {\n const blockBody = body as import(\"ts-morph\").Block;\n const statements = blockBody.getStatements();\n\n const declaresVar = (name: string) =>\n statements.some((stmt) => {\n if (stmt.getKind() !== SyntaxKind.VariableStatement) return false;\n return (stmt as import(\"ts-morph\").VariableStatement)\n .getDeclarations()\n .some((d) => d.getName() === name);\n });\n\n const hasDependsCall = statements.some(\n (stmt) =>\n stmt.getKind() === SyntaxKind.ExpressionStatement &&\n stmt.getDescendantsOfKind(SyntaxKind.CallExpression).some((ce) => {\n if (ce.getExpression().getText() !== \"depends\") return false;\n const args = ce.getArguments();\n const argText = args[0]?.getText() ?? \"\";\n return (\n args.length === 1 &&\n (argText === \"'app:notifications'\" ||\n argText === '\"app:notifications\"')\n );\n }),\n );\n\n const hasNotificationsList = declaresVar(\"notificationsList\");\n const hasNotifications = declaresVar(\"notifications\");\n\n // The query filters on `user.id`. A load written by enable-auth has the\n // user already, by either name for it (`requireUser()` now,\n // `locals.pb.authStore.record!` before); any other gets it first.\n if (!hasNotificationsList && !declaresVar(\"user\")) {\n blockBody.insertStatements(0, USER_STATEMENT);\n ensureNamedImport(sourceFile, AUTH_MODULE, \"requireUser\");\n }\n\n const current = blockBody.getStatements();\n const returnIdx = current.findIndex(\n (s) => s.getKind() === SyntaxKind.ReturnStatement,\n );\n let insertAt = returnIdx >= 0 ? returnIdx : current.length;\n\n if (!hasNotificationsList) {\n blockBody.insertStatements(insertAt, FETCH_STATEMENT);\n insertAt++;\n }\n if (!hasNotifications) {\n blockBody.insertStatements(insertAt, NOTIFICATIONS_STATEMENT);\n insertAt++;\n }\n if (!hasDependsCall) {\n blockBody.insertStatements(insertAt, DEPENDS_STATEMENT);\n }\n }\n\n const augmentReturnObject = (\n obj: import(\"ts-morph\").ObjectLiteralExpression,\n ) => {\n addProperty(obj, \"notifications\", \"notifications\");\n };\n\n const augmentReturns = (target: import(\"ts-morph\").Node) => {\n const returns = target.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(\n inner as import(\"ts-morph\").ObjectLiteralExpression,\n );\n }\n }\n });\n };\n\n if (loadArrow) {\n const arrowBody = loadArrow.getBody();\n if (arrowBody.getKind() === SyntaxKind.Block) {\n augmentReturns(arrowBody);\n } else {\n const bodyExpr = arrowBody as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(\n inner as import(\"ts-morph\").ObjectLiteralExpression,\n );\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n augmentReturnObject(\n bodyExpr as import(\"ts-morph\").ObjectLiteralExpression,\n );\n }\n }\n } else if (loadFn) {\n const fnBody = loadFn.getBody();\n if (fnBody) augmentReturns(fnBody);\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n applyCollectionRulePatches,\n createCollectionIdempotent,\n readMigration,\n} from \"../../../runtime/collections\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyUtils } from \"../../../runtime/modify-utils\";\nimport { modifyAppLayout } from \"./modifies/modify-app-layout\";\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { NOTIFICATION_RULE_PATCHES } from \"./runtime/pocketbase\";\n\nasync function pushMigrationCreates(\n creates: File[],\n collectionName: string,\n options: Options,\n created = true,\n) {\n if (!created) return;\n await migrationDelay();\n const migrationFile = getMigrationFile(collectionName, \"created\", options);\n if (!migrationFile) return;\n creates.push(await readMigration(migrationFile, options));\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n const userCollection = await pb.collections.getOne(\"users\");\n const create = (spec: Parameters<typeof createCollectionIdempotent>[1]) =>\n createCollectionIdempotent(pb, spec, logger);\n\n logger.info(\"Creating notifications collection\");\n const result = await create({\n name: \"notifications\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n type: \"text\",\n primaryKey: true,\n autogeneratePattern: \"[a-z0-9]{15}\",\n max: 15,\n min: 15,\n pattern: \"^[a-z0-9]+$\",\n required: true,\n },\n {\n name: \"user\",\n type: \"relation\",\n cascadeDelete: true,\n collectionId: userCollection.id,\n maxSelect: 1,\n minSelect: 0,\n required: true,\n },\n {\n name: \"title\",\n type: \"text\",\n required: true,\n },\n {\n name: \"body\",\n type: \"text\",\n },\n {\n name: \"read\",\n type: \"bool\",\n },\n {\n name: \"created\",\n type: \"autodate\",\n onCreate: true,\n onUpdate: false,\n },\n {\n name: \"updated\",\n type: \"autodate\",\n onCreate: true,\n onUpdate: true,\n },\n ],\n indexes: [\n \"CREATE INDEX `idx_notifications_user_read_created` ON `notifications` (`user`, `read`, `created` DESC)\",\n ],\n });\n await pushMigrationCreates(\n creates,\n \"notifications\",\n options,\n result.created,\n );\n\n logger.info(\"Applying notifications rule patches\");\n const ruleMigrations = await applyCollectionRulePatches(\n pb,\n NOTIFICATION_RULE_PATCHES,\n options,\n logger,\n );\n creates.push(...ruleMigrations);\n });\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying (app) +layout.svelte\");\n const appLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appLayoutPath, modifyAppLayout(appLayoutPath)),\n );\n\n logger.info(\"Modifying (app) +layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n modifyLayoutServer(appLayoutServerPath),\n ),\n );\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":";;;;;;;;;;;;;AASA,IAAMgB,IAAe,2EAMfC,IAAiB,CAAM;;GAIvBC,IAAe;CACnB;CACA;CACA;CACA;CACAD;CACA;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI,GAELG,IAAiB;CACrB;CACA;CACA;CACA;CACAF;CACA;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgBI,EAAgB,GAAmC;CACjE,IAAI,CAACN,EAAG,WAAWO,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAGxD,IAAMG,IAAOd,EAAW,SAASa,CAAU;CAsB3C,OArBKC,EAAK,WAAW,QAAQ,IAGzBA,EAAK,WAAW,mBAAmB,IAC9B;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7CA,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQC,MAAQd,EAAmBe,IAAS,MAAO;GACzD,EAAcC,GAAI,CAChB;IACE,eAAe;IACf,iBAAiB;GACnB,CACF,CAAC;EACH,CAAC;EACD,OAAOF;CACT,CAAC,GAEDD,EAAK,uBAAuB,UAAUN,CAAY,GAClDM,EAAK,QAAQD,CAAU,GAChB;EAAE,QAAQ;EAAW,SAASC,EAAK,WAAW;CAAE,KApB9C;EAAE,QAA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4E,EAAQ,MACR,OACA,UACA,SACA,gBACF;CAKA,AAJAa,EACEnG,EAAoBoG,GAAerF,EAAgBqF,CAAa,CAAC,CACnE,GAEAX,EAAO,KAAK,mCAAmC;CAC/C,IAAMY,IAAsB3F,EAAK,KAC/B4E,EAAQ,MACR,OACA,UACA,SACA,mBACF;CAQA,AAPAa,EACEnG,EACEqG,GACA3E,EAAmB2E,CAAmB,CACxC,CACF,GAEAZ,EAAO,KAAK,oBAAoB;CAChC,IAAMa,IAAY5F,EAAK,KAAK4E,EAAQ,MAAM,OAAO,OAAO,UAAU;CAGlE,OAFAa,EAAWnG,EAAoBsG,GAAWrG,EAAYqG,CAAS,CAAC,CAAC,GAE1D;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as e } from "./logger-t1HxmpG2.js";
|
|
2
|
-
import { r as t } from "./modify-file-
|
|
3
|
-
import { t as n } from "./shared-
|
|
2
|
+
import { r as t } from "./modify-file-DRdmZIvW.js";
|
|
3
|
+
import { t as n } from "./shared-D7-ZAoqr.js";
|
|
4
4
|
import { _ as r, h as i, n as a, o, u as s } from "./ts-morph-helpers-B4KZXP44.js";
|
|
5
5
|
import { t as c } from "./svelte-file-DfplF3BU.js";
|
|
6
6
|
import { t as l } from "./unmodify-load-DWixBz7y.js";
|
|
@@ -206,4 +206,4 @@ async function k(r) {
|
|
|
206
206
|
}
|
|
207
207
|
export { k as generate };
|
|
208
208
|
|
|
209
|
-
//# sourceMappingURL=generate.runtime-
|
|
209
|
+
//# sourceMappingURL=generate.runtime-BpXoagaq.js.map
|