@velastack/patterns 0.6.0 → 0.7.1

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 (152) hide show
  1. package/README.md +15 -3
  2. package/dist/chunks/{_layout-D-FzWqn0.js → _layout-DQhSAhfF.js} +3 -3
  3. package/dist/chunks/{_layout-D-FzWqn0.js.map → _layout-DQhSAhfF.js.map} +1 -1
  4. package/dist/chunks/{auth-pages-B52ei-4z.js → auth-pages-jsyDV1GR.js} +7 -10
  5. package/dist/chunks/{auth-pages-B52ei-4z.js.map → auth-pages-jsyDV1GR.js.map} +1 -1
  6. package/dist/chunks/{collections-B_DisSfA.js → collections-BYcVyY9O.js} +39 -35
  7. package/dist/chunks/collections-BYcVyY9O.js.map +1 -0
  8. package/dist/chunks/collections-BrEA7a62.js +309 -0
  9. package/dist/chunks/collections-BrEA7a62.js.map +1 -0
  10. package/dist/chunks/{compose-handle-BDlZ7Pif.js → compose-handle-BBlamPfx.js} +18 -22
  11. package/dist/chunks/{compose-handle-BDlZ7Pif.js.map → compose-handle-BBlamPfx.js.map} +1 -1
  12. package/dist/chunks/{config-target-rHgjaA8u.js → config-target-BgyFkbFL.js} +2 -2
  13. package/dist/chunks/{config-target-rHgjaA8u.js.map → config-target-BgyFkbFL.js.map} +1 -1
  14. package/dist/chunks/constants-Bdx8mp7v.js +6 -0
  15. package/dist/chunks/constants-Bdx8mp7v.js.map +1 -0
  16. package/dist/chunks/dedent-Gq6Krl4n.js.map +1 -1
  17. package/dist/chunks/{env-BPfk1VAw.js → env-BugddEjd.js} +5 -9
  18. package/dist/chunks/{env-BPfk1VAw.js.map → env-BugddEjd.js.map} +1 -1
  19. package/dist/chunks/{env-vars-cqQU0ECK.js → env-vars-0hvKe55u.js} +6 -11
  20. package/dist/chunks/{env-vars-cqQU0ECK.js.map → env-vars-0hvKe55u.js.map} +1 -1
  21. package/dist/chunks/generate-BOQA-Flq.js +171 -0
  22. package/dist/chunks/generate-BOQA-Flq.js.map +1 -0
  23. package/dist/chunks/{generate-CXoQPz7n.js → generate-CNabcEBx.js} +2 -2
  24. package/dist/chunks/{generate-CXoQPz7n.js.map → generate-CNabcEBx.js.map} +1 -1
  25. package/dist/chunks/{generate-jx5Iuq5w.js → generate-CO88bEvs.js} +54 -53
  26. package/dist/chunks/generate-CO88bEvs.js.map +1 -0
  27. package/dist/chunks/{generate-Bm_jOMtF.js → generate-Df7t5Nbk.js} +3 -3
  28. package/dist/chunks/{generate-Bm_jOMtF.js.map → generate-Df7t5Nbk.js.map} +1 -1
  29. package/dist/chunks/{generate-Cqwa8kD9.js → generate-DoHn_xJZ.js} +2 -2
  30. package/dist/chunks/{generate-Cqwa8kD9.js.map → generate-DoHn_xJZ.js.map} +1 -1
  31. package/dist/chunks/generate-DyV5R8NP.js.map +1 -1
  32. package/dist/chunks/{generate-D3mSFPdT.js → generate-l2JZTRKb.js} +2 -2
  33. package/dist/chunks/{generate-D3mSFPdT.js.map → generate-l2JZTRKb.js.map} +1 -1
  34. package/dist/chunks/{generate.runtime-FGYc365Q.js → generate.runtime-1ldXcpiD.js} +6 -6
  35. package/dist/chunks/{generate.runtime-FGYc365Q.js.map → generate.runtime-1ldXcpiD.js.map} +1 -1
  36. package/dist/chunks/{generate.runtime-B2r11K7S.js → generate.runtime-B53OTMcE.js} +6 -6
  37. package/dist/chunks/{generate.runtime-B2r11K7S.js.map → generate.runtime-B53OTMcE.js.map} +1 -1
  38. package/dist/chunks/{generate.runtime-DCqf7nYM.js → generate.runtime-B84ymwlD.js} +7 -7
  39. package/dist/chunks/{generate.runtime-DCqf7nYM.js.map → generate.runtime-B84ymwlD.js.map} +1 -1
  40. package/dist/chunks/{generate.runtime-Dug2UIhV.js → generate.runtime-BOl3LpPB.js} +10 -13
  41. package/dist/chunks/{generate.runtime-Dug2UIhV.js.map → generate.runtime-BOl3LpPB.js.map} +1 -1
  42. package/dist/chunks/{generate.runtime-BxDUtkpT.js → generate.runtime-BP31tAcD.js} +5 -5
  43. package/dist/chunks/{generate.runtime-BxDUtkpT.js.map → generate.runtime-BP31tAcD.js.map} +1 -1
  44. package/dist/chunks/{generate.runtime-DdcVnK8J.js → generate.runtime-BoYwV0nt.js} +133 -121
  45. package/dist/chunks/generate.runtime-BoYwV0nt.js.map +1 -0
  46. package/dist/chunks/{generate.runtime-wGRE1zwZ.js → generate.runtime-BqCbJ-No.js} +4 -4
  47. package/dist/chunks/{generate.runtime-wGRE1zwZ.js.map → generate.runtime-BqCbJ-No.js.map} +1 -1
  48. package/dist/chunks/{generate.runtime-BVavIXtX.js → generate.runtime-Bvjj3zn0.js} +6 -6
  49. package/dist/chunks/{generate.runtime-BVavIXtX.js.map → generate.runtime-Bvjj3zn0.js.map} +1 -1
  50. package/dist/chunks/{generate.runtime-_c7daMAw.js → generate.runtime-ByPcr9vJ.js} +4 -4
  51. package/dist/chunks/{generate.runtime-_c7daMAw.js.map → generate.runtime-ByPcr9vJ.js.map} +1 -1
  52. package/dist/chunks/{generate.runtime-Dmob2wFf.js → generate.runtime-C4LUUuq7.js} +5 -5
  53. package/dist/chunks/{generate.runtime-Dmob2wFf.js.map → generate.runtime-C4LUUuq7.js.map} +1 -1
  54. package/dist/chunks/{generate.runtime-wziCW3ct.js → generate.runtime-CGjDfO1P.js} +5 -5
  55. package/dist/chunks/{generate.runtime-wziCW3ct.js.map → generate.runtime-CGjDfO1P.js.map} +1 -1
  56. package/dist/chunks/{generate.runtime-DYdkrHJ1.js → generate.runtime-CHQ_MQJQ.js} +6 -6
  57. package/dist/chunks/{generate.runtime-DYdkrHJ1.js.map → generate.runtime-CHQ_MQJQ.js.map} +1 -1
  58. package/dist/chunks/{generate.runtime-aN5QWygO.js → generate.runtime-CHS5lyHL.js} +39 -36
  59. package/dist/chunks/generate.runtime-CHS5lyHL.js.map +1 -0
  60. package/dist/chunks/{generate.runtime-CyGR8VTx.js → generate.runtime-CHUCMVa2.js} +3 -3
  61. package/dist/chunks/{generate.runtime-CyGR8VTx.js.map → generate.runtime-CHUCMVa2.js.map} +1 -1
  62. package/dist/chunks/{generate.runtime-BxUGDXIK.js → generate.runtime-CVWCUn52.js} +6 -6
  63. package/dist/chunks/{generate.runtime-BxUGDXIK.js.map → generate.runtime-CVWCUn52.js.map} +1 -1
  64. package/dist/chunks/generate.runtime-C_5Ghjri.js +17 -0
  65. package/dist/chunks/generate.runtime-C_5Ghjri.js.map +1 -0
  66. package/dist/chunks/{generate.runtime-CRhD98rs.js → generate.runtime-Cv3unKap.js} +5 -5
  67. package/dist/chunks/{generate.runtime-CRhD98rs.js.map → generate.runtime-Cv3unKap.js.map} +1 -1
  68. package/dist/chunks/{generate.runtime-CkmledBw.js → generate.runtime-D677SB4v.js} +12 -20
  69. package/dist/chunks/{generate.runtime-CkmledBw.js.map → generate.runtime-D677SB4v.js.map} +1 -1
  70. package/dist/chunks/{generate.runtime-DeniHg8L.js → generate.runtime-DERcpgc-.js} +5 -5
  71. package/dist/chunks/{generate.runtime-DeniHg8L.js.map → generate.runtime-DERcpgc-.js.map} +1 -1
  72. package/dist/chunks/{generate.runtime-x-o4LS8d.js → generate.runtime-DJ5uF6EN.js} +4 -4
  73. package/dist/chunks/{generate.runtime-x-o4LS8d.js.map → generate.runtime-DJ5uF6EN.js.map} +1 -1
  74. package/dist/chunks/{generate.runtime-CYBs0JgY.js → generate.runtime-Dfz53sSK.js} +5 -5
  75. package/dist/chunks/{generate.runtime-CYBs0JgY.js.map → generate.runtime-Dfz53sSK.js.map} +1 -1
  76. package/dist/chunks/{generate.runtime-CWnIiXwV.js → generate.runtime-DiqfbDfk.js} +3 -3
  77. package/dist/chunks/{generate.runtime-CWnIiXwV.js.map → generate.runtime-DiqfbDfk.js.map} +1 -1
  78. package/dist/chunks/{generate.runtime-CHb4znYx.js → generate.runtime-Dq6yS7tN.js} +6 -6
  79. package/dist/chunks/{generate.runtime-CHb4znYx.js.map → generate.runtime-Dq6yS7tN.js.map} +1 -1
  80. package/dist/chunks/{generate.runtime-BRCzUO94.js → generate.runtime-T7JLE4Wc.js} +10 -14
  81. package/dist/chunks/{generate.runtime-BRCzUO94.js.map → generate.runtime-T7JLE4Wc.js.map} +1 -1
  82. package/dist/chunks/{generate.runtime-Du4uf98c.js → generate.runtime-WPq7bHRA.js} +3 -3
  83. package/dist/chunks/{generate.runtime-Du4uf98c.js.map → generate.runtime-WPq7bHRA.js.map} +1 -1
  84. package/dist/chunks/{generate.runtime-kpqW3dVO.js → generate.runtime-WeDv05E2.js} +8 -8
  85. package/dist/chunks/{generate.runtime-kpqW3dVO.js.map → generate.runtime-WeDv05E2.js.map} +1 -1
  86. package/dist/chunks/{generate.runtime-N1KtAG8C.js → generate.runtime-aKNvrk3M.js} +90 -175
  87. package/dist/chunks/generate.runtime-aKNvrk3M.js.map +1 -0
  88. package/dist/chunks/{generate.runtime-Bh9Z2cRN.js → generate.runtime-e_BkDyP0.js} +3 -3
  89. package/dist/chunks/{generate.runtime-Bh9Z2cRN.js.map → generate.runtime-e_BkDyP0.js.map} +1 -1
  90. package/dist/chunks/{generate.runtime-DY5vQ3aZ.js → generate.runtime-gZ4wfYBP.js} +8 -8
  91. package/dist/chunks/{generate.runtime-DY5vQ3aZ.js.map → generate.runtime-gZ4wfYBP.js.map} +1 -1
  92. package/dist/chunks/{generate.runtime-DUo-pLRr.js → generate.runtime-oUJUQRdg.js} +7 -7
  93. package/dist/chunks/{generate.runtime-DUo-pLRr.js.map → generate.runtime-oUJUQRdg.js.map} +1 -1
  94. package/dist/chunks/{generate.runtime-gFr2Gsjz.js → generate.runtime-q17D7QUT.js} +5 -5
  95. package/dist/chunks/{generate.runtime-gFr2Gsjz.js.map → generate.runtime-q17D7QUT.js.map} +1 -1
  96. package/dist/chunks/{generate.runtime-B4u9C2YH.js → generate.runtime-rLlDp4R6.js} +5 -5
  97. package/dist/chunks/{generate.runtime-B4u9C2YH.js.map → generate.runtime-rLlDp4R6.js.map} +1 -1
  98. package/dist/chunks/{generate.runtime-bpH3DB0t.js → generate.runtime-zr6uIHCd.js} +3 -3
  99. package/dist/chunks/{generate.runtime-bpH3DB0t.js.map → generate.runtime-zr6uIHCd.js.map} +1 -1
  100. package/dist/chunks/{modify-file-289rStJ2.js → modify-file-B4uJzOEj.js} +4 -4
  101. package/dist/chunks/{modify-file-289rStJ2.js.map → modify-file-B4uJzOEj.js.map} +1 -1
  102. package/dist/chunks/{modify-nav-user-B8h8WTrM.js → modify-nav-user-CJ1LevSU.js} +2 -2
  103. package/dist/chunks/{modify-nav-user-B8h8WTrM.js.map → modify-nav-user-CJ1LevSU.js.map} +1 -1
  104. package/dist/chunks/{modify-svelte-config-remote-DhuRX4FI.js → modify-svelte-config-remote-CEyYydL7.js} +2 -2
  105. package/dist/chunks/{modify-svelte-config-remote-DhuRX4FI.js.map → modify-svelte-config-remote-CEyYydL7.js.map} +1 -1
  106. package/dist/chunks/{modify-user-signup-BbqTiUuA.js → modify-user-signup-DLtopazD.js} +2 -2
  107. package/dist/chunks/{modify-user-signup-BbqTiUuA.js.map → modify-user-signup-DLtopazD.js.map} +1 -1
  108. package/dist/chunks/{package-imports-Bbw3iMPg.js → package-imports-B9Asv3ZH.js} +3 -3
  109. package/dist/chunks/{package-imports-Bbw3iMPg.js.map → package-imports-B9Asv3ZH.js.map} +1 -1
  110. package/dist/chunks/{pocketbase-B017Cqjq.js → pocketbase-BtN-wL8f.js} +9 -17
  111. package/dist/chunks/{pocketbase-B017Cqjq.js.map → pocketbase-BtN-wL8f.js.map} +1 -1
  112. package/dist/chunks/{providers-CN5J5_fY.js → providers-DRwJnSzb.js} +2 -2
  113. package/dist/chunks/{providers-CN5J5_fY.js.map → providers-DRwJnSzb.js.map} +1 -1
  114. package/dist/chunks/{rolldown-runtime-DArdT4gl.js → rolldown-runtime-5HNE8Q1r.js} +1 -1
  115. package/dist/chunks/{shared-BPlAVf-T.js → shared-BbxLil4g.js} +2 -2
  116. package/dist/chunks/{shared-BPlAVf-T.js.map → shared-BbxLil4g.js.map} +1 -1
  117. package/dist/chunks/{site-DkU1-VRq.js → site-Dw2KIRJu.js} +2 -2
  118. package/dist/chunks/{site-DkU1-VRq.js.map → site-Dw2KIRJu.js.map} +1 -1
  119. package/dist/chunks/{table-core-vXEjJDYP.js → table-core-BHFT-uMX.js} +3 -3
  120. package/dist/chunks/{table-core-vXEjJDYP.js.map → table-core-BHFT-uMX.js.map} +1 -1
  121. package/dist/chunks/{taggedTemplateLiteral-CswN2AAa.js → taggedTemplateLiteral-KSUnuvOk.js} +1 -1
  122. package/dist/chunks/{test-setup-CAfgVlwc.js → test-setup-BVJwm22s.js} +5 -5
  123. package/dist/chunks/{test-setup-CAfgVlwc.js.map → test-setup-BVJwm22s.js.map} +1 -1
  124. package/dist/chunks/{ts-morph-helpers-Bepc-Es2.js → ts-morph-helpers-CHI9wAil.js} +7 -11
  125. package/dist/chunks/{ts-morph-helpers-Bepc-Es2.js.map → ts-morph-helpers-CHI9wAil.js.map} +1 -1
  126. package/dist/chunks/{ui-CTdsenEv.js → ui-gG8i_Mzk.js} +3 -3
  127. package/dist/chunks/{ui-CTdsenEv.js.map → ui-gG8i_Mzk.js.map} +1 -1
  128. package/dist/chunks/{unmodify-load-Bl5vXQiL.js → unmodify-load-Buak-r1f.js} +2 -2
  129. package/dist/chunks/{unmodify-load-Bl5vXQiL.js.map → unmodify-load-Buak-r1f.js.map} +1 -1
  130. package/dist/chunks/{whatsapp-5qJ_xCV1.js → whatsapp-DbjOxHaZ.js} +2 -2
  131. package/dist/chunks/{whatsapp-5qJ_xCV1.js.map → whatsapp-DbjOxHaZ.js.map} +1 -1
  132. package/dist/chunks/write-result-DcqMefuP.js +499 -0
  133. package/dist/chunks/write-result-DcqMefuP.js.map +1 -0
  134. package/dist/chunks/wuchale-config-c3Q4JVSF.js +50 -0
  135. package/dist/chunks/wuchale-config-c3Q4JVSF.js.map +1 -0
  136. package/dist/index.d.ts +173 -19
  137. package/dist/index.js +2330 -2505
  138. package/dist/index.js.map +1 -1
  139. package/package.json +2 -2
  140. package/dist/chunks/collections-B_DisSfA.js.map +0 -1
  141. package/dist/chunks/constants-iej3WkEa.js +0 -6
  142. package/dist/chunks/constants-iej3WkEa.js.map +0 -1
  143. package/dist/chunks/generate-8FS2ROOJ.js +0 -170
  144. package/dist/chunks/generate-8FS2ROOJ.js.map +0 -1
  145. package/dist/chunks/generate-jx5Iuq5w.js.map +0 -1
  146. package/dist/chunks/generate.runtime-DdcVnK8J.js.map +0 -1
  147. package/dist/chunks/generate.runtime-N1KtAG8C.js.map +0 -1
  148. package/dist/chunks/generate.runtime-aN5QWygO.js.map +0 -1
  149. package/dist/chunks/shopify-page-D-VFwGxI.js +0 -11
  150. package/dist/chunks/shopify-page-D-VFwGxI.js.map +0 -1
  151. package/dist/chunks/write-result-0HYIr5a6.js +0 -511
  152. package/dist/chunks/write-result-0HYIr5a6.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-BxDUtkpT.js","names":["getLogger","withPocketbase","getMigrationFile","modifyOutcomeToFile","hasWhatsAppPlugin","writeWhatsAppConfigMigration","enableWhatsAppAuth","MIN_POCKETBASE_SERVER","fs","path","modifyTestSetup","setupPath","original","content","indent","head","tail","bodyIndent","value","fieldIndent","DOCS_URL","migrationCreate","file","generate","logger","options","creates","pb","setupWhatsAppFields","migrationDelay","configMigration","modifies","outcomes","swapAuthPages","filePath","outcome","testSetup","testSetupFile"],"sources":["../../src/patterns/enable/whatsapp/modifies/modify-test-setup.ts","../../src/patterns/enable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * `email` turns optional on `users`, which the generated types follow, so a\n * test setup from before enable-backend handled that no longer type-checks:\n * its `authenticateUser` takes `{ email: string }` and it signs the test\n * user in with `context.user.email`. Brings those two spots up to the\n * current setup; anything else in the file is the project's own.\n */\nexport function modifyTestSetup(setupPath: string): ModifyOutcome {\n if (!fs.existsSync(setupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(setupPath, \"utf8\");\n let content = original;\n\n content = content.replace(\n /^([ \\t]*)(async function authenticateUser\\(agent: Agent, user: \\{ )email: string( \\}\\) \\{\\n)([ \\t]*)/m,\n (_, indent, head, tail, bodyIndent) =>\n `${indent}${head}email?: string${tail}` +\n `${bodyIndent}// Logs in with the password, so it needs the email (made optional by\\n` +\n `${bodyIndent}// enable-whatsapp, for accounts that sign in with a phone number).\\n` +\n `${bodyIndent}if (!user.email) {\\n` +\n `${bodyIndent}${bodyIndent.includes(\"\\t\") ? \"\\t\" : \" \"}throw new Error('authenticateUser needs a user with an email');\\n` +\n `${bodyIndent}}\\n` +\n bodyIndent,\n );\n\n // The user is made with a known email: sign in with that.\n content = content.replace(\n /^([ \\t]*)context\\.user = await context\\.admin\\.collection\\('users'\\)\\.create\\(\\{\\n([ \\t]*)email: (`test-\\$\\{Math\\.random\\(\\)\\.toString\\(36\\)\\.slice\\(2\\)\\}@example\\.com`),/m,\n (_, indent, fieldIndent, value) =>\n `${indent}const email = ${value};\\n` +\n `${indent}context.user = await context.admin.collection('users').create({\\n` +\n `${fieldIndent}email,`,\n );\n if (content.includes(\"const email = `test-\")) {\n content = content.replace(\n \".authWithPassword(context.user.email, testUserPassword)\",\n \".authWithPassword(email, testUserPassword)\",\n );\n }\n\n if (content === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(setupPath, content, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n MIN_POCKETBASE_SERVER,\n enableWhatsAppAuth,\n hasWhatsAppPlugin,\n setupWhatsAppFields,\n writeWhatsAppConfigMigration,\n} from \"./runtime/whatsapp\";\nimport { swapAuthPages } from \"./modifies/auth-pages\";\nimport { modifyTestSetup } from \"./modifies/modify-test-setup\";\n\nexport const DOCS_URL = \"https://velastack.dev/docs/enable/whatsapp\";\n\nfunction migrationCreate(file: string): File {\n return {\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n };\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 if (!(await hasWhatsAppPlugin(pb))) {\n throw new Error(\n `This PocketBase has no WhatsApp sign-in. It comes with pocketbase-server ${MIN_POCKETBASE_SERVER} and later: run \\`npm install -D pocketbase-server@^${MIN_POCKETBASE_SERVER}\\`, then \\`vela enable whatsapp\\` again.`,\n );\n }\n\n logger.info(\"Adding the phone fields to users and making email optional\");\n if (await setupWhatsAppFields(pb)) {\n await migrationDelay();\n const file = getMigrationFile(\"users\", \"updated\", options);\n if (file) creates.push(migrationCreate(file));\n }\n\n logger.info(\"Turning on WhatsApp sign-in for users\");\n await enableWhatsAppAuth(pb);\n await migrationDelay();\n const configMigration = writeWhatsAppConfigMigration(options, true);\n if (configMigration) creates.push(migrationCreate(configMigration));\n });\n\n logger.info(\"Adding WhatsApp to the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"enable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-auth wrote, so it was left as it is. Add the WhatsApp option to it by hand: ${DOCS_URL}`,\n );\n for (const [filePath, outcome] of outcomes) {\n const file = modifyOutcomeToFile(filePath, outcome);\n if (file) modifies.push(file);\n }\n\n logger.info(\"Updating test/setup.ts for an optional email\");\n const testSetup = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetup,\n modifyTestSetup(testSetup),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAUA,SAAgBU,EAAgB,GAAkC;CAChE,IAAI,CAACF,EAAG,WAAWG,CAAS,GAC1B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAW,MAAM,GAC9CE,IAAUD;CAiCd,OA/BA,IAAUC,EAAQ,QAChB,0GACC,GAAG,GAAQ,GAAM,GAAM,MACtB,GAAGC,IAASC,EAAK,gBAAgBC,IAC9BC,EAAW,yEACXA,EAAW,uEACXA,EAAW,sBACXA,IAAaA,EAAW,SAAS,GAAI,IAAI,MAAO,KAAK,mEACrDA,EAAW,OACdA,CACJ,GAGA,IAAUJ,EAAQ,QAChB,gLACC,GAAG,GAAQ,GAAa,MACvB,GAAGC,EAAO,gBAAgBI,EAAM,KAC7BJ,EAAO,mEACPK,EAAY,OACnB,GACIN,EAAQ,SAAS,sBAAsB,MACzC,IAAUA,EAAQ,QAChB,2DACA,4CACF,IAGEA,MAAYD,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAE7CJ,EAAG,cAAcG,GAAWE,GAAS,MAAM,GACpC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;AC9BA,IAAaO,IAAW;AAExB,SAASC,EAAgB,GAAoB;CAC3C,OAAO;EACL,MAAMC;EACN,UAAU;EACV,SAASd,EAAG,aAAac,GAAM,MAAM;EACrC,QAAQ;CACV;AACF;AAEA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASxB,EAAUyB,CAAO,GAC1BC,IAAkB,CAAC;CAuBzB,AArBA,MAAMzB,EAAewB,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAI,CAAE,MAAMrB,EAAkBuB,CAAE,GAC9B,MAAU,MACR,4EAA4EpB,EAAsB,sDAAsDA,EAAsB,yCAChL;EAIF,IADAiB,EAAO,KAAK,4DAA4D,GACpE,MAAMI,EAAoBD,CAAE,GAAG;GACjC,MAAME,EAAe;GACrB,IAAMP,IAAOpB,EAAiB,SAAS,WAAWuB,CAAO;GACzD,AAAIH,KAAMI,EAAQ,KAAKL,EAAgBC,CAAI,CAAC;EAC9C;EAIA,AAFAE,EAAO,KAAK,uCAAuC,GACnD,MAAMlB,EAAmBqB,CAAE,GAC3B,MAAME,EAAe;EACrB,IAAMC,IAAkBzB,EAA6BoB,GAAS,EAAI;EAClE,AAAIK,KAAiBJ,EAAQ,KAAKL,EAAgBS,CAAe,CAAC;CACpE,CAAC,GAEDN,EAAO,KAAK,+CAA+C;CAC3D,IAAMO,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBR,EAAQ,MACR,WACC,MACC,GAAGhB,EAAK,SAASgB,EAAQ,MAAMS,CAAQ,EAAE,sGAAsGd,GACnJ;CACA,KAAK,IAAM,CAACc,GAAUC,MAAYH,GAAU;EAC1C,IAAMV,IAAOnB,EAAoB+B,GAAUC,CAAO;EAClD,AAAIb,KAAMS,EAAS,KAAKT,CAAI;CAC9B;CAEA,EAAO,KAAK,8CAA8C;CAC1D,IAAMc,IAAY3B,EAAK,KAAKgB,EAAQ,MAAM,QAAQ,UAAU,GACtDY,IAAgBlC,EACpBiC,GACA1B,EAAgB0B,CAAS,CAC3B;CAGA,OAFIC,KAAeN,EAAS,KAAKM,CAAa,GAEvC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
