@velastack/patterns 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +32 -2
  2. package/dist/chunks/_layout-B7ujvjnA.js +55 -0
  3. package/dist/chunks/_layout-B7ujvjnA.js.map +1 -0
  4. package/dist/chunks/{collections-CgdvZXmh.js → collections-UPqYto13.js} +2 -2
  5. package/dist/chunks/{collections-CgdvZXmh.js.map → collections-UPqYto13.js.map} +1 -1
  6. package/dist/chunks/{compose-handle-Cg9jnCsS.js → compose-handle-B-CkDcQD.js} +23 -23
  7. package/dist/chunks/{compose-handle-Cg9jnCsS.js.map → compose-handle-B-CkDcQD.js.map} +1 -1
  8. package/dist/chunks/config-target-Bln26FJe.js +164 -0
  9. package/dist/chunks/config-target-Bln26FJe.js.map +1 -0
  10. package/dist/chunks/errors-DR3gF_7a.js +18 -0
  11. package/dist/chunks/errors-DR3gF_7a.js.map +1 -0
  12. package/dist/chunks/{generate-DRA63W0r.js → generate-6snrlnpA.js} +2 -2
  13. package/dist/chunks/{generate-DRA63W0r.js.map → generate-6snrlnpA.js.map} +1 -1
  14. package/dist/chunks/{generate-BkQ1xMDp.js → generate-C6xi5S5L.js} +4 -4
  15. package/dist/chunks/{generate-BkQ1xMDp.js.map → generate-C6xi5S5L.js.map} +1 -1
  16. package/dist/chunks/{generate-tOkjJFUf.js → generate-CyuY2Ci7.js} +4 -3
  17. package/dist/chunks/generate-CyuY2Ci7.js.map +1 -0
  18. package/dist/chunks/{generate-iQP31-m1.js → generate-DHgKgHb7.js} +4 -4
  19. package/dist/chunks/{generate-iQP31-m1.js.map → generate-DHgKgHb7.js.map} +1 -1
  20. package/dist/chunks/{generate-_LvrYK6i.js → generate-jsB_oO0b.js} +4 -4
  21. package/dist/chunks/{generate-_LvrYK6i.js.map → generate-jsB_oO0b.js.map} +1 -1
  22. package/dist/chunks/{generate.runtime-DAmYsIvF.js → generate.runtime-9R2AUKLS.js} +5 -5
  23. package/dist/chunks/{generate.runtime-DAmYsIvF.js.map → generate.runtime-9R2AUKLS.js.map} +1 -1
  24. package/dist/chunks/generate.runtime-B3yX6kl2.js +87 -0
  25. package/dist/chunks/generate.runtime-B3yX6kl2.js.map +1 -0
  26. package/dist/chunks/{generate.runtime-BKo-Nidn.js → generate.runtime-B7wkyj-8.js} +6 -6
  27. package/dist/chunks/{generate.runtime-BKo-Nidn.js.map → generate.runtime-B7wkyj-8.js.map} +1 -1
  28. package/dist/chunks/generate.runtime-BHf8p_3K.js +94 -0
  29. package/dist/chunks/generate.runtime-BHf8p_3K.js.map +1 -0
  30. package/dist/chunks/{generate.runtime-BbIN0tUZ.js → generate.runtime-BSFIwX58.js} +67 -66
  31. package/dist/chunks/generate.runtime-BSFIwX58.js.map +1 -0
  32. package/dist/chunks/{generate.runtime-BnWE4qsu.js → generate.runtime-Bb9CCwQm.js} +55 -54
  33. package/dist/chunks/generate.runtime-Bb9CCwQm.js.map +1 -0
  34. package/dist/chunks/{generate.runtime-D8vgh5MH.js → generate.runtime-BjciAjq7.js} +156 -76
  35. package/dist/chunks/generate.runtime-BjciAjq7.js.map +1 -0
  36. package/dist/chunks/{generate.runtime-BwhGDnGu.js → generate.runtime-BpTpRBdH.js} +151 -150
  37. package/dist/chunks/generate.runtime-BpTpRBdH.js.map +1 -0
  38. package/dist/chunks/{generate.runtime-D0icLb5j.js → generate.runtime-Brf08fMW.js} +11 -10
  39. package/dist/chunks/{generate.runtime-D0icLb5j.js.map → generate.runtime-Brf08fMW.js.map} +1 -1
  40. package/dist/chunks/{generate.runtime-S5RIgbQx.js → generate.runtime-C6DfW_NO.js} +98 -92
  41. package/dist/chunks/generate.runtime-C6DfW_NO.js.map +1 -0
  42. package/dist/chunks/{generate.runtime-DhkaXTq3.js → generate.runtime-C9fSqy6a.js} +61 -59
  43. package/dist/chunks/generate.runtime-C9fSqy6a.js.map +1 -0
  44. package/dist/chunks/{generate.runtime-CRYjWJRe.js → generate.runtime-CawvLUoV.js} +89 -88
  45. package/dist/chunks/generate.runtime-CawvLUoV.js.map +1 -0
  46. package/dist/chunks/{generate.runtime-DNaQxed-.js → generate.runtime-CzS7PuPN.js} +84 -83
  47. package/dist/chunks/generate.runtime-CzS7PuPN.js.map +1 -0
  48. package/dist/chunks/{generate.runtime-B0hhtyAL.js → generate.runtime-D1NZPV6C.js} +27 -26
  49. package/dist/chunks/generate.runtime-D1NZPV6C.js.map +1 -0
  50. package/dist/chunks/generate.runtime-D3baqo6a.js +111 -0
  51. package/dist/chunks/generate.runtime-D3baqo6a.js.map +1 -0
  52. package/dist/chunks/{generate.runtime-DSqkXvps.js → generate.runtime-D47djbeG.js} +15 -14
  53. package/dist/chunks/{generate.runtime-DSqkXvps.js.map → generate.runtime-D47djbeG.js.map} +1 -1
  54. package/dist/chunks/generate.runtime-D72UBiwD.js +313 -0
  55. package/dist/chunks/generate.runtime-D72UBiwD.js.map +1 -0
  56. package/dist/chunks/{generate.runtime-CcuAXuV2.js → generate.runtime-DDPoXmqN.js} +15 -14
  57. package/dist/chunks/{generate.runtime-CcuAXuV2.js.map → generate.runtime-DDPoXmqN.js.map} +1 -1
  58. package/dist/chunks/{generate.runtime-acRmiU7e.js → generate.runtime-DEnn0HKw.js} +9 -8
  59. package/dist/chunks/{generate.runtime-acRmiU7e.js.map → generate.runtime-DEnn0HKw.js.map} +1 -1
  60. package/dist/chunks/{generate.runtime-wA1G3tQ4.js → generate.runtime-DHXkw2gf.js} +38 -37
  61. package/dist/chunks/generate.runtime-DHXkw2gf.js.map +1 -0
  62. package/dist/chunks/{generate.runtime-DOuufRLr.js → generate.runtime-DIuCrH6l.js} +82 -81
  63. package/dist/chunks/generate.runtime-DIuCrH6l.js.map +1 -0
  64. package/dist/chunks/generate.runtime-DOB4U-Sa.js +57 -0
  65. package/dist/chunks/generate.runtime-DOB4U-Sa.js.map +1 -0
  66. package/dist/chunks/generate.runtime-DPAy7Cav.js +328 -0
  67. package/dist/chunks/generate.runtime-DPAy7Cav.js.map +1 -0
  68. package/dist/chunks/{generate.runtime-BORbegw_.js → generate.runtime-D_ZqiYt-.js} +123 -122
  69. package/dist/chunks/generate.runtime-D_ZqiYt-.js.map +1 -0
  70. package/dist/chunks/{generate.runtime-B49wetSx.js → generate.runtime-Dm7g_WTN.js} +43 -42
  71. package/dist/chunks/generate.runtime-Dm7g_WTN.js.map +1 -0
  72. package/dist/chunks/{generate.runtime-DoZdSh9W.js → generate.runtime-HE9rzfXz.js} +58 -57
  73. package/dist/chunks/generate.runtime-HE9rzfXz.js.map +1 -0
  74. package/dist/chunks/{generate.runtime-flFRYzpi.js → generate.runtime-ejrt1o6M.js} +62 -61
  75. package/dist/chunks/generate.runtime-ejrt1o6M.js.map +1 -0
  76. package/dist/chunks/generate.runtime-l6I-St2R.js +94 -0
  77. package/dist/chunks/generate.runtime-l6I-St2R.js.map +1 -0
  78. package/dist/chunks/modify-file-DGe7MJu_.js +46 -0
  79. package/dist/chunks/modify-file-DGe7MJu_.js.map +1 -0
  80. package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js → modify-svelte-config-remote-BUU_EaDf.js} +2 -2
  81. package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js.map → modify-svelte-config-remote-BUU_EaDf.js.map} +1 -1
  82. package/dist/chunks/{providers-DO9kMyzB.js → providers-BL9vJP_9.js} +2 -2
  83. package/dist/chunks/{providers-DO9kMyzB.js.map → providers-BL9vJP_9.js.map} +1 -1
  84. package/dist/chunks/{shared-BwHQM-a9.js → shared-DkGfltvn.js} +2 -2
  85. package/dist/chunks/{shared-BwHQM-a9.js.map → shared-DkGfltvn.js.map} +1 -1
  86. package/dist/chunks/{test-setup-B2hd8I-s.js → test-setup-DHEFKEHE.js} +23 -10
  87. package/dist/chunks/test-setup-DHEFKEHE.js.map +1 -0
  88. package/dist/chunks/ts-morph-helpers-CeduA--o.js +253 -0
  89. package/dist/chunks/ts-morph-helpers-CeduA--o.js.map +1 -0
  90. package/dist/chunks/{ui-B4Tuit-7.js → ui-B3-B3sE2.js} +3 -3
  91. package/dist/chunks/{ui-B4Tuit-7.js.map → ui-B3-B3sE2.js.map} +1 -1
  92. package/dist/chunks/{ui-jhXrsw4T.js → ui-DD4NltyN.js} +2 -2
  93. package/dist/chunks/{ui-jhXrsw4T.js.map → ui-DD4NltyN.js.map} +1 -1
  94. package/dist/chunks/unmodify-load-jfdcVZ_a.js +81 -0
  95. package/dist/chunks/unmodify-load-jfdcVZ_a.js.map +1 -0
  96. package/dist/chunks/write-result-DRwceOV3.js +452 -0
  97. package/dist/chunks/write-result-DRwceOV3.js.map +1 -0
  98. package/dist/index.d.ts +34 -0
  99. package/dist/index.js +1918 -1901
  100. package/dist/index.js.map +1 -1
  101. package/package.json +1 -1
  102. package/dist/chunks/_layout-DqH4lA_r.js +0 -47
  103. package/dist/chunks/_layout-DqH4lA_r.js.map +0 -1
  104. package/dist/chunks/config-target-Co-ij8p3.js +0 -163
  105. package/dist/chunks/config-target-Co-ij8p3.js.map +0 -1
  106. package/dist/chunks/errors-D6gyegUK.js +0 -14
  107. package/dist/chunks/errors-D6gyegUK.js.map +0 -1
  108. package/dist/chunks/generate-tOkjJFUf.js.map +0 -1
  109. package/dist/chunks/generate.runtime-B0hhtyAL.js.map +0 -1
  110. package/dist/chunks/generate.runtime-B49wetSx.js.map +0 -1
  111. package/dist/chunks/generate.runtime-B7LRx-BU.js +0 -86
  112. package/dist/chunks/generate.runtime-B7LRx-BU.js.map +0 -1
  113. package/dist/chunks/generate.runtime-BORbegw_.js.map +0 -1
  114. package/dist/chunks/generate.runtime-BbIN0tUZ.js.map +0 -1
  115. package/dist/chunks/generate.runtime-BnWE4qsu.js.map +0 -1
  116. package/dist/chunks/generate.runtime-BwhGDnGu.js.map +0 -1
  117. package/dist/chunks/generate.runtime-CCg2Pjcv.js +0 -257
  118. package/dist/chunks/generate.runtime-CCg2Pjcv.js.map +0 -1
  119. package/dist/chunks/generate.runtime-CRYjWJRe.js.map +0 -1
  120. package/dist/chunks/generate.runtime-D2e_KRj0.js +0 -56
  121. package/dist/chunks/generate.runtime-D2e_KRj0.js.map +0 -1
  122. package/dist/chunks/generate.runtime-D44gjxRA.js +0 -332
  123. package/dist/chunks/generate.runtime-D44gjxRA.js.map +0 -1
  124. package/dist/chunks/generate.runtime-D8vgh5MH.js.map +0 -1
  125. package/dist/chunks/generate.runtime-DNaQxed-.js.map +0 -1
  126. package/dist/chunks/generate.runtime-DOuufRLr.js.map +0 -1
  127. package/dist/chunks/generate.runtime-DhkaXTq3.js.map +0 -1
  128. package/dist/chunks/generate.runtime-DoZdSh9W.js.map +0 -1
  129. package/dist/chunks/generate.runtime-S5RIgbQx.js.map +0 -1
  130. package/dist/chunks/generate.runtime-WmSMWL15.js +0 -82
  131. package/dist/chunks/generate.runtime-WmSMWL15.js.map +0 -1
  132. package/dist/chunks/generate.runtime-flFRYzpi.js.map +0 -1
  133. package/dist/chunks/generate.runtime-gtpOuLNO.js +0 -110
  134. package/dist/chunks/generate.runtime-gtpOuLNO.js.map +0 -1
  135. package/dist/chunks/generate.runtime-kLxeDGnS.js +0 -93
  136. package/dist/chunks/generate.runtime-kLxeDGnS.js.map +0 -1
  137. package/dist/chunks/generate.runtime-wA1G3tQ4.js.map +0 -1
  138. package/dist/chunks/modify-file-GQD6uNgI.js +0 -254
  139. package/dist/chunks/modify-file-GQD6uNgI.js.map +0 -1
  140. package/dist/chunks/test-setup-B2hd8I-s.js.map +0 -1
  141. package/dist/chunks/unmodify-load-W1ePZQHr.js +0 -80
  142. package/dist/chunks/unmodify-load-W1ePZQHr.js.map +0 -1
  143. package/dist/chunks/write-result-DewHCNhM.js +0 -451
  144. package/dist/chunks/write-result-DewHCNhM.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-BjciAjq7.js","names":[],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/svelte-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 { SyntaxKind, type PropertyAssignment } from \"ts-morph\";\nimport {\n getOrCreateObjectLiteralProperty,\n modifyConfig,\n type ConfigModifyResult,\n} from \"../../../../runtime/config-target\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your config (sveltekit() arg in vite.config, or svelte.config):\",\n \"\",\n \"alias: {\",\n \" $locales: 'src/locales',\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Add the $locales alias by passing config to the sveltekit() plugin in vite.config.ts:\",\n \"\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { defineConfig } from 'vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [sveltekit({ alias: { $locales: 'src/locales' } })],\",\n \"});\",\n].join(\"\\n\");\n\n/** Ensure the `$locales` alias points at `src/locales`. */\nexport function modifySvelteConfig(root: string): ConfigModifyResult {\n return modifyConfig(\n root,\n { notFound: NOT_FOUND_HINT, failed: FAILURE_HINT },\n (target) => {\n const kit = target.kitContainer();\n if (!kit) return false;\n const aliasObj = getOrCreateObjectLiteralProperty(kit, \"alias\", \"{}\");\n if (!aliasObj) return false;\n\n const existing = aliasObj.getProperty(\"$locales\");\n if (!existing) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n return true;\n }\n if (existing.getKind() !== SyntaxKind.PropertyAssignment) return false;\n\n const init = (existing as PropertyAssignment).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current !== \"src/locales\") {\n (existing as PropertyAssignment).setInitializer(\"'src/locales'\");\n }\n return true;\n },\n );\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\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\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 = dedent`\n import type { Handle } from '@sveltejs/kit';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n\n const handleWuchale: Handle = async ({ event, resolve }) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }) => html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n\n export const handle = handleWuchale;\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, \"$locales/main.url\", \"getLocale\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"locales\");\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 const startupSnippet = dedent`\n loadLocales(main.key, main.loadCount, main.loadCatalog, locales);\n loadLocales(js.key, js.loadCount, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${I18N_HANDLE} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\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 `${startupSnippet}\\n\\n${i18nHandleSnippet}\\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';\n import { locales } from '$locales/data';\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';\n import { locales } from '$locales/data';\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\", \"matchUrl\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"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 { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyHooksI18n } from \"./modifies/hooks\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\nimport { welcomePageCatalog } from \"./welcome-catalog\";\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(\"Modifying config for i18n alias\");\n const alias = modifySvelteConfig(options.root);\n pushResult(modifyOutcomeToFile(alias.filePath, alias.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(\"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 logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n const catalog = welcomePageCatalog(options.root, ui);\n if (catalog) logger.info(\"Translating the welcome page into Spanish\");\n\n return {\n creates: catalog ? [catalog] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgB,EAAiB,GAAuC;CACtE,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAOxD,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAc,GAEzD,IAAU,IACV,IAAS;CAMb,AAJkB,EACf,sBAAsB,CAAC,CACvB,MAAM,MAAM,EAAE,wBAAwB,MAAM,cAE1C,MACH,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,SAAS;EACxB,iBAAiB;CACnB,CAAC,GACD,IAAU;CAOZ,IAAM,IAJmB,EACtB,qBAAqB,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAO,EAAG,cAAc,CAAC,CAAC,QAAQ,MAA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;AACF"}