1
+ {"version":3,"file":"generate.runtime-BP31tAcD.js","names":["getLogger","withPocketbase","getMigrationFile","modifyOutcomeToFile","hasWhatsAppPlugin","writeWhatsAppConfigMigration","enableWhatsAppAuth","MIN_POCKETBASE_SERVER","fs","path","modifyTestSetup","setupPath","original","content","indent","head","tail","bodyIndent","value","fieldIndent","DOCS_URL","migrationCreate","file","generate","logger","options","creates","pb","setupWhatsAppFields","migrationDelay","configMigration","modifies","outcomes","swapAuthPages","filePath","outcome","testSetup","testSetupFile"],"sources":["../../src/patterns/enable/whatsapp/modifies/modify-test-setup.ts","../../src/patterns/enable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * `email` turns optional on `users`, which the generated types follow, so a\n * test setup from before enable-backend handled that no longer type-checks:\n * its `authenticateUser` takes `{ email: string }` and it signs the test\n * user in with `context.user.email`. Brings those two spots up to the\n * current setup; anything else in the file is the project's own.\n */\nexport function modifyTestSetup(setupPath: string): ModifyOutcome {\n if (!fs.existsSync(setupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(setupPath, \"utf8\");\n let content = original;\n\n content = content.replace(\n /^([ \\t]*)(async function authenticateUser\\(agent: Agent, user: \\{ )email: string( \\}\\) \\{\\n)([ \\t]*)/m,\n (_, indent, head, tail, bodyIndent) =>\n `${indent}${head}email?: string${tail}` +\n `${bodyIndent}// Logs in with the password, so it needs the email (made optional by\\n` +\n `${bodyIndent}// enable-whatsapp, for accounts that sign in with a phone number).\\n` +\n `${bodyIndent}if (!user.email) {\\n` +\n `${bodyIndent}${bodyIndent.includes(\"\\t\") ? \"\\t\" : \" \"}throw new Error('authenticateUser needs a user with an email');\\n` +\n `${bodyIndent}}\\n` +\n bodyIndent,\n );\n\n // The user is made with a known email: sign in with that.\n content = content.replace(\n /^([ \\t]*)context\\.user = await context\\.admin\\.collection\\('users'\\)\\.create\\(\\{\\n([ \\t]*)email: (`test-\\$\\{Math\\.random\\(\\)\\.toString\\(36\\)\\.slice\\(2\\)\\}@example\\.com`),/m,\n (_, indent, fieldIndent, value) =>\n `${indent}const email = ${value};\\n` +\n `${indent}context.user = await context.admin.collection('users').create({\\n` +\n `${fieldIndent}email,`,\n );\n if (content.includes(\"const email = `test-\")) {\n content = content.replace(\n \".authWithPassword(context.user.email, testUserPassword)\",\n \".authWithPassword(email, testUserPassword)\",\n );\n }\n\n if (content === original) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(setupPath, content, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n MIN_POCKETBASE_SERVER,\n enableWhatsAppAuth,\n hasWhatsAppPlugin,\n setupWhatsAppFields,\n writeWhatsAppConfigMigration,\n} from \"./runtime/whatsapp\";\nimport { swapAuthPages } from \"./modifies/auth-pages\";\nimport { modifyTestSetup } from \"./modifies/modify-test-setup\";\n\nexport const DOCS_URL = \"https://velastack.dev/docs/enable/whatsapp\";\n\nfunction migrationCreate(file: string): File {\n return {\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n };\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 if (!(await hasWhatsAppPlugin(pb))) {\n throw new Error(\n `This PocketBase has no WhatsApp sign-in. It comes with pocketbase-server ${MIN_POCKETBASE_SERVER} and later: run \\`npm install -D pocketbase-server@^${MIN_POCKETBASE_SERVER}\\`, then \\`vela enable whatsapp\\` again.`,\n );\n }\n\n logger.info(\"Adding the phone fields to users and making email optional\");\n if (await setupWhatsAppFields(pb)) {\n await migrationDelay();\n const file = getMigrationFile(\"users\", \"updated\", options);\n if (file) creates.push(migrationCreate(file));\n }\n\n logger.info(\"Turning on WhatsApp sign-in for users\");\n await enableWhatsAppAuth(pb);\n await migrationDelay();\n const configMigration = writeWhatsAppConfigMigration(options, true);\n if (configMigration) creates.push(migrationCreate(configMigration));\n });\n\n logger.info(\"Adding WhatsApp to the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"enable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-auth wrote, so it was left as it is. Add the WhatsApp option to it by hand: ${DOCS_URL}`,\n );\n for (const [filePath, outcome] of outcomes) {\n const file = modifyOutcomeToFile(filePath, outcome);\n if (file) modifies.push(file);\n }\n\n logger.info(\"Updating test/setup.ts for an optional email\");\n const testSetup = path.join(options.root, \"test\", \"setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetup,\n modifyTestSetup(testSetup),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAUA,SAAgBU,EAAgB,GAAkC;CAChE,IAAI,CAACF,EAAG,WAAWG,CAAS,GAC1B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAWJ,EAAG,aAAaG,GAAW,MAAM,GAC9CE,IAAUD;CAiCd,OA/BA,IAAUC,EAAQ,QAChB,0GACC,GAAG,GAAQ,GAAM,GAAM,MACtB,GAAGC,IAASC,EAAK,gBAAgBC,IAC9BC,EAAW,yEACXA,EAAW,uEACXA,EAAW,sBACXA,IAAaA,EAAW,SAAS,GAAI,IAAI,MAAO,KAAK,mEACrDA,EAAW,OACdA,CACJ,GAGA,IAAUJ,EAAQ,QAChB,gLACC,GAAG,GAAQ,GAAa,MACvB,GAAGC,EAAO,gBAAgBI,EAAM,KAC7BJ,EAAO,mEACPK,EAAY,OACnB,GACIN,EAAQ,SAAS,sBAAsB,MACzC,IAAUA,EAAQ,QAChB,2DACA,4CACF,IAGEA,MAAYD,IACP;EAAE,QAAQ;EAAW,SAAS;CAAM,KAE7CJ,EAAG,cAAcG,GAAWE,GAAS,MAAM,GACpC;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;AC9BA,IAAaO,IAAW;AAExB,SAASC,EAAgB,GAAoB;CAC3C,OAAO;EACL,MAAMC;EACN,UAAU;EACV,SAASd,EAAG,aAAac,GAAM,MAAM;EACrC,QAAQ;CACV;AACF;AAEA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASxB,EAAUyB,CAAO,GAC1BC,IAAkB,CAAC;CAuBzB,AArBA,MAAMzB,EAAewB,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAI,CAAE,MAAMrB,EAAkBuB,CAAE,GAC9B,MAAU,MACR,4EAA4EpB,EAAsB,sDAAsDA,EAAsB,yCAChL;EAIF,IADAiB,EAAO,KAAK,4DAA4D,GACpE,MAAMI,EAAoBD,CAAE,GAAG;GACjC,MAAME,EAAe;GACrB,IAAMP,IAAOpB,EAAiB,SAAS,WAAWuB,CAAO;GACzD,AAAIH,KAAMI,EAAQ,KAAKL,EAAgBC,CAAI,CAAC;EAC9C;EAIA,AAFAE,EAAO,KAAK,uCAAuC,GACnD,MAAMlB,EAAmBqB,CAAE,GAC3B,MAAME,EAAe;EACrB,IAAMC,IAAkBzB,EAA6BoB,GAAS,EAAI;EAClE,AAAIK,KAAiBJ,EAAQ,KAAKL,EAAgBS,CAAe,CAAC;CACpE,CAAC,GAEDN,EAAO,KAAK,+CAA+C;CAC3D,IAAMO,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBR,EAAQ,MACR,WACC,MACC,GAAGhB,EAAK,SAASgB,EAAQ,MAAMS,CAAQ,EAAE,sGAAsGd,GACnJ;CACA,KAAK,IAAM,CAACc,GAAUC,MAAYH,GAAU;EAC1C,IAAMV,IAAOnB,EAAoB+B,GAAUC,CAAO;EAClD,AAAIb,KAAMS,EAAS,KAAKT,CAAI;CAC9B;CAEA,EAAO,KAAK,8CAA8C;CAC1D,IAAMc,IAAY3B,EAAK,KAAKgB,EAAQ,MAAM,QAAQ,UAAU,GACtDY,IAAgBlC,EACpBiC,GACA1B,EAAgB0B,CAAS,CAC3B;CAGA,OAFIC,KAAeN,EAAS,KAAKM,CAAa,GAEvC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,17 +1,18 @@
1
1
  import { t as e } from "./dedent-Gq6Krl4n.js";
2
2
  import { t } from "./ui-DD4NltyN.js";
3
3
  import { n } from "./logger-CQONztPm.js";
4
- import { _ as r, i, o as a, r as o } from "./ts-morph-helpers-Bepc-Es2.js";
5
- import { r as s } from "./modify-file-289rStJ2.js";
4
+ import { _ as r, i, o as a, r as o } from "./ts-morph-helpers-CHI9wAil.js";
5
+ import { r as s } from "./modify-file-B4uJzOEj.js";
6
6
  import { t as c } from "./svelte-file-Dv5-bl79.js";
7
- import { t as l } from "./compose-handle-BDlZ7Pif.js";
8
- import { a as u, t as d } from "./config-target-rHgjaA8u.js";
9
- import { i as f, n as p } from "./_layout-D-FzWqn0.js";
10
- import m from "node:fs";
11
- import h from "node:path";
12
- import { Project as g, QuoteKind as _, SyntaxKind as v } from "ts-morph";
7
+ import { t as l } from "./compose-handle-BBlamPfx.js";
8
+ import { a as u, t as d } from "./config-target-BgyFkbFL.js";
9
+ import { i as f, n as p } from "./_layout-DQhSAhfF.js";
10
+ import { r as m, t as h } from "./wuchale-config-c3Q4JVSF.js";
11
+ import g from "node:fs";
12
+ import _ from "node:path";
13
+ import { Project as v, QuoteKind as y, SyntaxKind as b } from "ts-morph";
13
14
  //#region src/patterns/enable/i18n/modifies/vite-config.ts
14
- var y = [
15
+ var x = [
15
16
  "Add the wuchale plugin to your Vite config:",
16
17
  "",
17
18
  "import { wuchale } from 'wuchale/vite';",
@@ -19,7 +20,7 @@ var y = [
19
20
  "export default defineConfig({",
20
21
  " plugins: [wuchale(), /* ...existing plugins */],",
21
22
  "});"
22
- ].join("\n"), b = [
23
+ ].join("\n"), S = [
23
24
  "Create a Vite config with the wuchale plugin:",
24
25
  "",
25
26
  "import { defineConfig } from 'vite';",
@@ -29,20 +30,20 @@ var y = [
29
30
  " plugins: [wuchale()],",
30
31
  "});"
31
32
  ].join("\n");
32
- function x(e) {
33
- if (!m.existsSync(e)) return {
33
+ function C(e) {
34
+ if (!g.existsSync(e)) return {
34
35
  status: "not-found",
35
- message: b
36
+ message: S
36
37
  };
37
- let t = new g({
38
+ let t = new v({
38
39
  compilerOptions: { allowJs: !0 },
39
- manipulationSettings: { quoteKind: _.Single }
40
+ manipulationSettings: { quoteKind: y.Single }
40
41
  }).addSourceFileAtPath(e), n = !1, r = !1;
41
42
  t.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "wuchale/vite") || (t.insertImportDeclaration(0, {
42
43
  namedImports: ["wuchale"],
43
44
  moduleSpecifier: "wuchale/vite"
44
45
  }), n = !0);
45
- let i = t.getDescendantsOfKind(v.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], o = i?.getKind() === v.ObjectLiteralExpression ? i : null;
46
+ let i = t.getDescendantsOfKind(b.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], o = i?.getKind() === b.ObjectLiteralExpression ? i : null;
46
47
  if (!o) r = !0;
47
48
  else {
48
49
  let e = o.getProperty("plugins");
@@ -50,11 +51,11 @@ function x(e) {
50
51
  name: "plugins",
51
52
  initializer: "[wuchale()]"
52
53
  }), n = !0;
53
- else if (e.getKind() !== v.PropertyAssignment) r = !0;
54
+ else if (e.getKind() !== b.PropertyAssignment) r = !0;
54
55
  else {
55
56
  let t = e.getInitializer();
56
57
  if (!t) e.setInitializer("[wuchale()]"), n = !0;
57
- else if (t.getKind() !== v.ArrayLiteralExpression) r = !0;
58
+ else if (t.getKind() !== b.ArrayLiteralExpression) r = !0;
58
59
  else {
59
60
  let e = t;
60
61
  e.getElements().some((e) => e.getText().replace(/\s/g, "") === "wuchale()") || (e.insertElement(0, "wuchale()"), n = !0);
@@ -63,7 +64,7 @@ function x(e) {
63
64
  }
64
65
  return n && (a(t), t.saveSync()), r ? {
65
66
  status: "failed",
66
- message: y
67
+ message: x
67
68
  } : {
68
69
  status: "success",
69
70
  changed: n
@@ -71,7 +72,7 @@ function x(e) {
71
72
  }
72
73
  //#endregion
73
74
  //#region src/patterns/enable/i18n/modifies/hooks.server.ts
74
- var S = "handleWuchale", C = e`
75
+ var w = "handleWuchale", T = e`
75
76
  Wrap your exported handle with the wuchale i18n handler:
76
77
 
77
78
  import { sequence } from '@sveltejs/kit/hooks';
@@ -95,7 +96,7 @@ var S = "handleWuchale", C = e`
95
96
  };
96
97
 
97
98
  export const handle = sequence(handleWuchale, /* your existing handle */);
98
- `, w = e`
99
+ `, E = e`
99
100
  import type { Handle } from '@sveltejs/kit/hooks';
100
101
  import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';
101
102
  import { getLocale } from '#locales/main.url.js';
@@ -117,40 +118,40 @@ var S = "handleWuchale", C = e`
117
118
 
118
119
  export const handle = handleWuchale;
119
120
  `;
120
- function T(e, t, n) {
121
+ function D(e, t, n) {
121
122
  e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t) || e.addImportDeclaration({
122
123
  namespaceImport: n,
123
124
  moduleSpecifier: t
124
125
  });
125
126
  }
126
- function E(t) {
127
- if (!m.existsSync(t)) return m.existsSync(t.replace(/\.ts$/, ".js")) ? {
127
+ function O(t) {
128
+ if (!g.existsSync(t)) return g.existsSync(t.replace(/\.ts$/, ".js")) ? {
128
129
  status: "failed",
129
- message: C
130
- } : (m.mkdirSync(h.dirname(t), { recursive: !0 }), m.writeFileSync(t, w + "\n"), {
130
+ message: T
131
+ } : (g.mkdirSync(_.dirname(t), { recursive: !0 }), g.writeFileSync(t, E + "\n"), {
131
132
  status: "success",
132
133
  changed: !0
133
134
  });
134
- let n = m.readFileSync(t, "utf8");
135
+ let n = g.readFileSync(t, "utf8");
135
136
  if (n.includes("runWithLocale") || n.includes("loadLocales(")) return {
136
137
  status: "success",
137
138
  changed: !1
138
139
  };
139
- let r = new g({
140
+ let r = new v({
140
141
  compilerOptions: { allowJs: !0 },
141
- manipulationSettings: { quoteKind: _.Single }
142
- }).addSourceFileAtPath(t), o = l(r, { expression: S });
142
+ manipulationSettings: { quoteKind: y.Single }
143
+ }).addSourceFileAtPath(t), o = l(r, { expression: w });
143
144
  if (o.status === "unsupported" || !o.statement) return {
144
145
  status: "failed",
145
- message: C
146
+ message: T
146
147
  };
147
148
  let s = o.statement;
148
- i(r, "wuchale/load-utils/server", "runWithLocale"), i(r, "wuchale/load-utils/server", "loadLocales"), i(r, "#locales/main.url.js", "getLocale"), i(r, "#locales/data.js", "locales"), T(r, "#locales/main.loader.server.svelte.js", "main"), T(r, "#locales/js.loader.server.js", "js");
149
+ i(r, "wuchale/load-utils/server", "runWithLocale"), i(r, "wuchale/load-utils/server", "loadLocales"), i(r, "#locales/main.url.js", "getLocale"), i(r, "#locales/data.js", "locales"), D(r, "#locales/main.loader.server.svelte.js", "main"), D(r, "#locales/js.loader.server.js", "js");
149
150
  let c = e`
150
151
  loadLocales(main.key, main.loadCount, main.loadCatalog, locales);
151
152
  loadLocales(js.key, js.loadCount, js.loadCatalog, locales);
152
153
  `, u = e`
153
- const ${S} = async ({ event, resolve }: any) => {
154
+ const ${w} = async ({ event, resolve }: any) => {
154
155
  const locale = getLocale(event.url);
155
156
  return await runWithLocale(locale, () =>
156
157
  resolve(event, {
@@ -167,13 +168,13 @@ function E(t) {
167
168
  }
168
169
  //#endregion
169
170
  //#region src/patterns/enable/i18n/modifies/hooks.ts
170
- var D = e`
171
+ var k = e`
171
172
  const rerouteDeLocalize = (url: string) => {
172
173
  const [upath, locale] = deLocalizeDefault(url, locales);
173
174
  const { path } = matchUrl(upath, locale);
174
175
  return path ?? url;
175
176
  };
176
- `, O = e`
177
+ `, A = e`
177
178
  import { deLocalizeDefault } from 'wuchale/url';
178
179
  import { matchUrl } from '#locales/main.url.js';
179
180
  import { locales } from '#locales/data.js';
@@ -185,7 +186,7 @@ var D = e`
185
186
  };
186
187
 
187
188
  export const reroute = ({ url }) => rerouteDeLocalize(url.pathname);
188
- `, k = e`
189
+ `, j = e`
189
190
  Compose your existing reroute in src/hooks.ts with the wuchale de-localizer:
190
191
 
191
192
  import { deLocalizeDefault } from 'wuchale/url';
@@ -199,56 +200,56 @@ var D = e`
199
200
  };
200
201
 
201
202
  export const reroute = ({ url }) => rerouteDeLocalize(existingReroute(url.pathname));
202
- `, A = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*negotiateReroute\(\s*url\.pathname\s*\)$/;
203
- function j(e) {
203
+ `, M = /^\(\s*\{\s*url\s*\}\s*\)\s*=>\s*negotiateReroute\(\s*url\.pathname\s*\)$/;
204
+ function N(e) {
204
205
  return e.getFunction("reroute") ? !0 : e.getExportDeclarations().some((e) => e.getNamedExports().some((e) => (e.getAliasNode()?.getText() ?? e.getName()) === "reroute"));
205
206
  }
206
- function M(e) {
207
+ function P(e) {
207
208
  i(e, "wuchale/url", "deLocalizeDefault"), i(e, "#locales/main.url.js", "matchUrl"), i(e, "#locales/data.js", "locales");
208
209
  }
209
- function N(e) {
210
- if (!m.existsSync(e)) return m.mkdirSync(h.dirname(e), { recursive: !0 }), m.writeFileSync(e, O + "\n"), {
210
+ function ee(e) {
211
+ if (!g.existsSync(e)) return g.mkdirSync(_.dirname(e), { recursive: !0 }), g.writeFileSync(e, A + "\n"), {
211
212
  status: "success",
212
213
  changed: !0
213
214
  };
214
- if (m.readFileSync(e, "utf8").includes("rerouteDeLocalize")) return {
215
+ if (g.readFileSync(e, "utf8").includes("rerouteDeLocalize")) return {
215
216
  status: "success",
216
217
  changed: !1
217
218
  };
218
- let t = new g({
219
+ let t = new v({
219
220
  compilerOptions: { allowJs: !0 },
220
- manipulationSettings: { quoteKind: _.Single }
221
+ manipulationSettings: { quoteKind: y.Single }
221
222
  }).addSourceFileAtPath(e), n = t.getVariableDeclaration("reroute");
222
- if (!n) return j(t) ? {
223
+ if (!n) return N(t) ? {
223
224
  status: "failed",
224
- message: k
225
- } : (M(t), t.addStatements(`\n${D}\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`), a(t), t.saveSync(), {
225
+ message: j
226
+ } : (P(t), t.addStatements(`\n${k}\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n`), a(t), t.saveSync(), {
226
227
  status: "success",
227
228
  changed: !0
228
229
  });
229
- if (!n.getFirstAncestorByKind(v.VariableStatement)?.hasExportKeyword()) return {
230
+ if (!n.getFirstAncestorByKind(b.VariableStatement)?.hasExportKeyword()) return {
230
231
  status: "failed",
231
- message: k
232
+ message: j
232
233
  };
233
234
  let r = n.getInitializer();
234
- if (!r || !A.test(r.getText())) return {
235
+ if (!r || !M.test(r.getText())) return {
235
236
  status: "failed",
236
- message: k
237
+ message: j
237
238
  };
238
- M(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))");
239
+ P(t), n.setInitializer("({ url }) => rerouteDeLocalize(negotiateReroute(url.pathname))");
239
240
  let i = t.getVariableStatements().find((e) => e.getDeclarations().some((e) => e.getName() === "reroute"));
240
- return t.insertText(i.getStart(!0), `${D}\n\n`), a(t), t.saveSync(), {
241
+ return t.insertText(i.getStart(!0), `${k}\n\n`), a(t), t.saveSync(), {
241
242
  status: "success",
242
243
  changed: !0
243
244
  };
244
245
  }
245
246
  //#endregion
246
247
  //#region src/patterns/enable/i18n/modifies/app-html.ts
247
- var P = [
248
+ var F = [
248
249
  "Add the sveltekit lang placeholder to the <html> tag:",
249
250
  "",
250
251
  "<html lang=\"%sveltekit.lang%\">"
251
- ].join("\n"), F = [
252
+ ].join("\n"), I = [
252
253
  "Create src/app.html with a lang placeholder:",
253
254
  "",
254
255
  "<!doctype html>",
@@ -262,12 +263,12 @@ var P = [
262
263
  " </body>",
263
264
  "</html>"
264
265
  ].join("\n");
265
- function I(e) {
266
- if (!m.existsSync(e)) return {
266
+ function L(e) {
267
+ if (!g.existsSync(e)) return {
267
268
  status: "not-found",
268
- message: F
269
+ message: I
269
270
  };
270
- let t = m.readFileSync(e, "utf8");
271
+ let t = g.readFileSync(e, "utf8");
271
272
  if (t.includes("lang=\"%sveltekit.lang%\"") || t.includes("lang='%sveltekit.lang%'")) return {
272
273
  status: "success",
273
274
  changed: !1
@@ -275,26 +276,26 @@ function I(e) {
275
276
  let n = t.replace(/<html(\s[^>]*?)?>/i, (e) => /\slang\s*=/i.test(e) ? e.replace(/\slang\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i, " lang=\"%sveltekit.lang%\"") : e.replace(/<html/i, "<html lang=\"%sveltekit.lang%\""));
276
277
  return n === t ? {
277
278
  status: "failed",
278
- message: P
279
- } : (m.writeFileSync(e, n), {
279
+ message: F
280
+ } : (g.writeFileSync(e, n), {
280
281
  status: "success",
281
282
  changed: !0
282
283
  });
283
284
  }
284
285
  //#endregion
285
286
  //#region src/patterns/enable/i18n/modifies/gitignore.ts
286
- var L = [
287
+ var R = [
287
288
  "Create a .gitignore with the wuchale cache ignored:",
288
289
  "",
289
290
  "# Wuchale",
290
291
  "src/locales/.wuchale"
291
292
  ].join("\n");
292
- function R(t) {
293
- if (!m.existsSync(t)) return {
293
+ function z(t) {
294
+ if (!g.existsSync(t)) return {
294
295
  status: "not-found",
295
- message: L
296
+ message: R
296
297
  };
297
- let n = m.readFileSync(t, "utf8");
298
+ let n = g.readFileSync(t, "utf8");
298
299
  if (n.includes("src/locales/.wuchale")) return {
299
300
  status: "success",
300
301
  changed: !1
@@ -303,55 +304,55 @@ function R(t) {
303
304
  # Wuchale
304
305
  src/locales/.wuchale
305
306
  `, i = n + (n.length > 0 && !n.endsWith("\n") ? "\n" : "") + "\n" + r + "\n";
306
- return m.writeFileSync(t, i), {
307
+ return g.writeFileSync(t, i), {
307
308
  status: "success",
308
309
  changed: !0
309
310
  };
310
311
  }
311
312
  //#endregion
312
313
  //#region src/patterns/enable/i18n/modifies/root-layout.svelte.ts
313
- var z = "<Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n ", B = "<LanguageSelect />", V = e`
314
+ var B = "<Navbar.Item>\n <LanguageSelect />\n </Navbar.Item>\n ", V = "<LanguageSelect />", H = e`
314
315
  import LanguageSelect from '#lib/components/language-select.svelte';
315
- `, H = [
316
+ `, U = [
316
317
  "Add the language select inside your <Navbar.List> in the root layout.",
317
318
  "",
318
319
  "Import to add to the <script> tag:",
319
320
  "",
320
- V,
321
+ H,
321
322
  "",
322
323
  "Markup to add at the end of <Navbar.List>:",
323
- z
324
- ].join("\n"), U = [
324
+ B
325
+ ].join("\n"), W = [
325
326
  "Create a root layout that includes a language select inside <Navbar.List>.",
326
327
  "",
327
328
  "Import for the <script> tag:",
328
329
  "",
329
- V,
330
+ H,
330
331
  "",
331
332
  "Markup at the end of <Navbar.List>:",
332
- z
333
- ].join("\n"), W = [
333
+ B
334
+ ].join("\n"), G = [
334
335
  "Add the language select to your root layout.",
335
336
  "",
336
337
  "Import to add to the <script> tag:",
337
338
  "",
338
- V,
339
+ H,
339
340
  "",
340
341
  "Markup to add wherever it should render, e.g. above {@render children()}:",
341
342
  "",
342
- B
343
- ].join("\n"), G = [
343
+ V
344
+ ].join("\n"), K = [
344
345
  "Create a root layout that includes the language select.",
345
346
  "",
346
347
  "Import for the <script> tag:",
347
348
  "",
348
- V,
349
+ H,
349
350
  "",
350
351
  "Markup above {@render children()}:",
351
352
  "",
352
- B
353
+ V
353
354
  ].join("\n");
354
- function K(e) {
355
+ function q(e) {
355
356
  e.modifyScript((e) => {
356
357
  let { source: t } = r(e, (e) => {
357
358
  o(e, [{
@@ -362,45 +363,45 @@ function K(e) {
362
363
  return t;
363
364
  });
364
365
  }
365
- function q(e, t = "shadcn") {
366
+ function J(e, t = "shadcn") {
366
367
  let n = t === "plain";
367
- if (!m.existsSync(e)) return {
368
+ if (!g.existsSync(e)) return {
368
369
  status: "not-found",
369
- message: n ? G : U
370
+ message: n ? K : W
370
371
  };
371
372
  let r = c.fromPath(e);
372
373
  return r.hasElement("LanguageSelect") ? {
373
374
  status: "success",
374
375
  changed: !1
375
- } : n ? !r.getScript() || !r.insertBeforeChildren(B) ? {
376
+ } : n ? !r.getScript() || !r.insertBeforeChildren(V) ? {
376
377
  status: "failed",
377
- message: W
378
- } : (K(r), r.writeTo(e), {
378
+ message: G
379
+ } : (q(r), r.writeTo(e), {
379
380
  status: "success",
380
381
  changed: r.hasChanged()
381
- }) : r.hasElement("Navbar.List") ? (K(r), r.insertBeforeClosingTag("Navbar.List", z), r.writeTo(e), {
382
+ }) : r.hasElement("Navbar.List") ? (q(r), r.insertBeforeClosingTag("Navbar.List", B), r.writeTo(e), {
382
383
  status: "success",
383
384
  changed: r.hasChanged()
384
385
  }) : {
385
386
  status: "failed",
386
- message: H
387
+ message: U
387
388
  };
388
389
  }
389
390
  //#endregion
390
391
  //#region src/patterns/enable/i18n/welcome-catalog.ts
391
- var J = "src/routes/+page.svelte", Y = "src/locales/es.po", X = ["<h1>Welcome to SvelteKit</h1>", "<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>"].join("\n"), Z = [{
392
- reference: J,
392
+ var Y = "src/routes/+page.svelte", X = "src/locales/es.po", Z = ["<h1>Welcome to SvelteKit</h1>", "<p>Visit <a href=\"https://svelte.dev/docs/kit\">svelte.dev/docs/kit</a> to read the documentation</p>"].join("\n"), Q = [{
393
+ reference: Y,
393
394
  msgid: "Welcome to SvelteKit",
394
395
  msgstr: "Bienvenido a SvelteKit"
395
396
  }, {
396
- reference: J,
397
+ reference: Y,
397
398
  msgid: "Visit <0>svelte.dev/docs/kit</0> to read the documentation",
398
399
  msgstr: "Visita <0>svelte.dev/docs/kit</0> para leer la documentación"
399
- }], Q = {
400
+ }], te = {
400
401
  reference: "src/lib/components/language-select.svelte",
401
402
  msgid: "Language",
402
403
  msgstr: "Idioma"
403
- }, ee = [
404
+ }, ne = [
404
405
  "msgid \"\"",
405
406
  "msgstr \"\"",
406
407
  "\"Source-Language: en\\n\"",
@@ -411,13 +412,13 @@ var J = "src/routes/+page.svelte", Y = "src/locales/es.po", X = ["<h1>Welcome to
411
412
  "\"Plural-Forms: nplurals=3\\n\"",
412
413
  "\"X-Plurals-Order: one, many, other\\n\""
413
414
  ].join("\n"), $ = (e) => e.replace(/\s+/g, "");
414
- function te(e, t) {
415
- if (m.existsSync(h.join(e, Y))) return null;
416
- let n = h.join(e, J);
417
- return !m.existsSync(n) || $(m.readFileSync(n, "utf8")) !== $(X) ? null : {
418
- path: Y,
415
+ function re(e, t) {
416
+ if (g.existsSync(_.join(e, X))) return null;
417
+ let n = _.join(e, Y);
418
+ return !g.existsSync(n) || $(g.readFileSync(n, "utf8")) !== $(Z) ? null : {
419
+ path: X,
419
420
  language: "text",
420
- content: [ee, ...(t === "plain" ? [...Z, Q] : Z).map((e) => [
421
+ content: [ne, ...(t === "plain" ? [...Q, te] : Q).map((e) => [
421
422
  `#: ${e.reference}`,
422
423
  `msgid "${e.msgid}"`,
423
424
  `msgstr "${e.msgstr}"`
@@ -427,33 +428,44 @@ function te(e, t) {
427
428
  }
428
429
  //#endregion
429
430
  //#region src/patterns/enable/i18n/generate.runtime.ts
430
- async function ne(e) {
431
+ function ie(e, t) {
432
+ let n = h.filter((t) => g.existsSync(_.join(e, t)));
433
+ return n.length === 0 ? t : t.map((e) => {
434
+ if (!e.path.endsWith("wuchale.config.js")) return e;
435
+ let t = m(e.content, n);
436
+ return t?.changed ? {
437
+ ...e,
438
+ content: t.source
439
+ } : e;
440
+ });
441
+ }
442
+ async function ae(e) {
431
443
  let r = n(e), i = [], a = (e) => {
432
444
  e && i.push(e);
433
445
  };
434
446
  r.info("Modifying vite.config");
435
- let o = u(e.root, d) ?? h.join(e.root, d[0]);
436
- a(s(o, x(o))), r.info("Adding #locales to package.json imports");
447
+ let o = u(e.root, d) ?? _.join(e.root, d[0]);
448
+ a(s(o, C(o))), r.info("Adding #locales to package.json imports");
437
449
  let c = f(e.root);
438
450
  a(s(c.filePath, c.outcome)), r.info("Modifying hooks.server.ts");
439
- let l = h.join(e.root, "src", "hooks.server.ts");
440
- a(s(l, E(l))), r.info("Modifying hooks.ts");
441
- let g = h.join(e.root, "src", "hooks.ts");
442
- a(s(g, N(g))), r.info("Modifying app.html");
443
- let _ = h.join(e.root, "src", "app.html");
444
- a(s(_, I(_))), r.info("Modifying root +layout.ts");
445
- let v = h.join(e.root, "src", "routes", "+layout.ts");
451
+ let l = _.join(e.root, "src", "hooks.server.ts");
452
+ a(s(l, O(l))), r.info("Modifying hooks.ts");
453
+ let m = _.join(e.root, "src", "hooks.ts");
454
+ a(s(m, ee(m))), r.info("Modifying app.html");
455
+ let h = _.join(e.root, "src", "app.html");
456
+ a(s(h, L(h))), r.info("Modifying root +layout.ts");
457
+ let v = _.join(e.root, "src", "routes", "+layout.ts");
446
458
  a(s(v, p(v))), r.info("Modifying root layout language select");
447
459
  let y = [
448
- h.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
449
- h.join(e.root, "src", "routes", "root-layout.svelte"),
450
- h.join(e.root, "src", "routes", "(public)", "+layout.svelte"),
451
- h.join(e.root, "src", "routes", "+layout.svelte")
452
- ], b = t(e), S = y.find((e) => m.existsSync(e)) ?? (b === "plain" ? y[3] : y[0]);
453
- a(s(S, q(S, b))), r.info("Updating .gitignore");
454
- let C = h.join(e.root, ".gitignore");
455
- a(s(C, R(C)));
456
- let w = te(e.root, b);
460
+ _.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
461
+ _.join(e.root, "src", "routes", "root-layout.svelte"),
462
+ _.join(e.root, "src", "routes", "(public)", "+layout.svelte"),
463
+ _.join(e.root, "src", "routes", "+layout.svelte")
464
+ ], b = t(e), x = y.find((e) => g.existsSync(e)) ?? (b === "plain" ? y[3] : y[0]);
465
+ a(s(x, J(x, b))), r.info("Updating .gitignore");
466
+ let S = _.join(e.root, ".gitignore");
467
+ a(s(S, z(S)));
468
+ let w = re(e.root, b);
457
469
  return w && r.info("Translating the welcome page into Spanish"), {
458
470
  creates: w ? [w] : [],
459
471
  modifies: i,
@@ -466,6 +478,6 @@ async function ne(e) {
466
478
  };
467
479
  }
468
480
  //#endregion
469
- export { ne as generate };
481
+ export { ae as generate, ie as withLibraryTexts };
470
482
 
471
- //# sourceMappingURL=generate.runtime-DdcVnK8J.js.map
483
+ //# sourceMappingURL=generate.runtime-BoYwV0nt.js.map