@@ -1,14 +1,15 @@
1
1
  import { t as e } from "./dedent-Gq6Krl4n.js";
2
2
  import { n as t } from "./logger-CQONztPm.js";
3
- import { n } from "./generate-tOkjJFUf.js";
4
- import { h as r, modifyOutcomeToFile as i, r as a } from "./modify-file-GQD6uNgI.js";
5
- import { t as o } from "./svelte-file-B3RfgVdt.js";
6
- import { a as s, t as c } from "./config-target-Co-ij8p3.js";
7
- import l from "node:fs";
8
- import u from "node:path";
9
- import { Node as d, Project as f, QuoteKind as p, SyntaxKind as m } from "ts-morph";
3
+ import { n } from "./generate-CyuY2Ci7.js";
4
+ import { _ as r, o as i, r as a } from "./ts-morph-helpers-CeduA--o.js";
5
+ import { modifyOutcomeToFile as o } from "./modify-file-DGe7MJu_.js";
6
+ import { t as s } from "./svelte-file-B3RfgVdt.js";
7
+ import { a as c, t as l } from "./config-target-Bln26FJe.js";
8
+ import u from "node:fs";
9
+ import d from "node:path";
10
+ import { Node as f, Project as p, QuoteKind as m, SyntaxKind as h } from "ts-morph";
10
11
  //#region src/patterns/enable/cms/modifies/vite-config.ts
11
- var h = [
12
+ var g = [
12
13
  "Add the CMS plugin to your Vite config, ahead of sveltekit():",
13
14
  "",
14
15
  "import { cms } from '@velastack/cms/vite';",
@@ -16,7 +17,7 @@ var h = [
16
17
  "export default defineConfig({",
17
18
  " plugins: [cms(), sveltekit(), /* ...existing plugins */],",
18
19
  "});"
19
- ].join("\n"), g = [
20
+ ].join("\n"), _ = [
20
21
  "Create a Vite config with the CMS plugin ahead of sveltekit():",
21
22
  "",
22
23
  "import { defineConfig } from 'vite';",
@@ -27,62 +28,62 @@ var h = [
27
28
  " plugins: [cms(), sveltekit()],",
28
29
  "});"
29
30
  ].join("\n");
30
- function _(e) {
31
+ function v(e) {
31
32
  return e.replace(/\s/g, "");
32
33
  }
33
- function v(e, t = "") {
34
+ function y(e, t = "") {
34
35
  let n = `cms(${t})`;
35
- if (!l.existsSync(e)) return {
36
+ if (!u.existsSync(e)) return {
36
37
  status: "not-found",
37
- message: g
38
+ message: _
38
39
  };
39
- let r = new f({
40
+ let r = new p({
40
41
  compilerOptions: { allowJs: !0 },
41
- manipulationSettings: { quoteKind: p.Single }
42
- }).addSourceFileAtPath(e), i = !1, a = !1;
42
+ manipulationSettings: { quoteKind: m.Single }
43
+ }).addSourceFileAtPath(e), a = !1, o = !1;
43
44
  r.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "@velastack/cms/vite") || (r.insertImportDeclaration(0, {
44
45
  namedImports: ["cms"],
45
46
  moduleSpecifier: "@velastack/cms/vite"
46
- }), i = !0);
47
- let o = r.getDescendantsOfKind(m.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], s = o?.getKind() === m.ObjectLiteralExpression ? o : null;
48
- if (!s) a = !0;
47
+ }), a = !0);
48
+ let s = r.getDescendantsOfKind(h.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], c = s?.getKind() === h.ObjectLiteralExpression ? s : null;
49
+ if (!c) o = !0;
49
50
  else {
50
- let e = s.getProperty("plugins");
51
- if (!e) s.addPropertyAssignment({
51
+ let e = c.getProperty("plugins");
52
+ if (!e) c.addPropertyAssignment({
52
53
  name: "plugins",
53
54
  initializer: `[${n}]`
54
- }), i = !0;
55
- else if (e.getKind() !== m.PropertyAssignment) a = !0;
55
+ }), a = !0;
56
+ else if (e.getKind() !== h.PropertyAssignment) o = !0;
56
57
  else {
57
58
  let t = e.getInitializer();
58
- if (!t) e.setInitializer(`[${n}]`), i = !0;
59
- else if (t.getKind() !== m.ArrayLiteralExpression) a = !0;
59
+ if (!t) e.setInitializer(`[${n}]`), a = !0;
60
+ else if (t.getKind() !== h.ArrayLiteralExpression) o = !0;
60
61
  else {
61
62
  let e = t, r = e.getElements();
62
- if (!r.some((e) => _(e.getText()).startsWith("cms("))) {
63
- let t = r.findIndex((e) => _(e.getText()).startsWith("sveltekit("));
64
- e.insertElement(t === -1 ? 0 : t, n), i = !0;
63
+ if (!r.some((e) => v(e.getText()).startsWith("cms("))) {
64
+ let t = r.findIndex((e) => v(e.getText()).startsWith("sveltekit("));
65
+ e.insertElement(t === -1 ? 0 : t, n), a = !0;
65
66
  }
66
67
  }
67
68
  }
68
69
  }
69
- return i && (r.formatText(), r.saveSync()), a ? {
70
+ return a && (i(r), r.saveSync()), o ? {
70
71
  status: "failed",
71
- message: h
72
+ message: g
72
73
  } : {
73
74
  status: "success",
74
- changed: i
75
+ changed: a
75
76
  };
76
77
  }
77
78
  //#endregion
78
79
  //#region src/patterns/enable/cms/modifies/load-function.ts
79
- function y() {
80
- return new f({
80
+ function b() {
81
+ return new p({
81
82
  compilerOptions: { allowJs: !0 },
82
- manipulationSettings: { quoteKind: p.Single }
83
+ manipulationSettings: { quoteKind: m.Single }
83
84
  });
84
85
  }
85
- function b(e, t, n) {
86
+ function x(e, t, n) {
86
87
  let r = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t);
87
88
  if (!r) {
88
89
  e.addImportDeclaration({
@@ -93,60 +94,60 @@ function b(e, t, n) {
93
94
  }
94
95
  for (let e of n) r.getNamedImports().some((t) => t.getName() === e) || r.addNamedImport(e);
95
96
  }
96
- function x(e, t) {
97
- t.namedImports?.length && b(e, t.moduleSpecifier, t.namedImports), !e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t.moduleSpecifier) && e.addImportDeclaration({
97
+ function S(e, t) {
98
+ t.namedImports?.length && x(e, t.moduleSpecifier, t.namedImports), !e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t.moduleSpecifier) && e.addImportDeclaration({
98
99
  moduleSpecifier: t.moduleSpecifier,
99
100
  defaultImport: t.defaultImport,
100
101
  namespaceImport: t.namespaceImport
101
102
  });
102
103
  }
103
- function S(e) {
104
- if (d.isArrowFunction(e) || d.isFunctionExpression(e)) return e;
105
- if (d.isParenthesizedExpression(e) || d.isAsExpression(e) || d.isSatisfiesExpression(e)) return S(e.getExpression());
106
- if (d.isCallExpression(e)) for (let t of e.getArguments()) {
107
- let e = S(t);
104
+ function C(e) {
105
+ if (f.isArrowFunction(e) || f.isFunctionExpression(e)) return e;
106
+ if (f.isParenthesizedExpression(e) || f.isAsExpression(e) || f.isSatisfiesExpression(e)) return C(e.getExpression());
107
+ if (f.isCallExpression(e)) for (let t of e.getArguments()) {
108
+ let e = C(t);
108
109
  if (e) return e;
109
110
  }
110
111
  return null;
111
112
  }
112
- function C(e) {
113
+ function w(e) {
113
114
  let t = e.getFunction("load");
114
115
  if (t) return t.isExported() ? t : null;
115
116
  let n = e.getVariableDeclaration("load");
116
117
  if (!n || !n.getVariableStatement()?.isExported()) return null;
117
118
  let r = n.getInitializer();
118
- return r ? S(r) : null;
119
+ return r ? C(r) : null;
119
120
  }
120
- function w(e) {
121
- return d.isArrowFunction(e) || d.isFunctionExpression(e) || d.isFunctionDeclaration(e) || d.isMethodDeclaration(e);
121
+ function T(e) {
122
+ return f.isArrowFunction(e) || f.isFunctionExpression(e) || f.isFunctionDeclaration(e) || f.isMethodDeclaration(e);
122
123
  }
123
- function T(e, t) {
124
+ function E(e, t) {
124
125
  let n = t.getStatements(), r = n[n.length - 1];
125
- return !r || !d.isReturnStatement(r) || t.getDescendantsOfKind(m.ReturnStatement).filter((t) => t.getFirstAncestor(w) === e).length !== 1 ? null : r;
126
+ return !r || !f.isReturnStatement(r) || t.getDescendantsOfKind(h.ReturnStatement).filter((t) => t.getFirstAncestor(T) === e).length !== 1 ? null : r;
126
127
  }
127
- function E(e) {
128
+ function D(e) {
128
129
  let t = e.getExpression();
129
- for (; t && d.isParenthesizedExpression(t);) t = t.getExpression();
130
- return !t || !d.isObjectLiteralExpression(t) ? null : t;
131
- }
132
- function D(e, t) {
133
- return e.getProperties().some((e) => d.isPropertyAssignment(e) || d.isShorthandPropertyAssignment(e) ? e.getName() === t : !1);
130
+ for (; t && f.isParenthesizedExpression(t);) t = t.getExpression();
131
+ return !t || !f.isObjectLiteralExpression(t) ? null : t;
134
132
  }
135
133
  function O(e, t) {
136
- return e.getProperties().some((e) => d.isSpreadAssignment(e) && e.getExpression().getText() === t);
134
+ return e.getProperties().some((e) => f.isPropertyAssignment(e) || f.isShorthandPropertyAssignment(e) ? e.getName() === t : !1);
137
135
  }
138
- function k(e) {
136
+ function k(e, t) {
137
+ return e.getProperties().some((e) => f.isSpreadAssignment(e) && e.getExpression().getText() === t);
138
+ }
139
+ function A(e) {
139
140
  let t = e.getParameters();
140
141
  if (t.length === 0) return { kind: "none" };
141
142
  if (t.length > 1) return { kind: "unsupported" };
142
143
  let n = t[0];
143
144
  if (n.getInitializer() || n.isRestParameter()) return { kind: "unsupported" };
144
145
  let r = n.getNameNode();
145
- return d.isIdentifier(r) ? {
146
+ return f.isIdentifier(r) ? {
146
147
  kind: "identifier",
147
148
  name: r.getText(),
148
149
  param: n
149
- } : d.isObjectBindingPattern(r) ? {
150
+ } : f.isObjectBindingPattern(r) ? {
150
151
  kind: "binding",
151
152
  pattern: r,
152
153
  param: n
@@ -154,14 +155,14 @@ function k(e) {
154
155
  }
155
156
  //#endregion
156
157
  //#region src/patterns/enable/cms/modifies/layout.server.ts
157
- var A = { expression: () => "'en'" }, j = {
158
+ var j = { expression: () => "'en'" }, M = {
158
159
  expression: (e) => `getLocale(${e}.url)`,
159
160
  imports: [{
160
161
  namedImports: ["getLocale"],
161
162
  moduleSpecifier: "$locales/main.url"
162
163
  }]
163
164
  };
164
- function M(t, n) {
165
+ function N(t, n) {
165
166
  return e`
166
167
  const { cms, notFound, gone, redirectTo } = await loadCms(${t}, { locale: ${n} });
167
168
  if (redirectTo) redirect(308, redirectTo);
@@ -169,17 +170,17 @@ function M(t, n) {
169
170
  if (notFound) error(404, 'Not found');
170
171
  `;
171
172
  }
172
- function N(e) {
173
+ function P(e) {
173
174
  let t = [];
174
175
  return e.defaultImport && t.push(e.defaultImport), e.namespaceImport && t.push(`* as ${e.namespaceImport}`), e.namedImports?.length && t.push(`{ ${e.namedImports.join(", ")} }`), `import ${t.join(", ")} from '${e.moduleSpecifier}';`;
175
176
  }
176
- function P(t) {
177
+ function F(t) {
177
178
  let n = [
178
179
  "import { error, redirect } from '@sveltejs/kit';",
179
180
  "import { loadCms } from '$lib/cms';",
180
- ...(t.imports ?? []).map(N),
181
+ ...(t.imports ?? []).map(P),
181
182
  "import type { LayoutServerLoad } from './$types';"
182
- ].join("\n"), r = M("event", t.expression("event")).split("\n").join("\n ");
183
+ ].join("\n"), r = N("event", t.expression("event")).split("\n").join("\n ");
183
184
  return e`
184
185
  ${n}
185
186
 
@@ -190,65 +191,65 @@ function P(t) {
190
191
  };
191
192
  `.concat("\n");
192
193
  }
193
- var F = [
194
+ var I = [
194
195
  "Call loadCms from the root +layout.server.ts load and return `cms`:",
195
196
  "",
196
- P(A).trimEnd(),
197
+ F(j).trimEnd(),
197
198
  "",
198
199
  "loadCms needs the whole event, so a destructured parameter has to become",
199
200
  "`event` with the destructuring moved into the body."
200
201
  ].join("\n");
201
- function I(e, t = A) {
202
- if (!l.existsSync(e)) return l.mkdirSync(u.dirname(e), { recursive: !0 }), l.writeFileSync(e, P(t)), {
202
+ function L(e, t = j) {
203
+ if (!u.existsSync(e)) return u.mkdirSync(d.dirname(e), { recursive: !0 }), u.writeFileSync(e, F(t)), {
203
204
  status: "success",
204
205
  changed: !0
205
206
  };
206
- if (l.readFileSync(e, "utf8").includes("loadCms(")) return {
207
+ if (u.readFileSync(e, "utf8").includes("loadCms(")) return {
207
208
  status: "success",
208
209
  changed: !1
209
210
  };
210
- let n = y().addSourceFileAtPath(e), r = C(n);
211
+ let n = b().addSourceFileAtPath(e), r = w(n);
211
212
  if (!r) return {
212
213
  status: "failed",
213
- message: F
214
+ message: I
214
215
  };
215
- let i = r.getBody();
216
- if (!i || !d.isBlock(i)) return {
216
+ let a = r.getBody();
217
+ if (!a || !f.isBlock(a)) return {
217
218
  status: "failed",
218
- message: F
219
+ message: I
219
220
  };
220
- let a = k(r);
221
- if (a.kind === "unsupported") return {
221
+ let o = A(r);
222
+ if (o.kind === "unsupported") return {
222
223
  status: "failed",
223
- message: F
224
+ message: I
224
225
  };
225
- let o = T(r, i), s = o && E(o);
226
- if (!o || !s) return {
226
+ let s = E(r, a), c = s && D(s);
227
+ if (!s || !c) return {
227
228
  status: "failed",
228
- message: F
229
+ message: I
229
230
  };
230
- let c = a.kind === "identifier" ? a.name : "event";
231
- if (!D(s, "cms")) {
232
- let e = s.getProperties().findIndex((e) => d.isSpreadAssignment(e));
233
- e === -1 ? s.addShorthandPropertyAssignment({ name: "cms" }) : s.insertShorthandPropertyAssignment(e, { name: "cms" });
231
+ let l = o.kind === "identifier" ? o.name : "event";
232
+ if (!O(c, "cms")) {
233
+ let e = c.getProperties().findIndex((e) => f.isSpreadAssignment(e));
234
+ e === -1 ? c.addShorthandPropertyAssignment({ name: "cms" }) : c.insertShorthandPropertyAssignment(e, { name: "cms" });
234
235
  }
235
- let f = i.getStatementsWithComments().indexOf(o);
236
- if (i.insertStatements(f, `\n${M(c, t.expression(c))}\n`), a.kind === "binding") {
237
- let e = a.pattern.getText();
238
- i.insertStatements(0, `const ${e} = ${c};`);
239
- let t = a.param.getTypeNode()?.getText();
240
- a.param.replaceWithText(t ? `${c}: ${t}` : c);
241
- } else a.kind === "none" && r.addParameter({ name: c });
242
- r.isAsync() || r.setIsAsync(!0), b(n, "@sveltejs/kit", ["error", "redirect"]), b(n, "$lib/cms", ["loadCms"]);
243
- for (let e of t.imports ?? []) x(n, e);
244
- return n.formatText(), n.saveSync(), {
236
+ let p = a.getStatementsWithComments().indexOf(s);
237
+ if (a.insertStatements(p, `\n${N(l, t.expression(l))}\n`), o.kind === "binding") {
238
+ let e = o.pattern.getText();
239
+ a.insertStatements(0, `const ${e} = ${l};`);
240
+ let t = o.param.getTypeNode()?.getText();
241
+ o.param.replaceWithText(t ? `${l}: ${t}` : l);
242
+ } else o.kind === "none" && r.addParameter({ name: l });
243
+ r.isAsync() || r.setIsAsync(!0), x(n, "@sveltejs/kit", ["error", "redirect"]), x(n, "$lib/cms", ["loadCms"]);
244
+ for (let e of t.imports ?? []) S(n, e);
245
+ return i(n), n.saveSync(), {
245
246
  status: "success",
246
247
  changed: !0
247
248
  };
248
249
  }
249
250
  //#endregion
250
251
  //#region src/patterns/enable/cms/modifies/layout.ts
251
- var L = e`
252
+ var R = e`
252
253
  Forward the server load's data through the root +layout.ts, so \`cms\` reaches
253
254
  the page:
254
255
 
@@ -257,85 +258,85 @@ var L = e`
257
258
  return { ...data, /* existing keys */ };
258
259
  };
259
260
  `;
260
- function R(e) {
261
- if (!l.existsSync(e)) return {
261
+ function z(e) {
262
+ if (!u.existsSync(e)) return {
262
263
  status: "success",
263
264
  changed: !1
264
265
  };
265
- let t = y().addSourceFileAtPath(e), n = C(t);
266
+ let t = b().addSourceFileAtPath(e), n = w(t);
266
267
  if (!n) return {
267
268
  status: "success",
268
269
  changed: !1
269
270
  };
270
271
  let r = n.getBody();
271
- if (!r || !d.isBlock(r)) return {
272
+ if (!r || !f.isBlock(r)) return {
272
273
  status: "failed",
273
- message: L
274
+ message: R
274
275
  };
275
- let i = k(n);
276
- if (i.kind === "unsupported") return {
276
+ let a = A(n);
277
+ if (a.kind === "unsupported") return {
277
278
  status: "failed",
278
- message: L
279
+ message: R
279
280
  };
280
- let a = T(n, r);
281
- if (!a) return {
281
+ let o = E(n, r);
282
+ if (!o) return {
282
283
  status: "failed",
283
- message: L
284
+ message: R
284
285
  };
285
- let o = i.kind === "identifier" ? `${i.name}.data` : "data", s = a.getExpression();
286
- if (s && s.getText() === o) return {
286
+ let s = a.kind === "identifier" ? `${a.name}.data` : "data", c = o.getExpression();
287
+ if (c && c.getText() === s) return {
287
288
  status: "success",
288
289
  changed: !1
289
290
  };
290
- let c = E(a);
291
- if (!c) return {
291
+ let l = D(o);
292
+ if (!l) return {
292
293
  status: "failed",
293
- message: L
294
+ message: R
294
295
  };
295
- if (O(c, o)) return {
296
+ if (k(l, s)) return {
296
297
  status: "success",
297
298
  changed: !1
298
299
  };
299
- if (c.insertSpreadAssignment(0, { expression: o }), i.kind === "binding") {
300
- if (!i.pattern.getElements().some((e) => e.getName() === "data")) {
301
- let e = i.pattern.getText();
302
- i.pattern.replaceWithText(e.replace(/^\{\s*/, "{ data, "));
300
+ if (l.insertSpreadAssignment(0, { expression: s }), a.kind === "binding") {
301
+ if (!a.pattern.getElements().some((e) => e.getName() === "data")) {
302
+ let e = a.pattern.getText();
303
+ a.pattern.replaceWithText(e.replace(/^\{\s*/, "{ data, "));
303
304
  }
304
- } else i.kind === "none" && n.addParameter({ name: "{ data }" });
305
- return t.formatText(), t.saveSync(), {
305
+ } else a.kind === "none" && n.addParameter({ name: "{ data }" });
306
+ return i(t), t.saveSync(), {
306
307
  status: "success",
307
308
  changed: !0
308
309
  };
309
310
  }
310
311
  //#endregion
311
312
  //#region src/patterns/enable/cms/modifies/layout.svelte.ts
312
- var z = e`
313
+ var B = e`
313
314
  import { AdminBar } from '@velastack/cms';
314
- `, B = "\n<AdminBar />\n", V = [
315
+ `, V = "\n<AdminBar />\n", H = [
315
316
  "Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.",
316
317
  "",
317
318
  "Import for the <script> tag:",
318
319
  "",
319
- z,
320
+ B,
320
321
  "",
321
322
  "Markup to add at the top level of the layout, above {@render children()}:",
322
- B.trim()
323
- ].join("\n"), H = [
323
+ V.trim()
324
+ ].join("\n"), U = [
324
325
  "Mount <AdminBar /> in the root src/routes/+layout.svelte.",
325
326
  "",
326
327
  "Import for a <script lang=\"ts\"> tag:",
327
328
  "",
328
- z,
329
+ B,
329
330
  "",
330
331
  "Markup to add at the top level of the layout, above {@render children()}:",
331
- B.trim()
332
+ V.trim()
332
333
  ].join("\n");
333
- function U(e) {
334
- if (!l.existsSync(e)) return {
334
+ function W(e) {
335
+ if (!u.existsSync(e)) return {
335
336
  status: "not-found",
336
- message: V
337
+ message: H
337
338
  };
338
- let t = o.fromPath(e);
339
+ let t = s.fromPath(e);
339
340
  return t.hasElement("AdminBar") ? {
340
341
  status: "success",
341
342
  changed: !1
@@ -347,44 +348,44 @@ function U(e) {
347
348
  }]);
348
349
  });
349
350
  return t;
350
- }), t.insertBeforeChildren(B) || t.appendMarkup(B), t.writeTo(e), {
351
+ }), t.insertBeforeChildren(V) || t.appendMarkup(V), t.writeTo(e), {
351
352
  status: "success",
352
353
  changed: t.hasChanged()
353
354
  }) : {
354
355
  status: "failed",
355
- message: H
356
+ message: U
356
357
  };
357
358
  }
358
359
  //#endregion
359
360
  //#region src/patterns/enable/cms/generate.runtime.ts
360
- function W(e) {
361
- let t = u.join(e, "wuchale.config.js");
362
- if (!l.existsSync(t)) return null;
363
- let n = l.readFileSync(t, "utf8").match(/locales:\s*\[([^\]]*)\]/);
361
+ function G(e) {
362
+ let t = d.join(e, "wuchale.config.js");
363
+ if (!u.existsSync(t)) return null;
364
+ let n = u.readFileSync(t, "utf8").match(/locales:\s*\[([^\]]*)\]/);
364
365
  if (!n) return null;
365
366
  let r = [...n[1].matchAll(/['"]([^'"]+)['"]/g)].map((e) => e[1]);
366
367
  return r.length > 0 ? r : null;
367
368
  }
368
- function G(e, t) {
369
+ function K(e, t) {
369
370
  if (e.local) return "";
370
371
  let n = t.map((e) => `'${e}'`).join(", ");
371
372
  return `{ endpoint: '${e.endpoint}', locales: [${n}] }`;
372
373
  }
373
- async function K(e) {
374
- let r = t(e), a = [], o = n(e), l = e.features.i18n, d = (e) => {
375
- e && a.push(e);
374
+ async function q(e) {
375
+ let r = t(e), i = [], a = n(e), s = e.features.i18n, u = (e) => {
376
+ e && i.push(e);
376
377
  };
377
378
  r.info("Modifying vite.config");
378
- let f = s(e.root, c) ?? u.join(e.root, c[0]), p = l && W(e.root) || ["en"];
379
- d(i(f, v(f, G(o, p)))), r.info("Modifying src/routes/+layout.server.ts");
380
- let m = u.join(e.root, "src", "routes", "+layout.server.ts");
381
- d(i(m, I(m, l ? j : A))), r.info("Modifying src/routes/+layout.ts");
382
- let h = u.join(e.root, "src", "routes", "+layout.ts");
383
- d(i(h, R(h))), r.info("Modifying src/routes/+layout.svelte");
384
- let g = u.join(e.root, "src", "routes", "+layout.svelte");
385
- return d(i(g, U(g))), {
379
+ let f = c(e.root, l) ?? d.join(e.root, l[0]), p = s && G(e.root) || ["en"];
380
+ u(o(f, y(f, K(a, p)))), r.info("Modifying src/routes/+layout.server.ts");
381
+ let m = d.join(e.root, "src", "routes", "+layout.server.ts");
382
+ u(o(m, L(m, s ? M : j))), r.info("Modifying src/routes/+layout.ts");
383
+ let h = d.join(e.root, "src", "routes", "+layout.ts");
384
+ u(o(h, z(h))), r.info("Modifying src/routes/+layout.svelte");
385
+ let g = d.join(e.root, "src", "routes", "+layout.svelte");
386
+ return u(o(g, W(g))), {
386
387
  creates: [],
387
- modifies: a,
388
+ modifies: i,
388
389
  deletes: [],
389
390
  components: [],
390
391
  packages: [],
@@ -394,6 +395,6 @@ async function K(e) {
394
395
  };
395
396
  }
396
397
  //#endregion
397
- export { K as generate };
398
+ export { q as generate };
398
399
 
399
- //# sourceMappingURL=generate.runtime-BwhGDnGu.js.map
400
+ //# sourceMappingURL=generate.runtime-BpTpRBdH.js.map