@velastack/patterns 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/chunks/{collections-Cpjo2OiQ.js → collections-B_DisSfA.js} +2 -2
  2. package/dist/chunks/{collections-Cpjo2OiQ.js.map → collections-B_DisSfA.js.map} +1 -1
  3. package/dist/chunks/{constants-Rq8SCXwH.js → constants-iej3WkEa.js} +3 -3
  4. package/dist/chunks/constants-iej3WkEa.js.map +1 -0
  5. package/dist/chunks/{env-vars-Bj41Nccm.js → env-vars-cqQU0ECK.js} +3 -3
  6. package/dist/chunks/{env-vars-Bj41Nccm.js.map → env-vars-cqQU0ECK.js.map} +1 -1
  7. package/dist/chunks/generate-8FS2ROOJ.js +170 -0
  8. package/dist/chunks/generate-8FS2ROOJ.js.map +1 -0
  9. package/dist/chunks/{generate-yi8AP3xH.js → generate-Bm_jOMtF.js} +3 -3
  10. package/dist/chunks/{generate-yi8AP3xH.js.map → generate-Bm_jOMtF.js.map} +1 -1
  11. package/dist/chunks/{generate-dNlBII84.js → generate-CXoQPz7n.js} +2 -2
  12. package/dist/chunks/{generate-dNlBII84.js.map → generate-CXoQPz7n.js.map} +1 -1
  13. package/dist/chunks/{generate-B6Odfk5f.js → generate-Cqwa8kD9.js} +2 -2
  14. package/dist/chunks/{generate-B6Odfk5f.js.map → generate-Cqwa8kD9.js.map} +1 -1
  15. package/dist/chunks/{generate-DjBMRzsB.js → generate-D3mSFPdT.js} +2 -2
  16. package/dist/chunks/{generate-DjBMRzsB.js.map → generate-D3mSFPdT.js.map} +1 -1
  17. package/dist/chunks/{generate-ZIOVLH6Q.js → generate-jx5Iuq5w.js} +53 -50
  18. package/dist/chunks/generate-jx5Iuq5w.js.map +1 -0
  19. package/dist/chunks/{generate.runtime-DlbG-8Xm.js → generate.runtime-B2r11K7S.js} +4 -4
  20. package/dist/chunks/{generate.runtime-DlbG-8Xm.js.map → generate.runtime-B2r11K7S.js.map} +1 -1
  21. package/dist/chunks/{generate.runtime-pMpn0Pbf.js → generate.runtime-B4u9C2YH.js} +9 -9
  22. package/dist/chunks/{generate.runtime-pMpn0Pbf.js.map → generate.runtime-B4u9C2YH.js.map} +1 -1
  23. package/dist/chunks/{generate.runtime-DetYynf4.js → generate.runtime-BRCzUO94.js} +3 -3
  24. package/dist/chunks/{generate.runtime-DetYynf4.js.map → generate.runtime-BRCzUO94.js.map} +1 -1
  25. package/dist/chunks/{generate.runtime-CcPCAEV0.js → generate.runtime-BVavIXtX.js} +3 -3
  26. package/dist/chunks/{generate.runtime-CcPCAEV0.js.map → generate.runtime-BVavIXtX.js.map} +1 -1
  27. package/dist/chunks/{generate.runtime-BdHv7Jp1.js → generate.runtime-Bh9Z2cRN.js} +2 -2
  28. package/dist/chunks/{generate.runtime-BdHv7Jp1.js.map → generate.runtime-Bh9Z2cRN.js.map} +1 -1
  29. package/dist/chunks/{generate.runtime-D-qtaVdq.js → generate.runtime-BxDUtkpT.js} +12 -12
  30. package/dist/chunks/{generate.runtime-D-qtaVdq.js.map → generate.runtime-BxDUtkpT.js.map} +1 -1
  31. package/dist/chunks/{generate.runtime-BYfyZHhs.js → generate.runtime-BxUGDXIK.js} +4 -4
  32. package/dist/chunks/{generate.runtime-BYfyZHhs.js.map → generate.runtime-BxUGDXIK.js.map} +1 -1
  33. package/dist/chunks/{generate.runtime-DRRyPa-e.js → generate.runtime-CHb4znYx.js} +66 -66
  34. package/dist/chunks/{generate.runtime-DRRyPa-e.js.map → generate.runtime-CHb4znYx.js.map} +1 -1
  35. package/dist/chunks/{generate.runtime-DBBtYTAa.js → generate.runtime-CRhD98rs.js} +3 -3
  36. package/dist/chunks/{generate.runtime-DBBtYTAa.js.map → generate.runtime-CRhD98rs.js.map} +1 -1
  37. package/dist/chunks/{generate.runtime-Bdpu4rX0.js → generate.runtime-CWnIiXwV.js} +2 -2
  38. package/dist/chunks/{generate.runtime-Bdpu4rX0.js.map → generate.runtime-CWnIiXwV.js.map} +1 -1
  39. package/dist/chunks/{generate.runtime-b2RtuPy4.js → generate.runtime-CYBs0JgY.js} +3 -3
  40. package/dist/chunks/{generate.runtime-b2RtuPy4.js.map → generate.runtime-CYBs0JgY.js.map} +1 -1
  41. package/dist/chunks/{generate.runtime-BXZDKLbA.js → generate.runtime-CkmledBw.js} +2 -2
  42. package/dist/chunks/{generate.runtime-BXZDKLbA.js.map → generate.runtime-CkmledBw.js.map} +1 -1
  43. package/dist/chunks/{generate.runtime-NaSIZlP5.js → generate.runtime-CyGR8VTx.js} +2 -2
  44. package/dist/chunks/{generate.runtime-NaSIZlP5.js.map → generate.runtime-CyGR8VTx.js.map} +1 -1
  45. package/dist/chunks/{generate.runtime-DjCzW3zU.js → generate.runtime-DCqf7nYM.js} +2 -2
  46. package/dist/chunks/{generate.runtime-DjCzW3zU.js.map → generate.runtime-DCqf7nYM.js.map} +1 -1
  47. package/dist/chunks/{generate.runtime-C7s1Mx5L.js → generate.runtime-DUo-pLRr.js} +6 -6
  48. package/dist/chunks/{generate.runtime-C7s1Mx5L.js.map → generate.runtime-DUo-pLRr.js.map} +1 -1
  49. package/dist/chunks/{generate.runtime-B4QoBn5v.js → generate.runtime-DY5vQ3aZ.js} +6 -6
  50. package/dist/chunks/{generate.runtime-B4QoBn5v.js.map → generate.runtime-DY5vQ3aZ.js.map} +1 -1
  51. package/dist/chunks/{generate.runtime-CCV4O6_I.js → generate.runtime-DYdkrHJ1.js} +70 -70
  52. package/dist/chunks/{generate.runtime-CCV4O6_I.js.map → generate.runtime-DYdkrHJ1.js.map} +1 -1
  53. package/dist/chunks/{generate.runtime-utFLS6Jz.js → generate.runtime-DdcVnK8J.js} +2 -2
  54. package/dist/chunks/{generate.runtime-utFLS6Jz.js.map → generate.runtime-DdcVnK8J.js.map} +1 -1
  55. package/dist/chunks/{generate.runtime-CV4soy2n.js → generate.runtime-DeniHg8L.js} +47 -47
  56. package/dist/chunks/{generate.runtime-CV4soy2n.js.map → generate.runtime-DeniHg8L.js.map} +1 -1
  57. package/dist/chunks/{generate.runtime-BavEh01F.js → generate.runtime-Dmob2wFf.js} +3 -3
  58. package/dist/chunks/{generate.runtime-BavEh01F.js.map → generate.runtime-Dmob2wFf.js.map} +1 -1
  59. package/dist/chunks/{generate.runtime-CWgZhxQt.js → generate.runtime-Du4uf98c.js} +2 -2
  60. package/dist/chunks/{generate.runtime-CWgZhxQt.js.map → generate.runtime-Du4uf98c.js.map} +1 -1
  61. package/dist/chunks/{generate.runtime-MjWwR2Bd.js → generate.runtime-Dug2UIhV.js} +3 -3
  62. package/dist/chunks/{generate.runtime-MjWwR2Bd.js.map → generate.runtime-Dug2UIhV.js.map} +1 -1
  63. package/dist/chunks/{generate.runtime-QbmCPT42.js → generate.runtime-FGYc365Q.js} +15 -15
  64. package/dist/chunks/{generate.runtime-QbmCPT42.js.map → generate.runtime-FGYc365Q.js.map} +1 -1
  65. package/dist/chunks/{generate.runtime-DaRVyiSg.js → generate.runtime-N1KtAG8C.js} +116 -97
  66. package/dist/chunks/generate.runtime-N1KtAG8C.js.map +1 -0
  67. package/dist/chunks/{generate.runtime-DmsOEsJV.js → generate.runtime-_c7daMAw.js} +3 -3
  68. package/dist/chunks/{generate.runtime-DmsOEsJV.js.map → generate.runtime-_c7daMAw.js.map} +1 -1
  69. package/dist/chunks/{generate.runtime-azOvp6tl.js → generate.runtime-aN5QWygO.js} +6 -6
  70. package/dist/chunks/{generate.runtime-azOvp6tl.js.map → generate.runtime-aN5QWygO.js.map} +1 -1
  71. package/dist/chunks/{generate.runtime-OEgsdWRP.js → generate.runtime-bpH3DB0t.js} +2 -2
  72. package/dist/chunks/{generate.runtime-OEgsdWRP.js.map → generate.runtime-bpH3DB0t.js.map} +1 -1
  73. package/dist/chunks/{generate.runtime-BdmoAVJK.js → generate.runtime-gFr2Gsjz.js} +3 -3
  74. package/dist/chunks/{generate.runtime-BdmoAVJK.js.map → generate.runtime-gFr2Gsjz.js.map} +1 -1
  75. package/dist/chunks/{generate.runtime-CSUnP0l-.js → generate.runtime-kpqW3dVO.js} +26 -26
  76. package/dist/chunks/{generate.runtime-CSUnP0l-.js.map → generate.runtime-kpqW3dVO.js.map} +1 -1
  77. package/dist/chunks/{generate.runtime-BKTkVCEm.js → generate.runtime-wGRE1zwZ.js} +3 -3
  78. package/dist/chunks/{generate.runtime-BKTkVCEm.js.map → generate.runtime-wGRE1zwZ.js.map} +1 -1
  79. package/dist/chunks/{generate.runtime-BKINIJ2c.js → generate.runtime-wziCW3ct.js} +69 -69
  80. package/dist/chunks/{generate.runtime-BKINIJ2c.js.map → generate.runtime-wziCW3ct.js.map} +1 -1
  81. package/dist/chunks/{generate.runtime-BcgjZJug.js → generate.runtime-x-o4LS8d.js} +2 -2
  82. package/dist/chunks/{generate.runtime-BcgjZJug.js.map → generate.runtime-x-o4LS8d.js.map} +1 -1
  83. package/dist/chunks/{modify-file-Bbhyfiy_.js → modify-file-289rStJ2.js} +2 -2
  84. package/dist/chunks/{modify-file-Bbhyfiy_.js.map → modify-file-289rStJ2.js.map} +1 -1
  85. package/dist/chunks/{pocketbase-CgwbH1gI.js → pocketbase-B017Cqjq.js} +2 -2
  86. package/dist/chunks/{pocketbase-CgwbH1gI.js.map → pocketbase-B017Cqjq.js.map} +1 -1
  87. package/dist/chunks/{providers-DwbwccSW.js → providers-CN5J5_fY.js} +2 -2
  88. package/dist/chunks/{providers-DwbwccSW.js.map → providers-CN5J5_fY.js.map} +1 -1
  89. package/dist/chunks/{shared-D5GOS97l.js → shared-BPlAVf-T.js} +2 -2
  90. package/dist/chunks/{shared-D5GOS97l.js.map → shared-BPlAVf-T.js.map} +1 -1
  91. package/dist/chunks/site-DkU1-VRq.js +108 -0
  92. package/dist/chunks/site-DkU1-VRq.js.map +1 -0
  93. package/dist/chunks/{table-core-DhDqT03G.js → table-core-vXEjJDYP.js} +2 -2
  94. package/dist/chunks/{table-core-DhDqT03G.js.map → table-core-vXEjJDYP.js.map} +1 -1
  95. package/dist/chunks/{test-setup-DZoyF8Ak.js → test-setup-CAfgVlwc.js} +3 -3
  96. package/dist/chunks/{test-setup-DZoyF8Ak.js.map → test-setup-CAfgVlwc.js.map} +1 -1
  97. package/dist/chunks/{ui-BuocThuh.js → ui-CTdsenEv.js} +3 -3
  98. package/dist/chunks/{ui-BuocThuh.js.map → ui-CTdsenEv.js.map} +1 -1
  99. package/dist/chunks/{whatsapp-CguKGTtw.js → whatsapp-5qJ_xCV1.js} +2 -2
  100. package/dist/chunks/{whatsapp-CguKGTtw.js.map → whatsapp-5qJ_xCV1.js.map} +1 -1
  101. package/dist/chunks/{write-result-Cq-9A7Zy.js → write-result-0HYIr5a6.js} +4 -4
  102. package/dist/chunks/{write-result-Cq-9A7Zy.js.map → write-result-0HYIr5a6.js.map} +1 -1
  103. package/dist/index.js +1924 -1886
  104. package/dist/index.js.map +1 -1
  105. package/package.json +1 -1
  106. package/dist/chunks/constants-Rq8SCXwH.js.map +0 -1
  107. package/dist/chunks/generate-BClgUH4J.js +0 -137
  108. package/dist/chunks/generate-BClgUH4J.js.map +0 -1
  109. package/dist/chunks/generate-ZIOVLH6Q.js.map +0 -1
  110. package/dist/chunks/generate.runtime-DaRVyiSg.js.map +0 -1
  111. package/dist/chunks/site-lj0CDdQ1.js +0 -55
  112. package/dist/chunks/site-lj0CDdQ1.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"generate-DjBMRzsB.js","names":["changeCase.kebabCase","__import_glob__0_0_","__import_glob__0_1_","__import_glob__0_2_","__import_glob__1_0_","__import_glob__1_1_","__import_glob__2_0_","__import_glob__3_0_","__import_glob__3_1_","__import_glob__3_2_","InvalidArgumentError","ZOD","resolveProvider","providerEnvEdits","providerCreates","resolveUi","SPLIT_LOWER_UPPER_RE","SPLIT_UPPER_UPPER_RE","SPLIT_SEPARATE_NUMBER_RE","DEFAULT_STRIP_REGEXP","SPLIT_REPLACE_VALUE","DEFAULT_PREFIX_SUFFIX_CHARACTERS","split","result","value","start","end","splitSeparateNumbers","words","i","word","match","offset","noCase","prefix","suffix","splitPrefixSuffix","input","options","lowerFactory","camelCase","lower","upper","upperFactory","transform","capitalCaseTransformFactory","pascalCaseTransformFactory","index","pascalCase","capitalCase","kebabCase","snakeCase","locale","char0","splitFn","prefixCharacters","suffixCharacters","prefixIndex","suffixIndex","char","ROUTES_ROOT","DYNAMIC_PARAM_RE","VALID_SEGMENT_RE","defaultGroup","groups","routeGroups","features","routeFileBase","group","route","defaultRouteSegment","kind","model","stripRouteGroups","filePath","segment","extractDynamicParams","params","validateRouteInput","segments","hasRouteGroup","parseRoute","routeInput","fileBase","scaffoldFilePaths","scaffoldUrls","_page_default$1","_server_default$1","server_test_default$1","_server_default","server_test_default","_page_default","ai_default$2","ai_default$1","ai_default","PROVIDERS","PACKAGES","PROVIDER_PACKAGES","META","DEMO_DIR","demoDir","envEditsFor","provider","supplied","createsRaw","createsAppModeRaw","variantsRaw","providersRaw","generate","ui","serverTests","files","add","file","list","composeCreates","filesFromGlob","target","a","b"],"sources":["../../node_modules/change-case/dist/index.js","../../src/parse/route.ts","../../src/patterns/enable/ai/generate.ts"],"sourcesContent":["// Regexps involved with splitting words in various case formats.\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value) {\n let result = value.trim();\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n let start = 0;\n let end = result.length;\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\")\n start++;\n if (start === end)\n return [];\n while (result.charAt(end - 1) === \"\\0\")\n end--;\n return result.slice(start, end).split(/\\0/g);\n}\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix);\n}\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input, options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix);\n}\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input, options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input, options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input, options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input, options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input, options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\nfunction lowerFactory(locale) {\n return locale === false\n ? (input) => input.toLowerCase()\n : (input) => input.toLocaleLowerCase(locale);\n}\nfunction upperFactory(locale) {\n return locale === false\n ? (input) => input.toUpperCase()\n : (input) => input.toLocaleUpperCase(locale);\n}\nfunction capitalCaseTransformFactory(lower, upper) {\n return (word) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\nfunction pascalCaseTransformFactory(lower, upper) {\n return (word, index) => {\n const char0 = word[0];\n const initial = index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\nfunction splitPrefixSuffix(input, options = {}) {\n const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters.includes(char))\n break;\n prefixIndex++;\n }\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters.includes(char))\n break;\n suffixIndex = index;\n }\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n//# sourceMappingURL=index.js.map","import * as changeCase from \"change-case\";\nimport { APP_DIR, PUBLIC_DIR } from \"../core/constants\";\nimport { InvalidArgumentError } from \"../core/errors\";\nimport type { Options } from \"../core/types\";\nimport type {\n Model,\n RouteInfo,\n RouteKind,\n ScaffoldFilePaths,\n ScaffoldUrls,\n} from \"./types\";\n\nconst ROUTES_ROOT = \"src/routes\";\nconst DYNAMIC_PARAM_RE = /\\[([^\\]]+)\\]/g;\nconst VALID_SEGMENT_RE = /^[a-zA-Z0-9_\\-[\\]()]+$/;\n\ntype RouteOptions = Pick<Options, \"features\" | \"routeGroups\">;\n\n/**\n * The group a route lands in when none is given, or null for a project that\n * has no such group. Without `routeGroups` this is the vela layout.\n */\nexport function defaultGroup({\n features,\n routeGroups,\n}: RouteOptions): string | null {\n const groups = routeGroups ?? { public: PUBLIC_DIR, app: APP_DIR };\n return features.auth ? (groups.app ?? groups.public) : groups.public;\n}\n\nfunction routeFileBase(group: string | null, route: string): string {\n return [ROUTES_ROOT, group, route].filter(Boolean).join(\"/\");\n}\n\nfunction defaultRouteSegment(model: Model, kind: RouteKind): string {\n return kind === \"scaffold\"\n ? changeCase.kebabCase(model.pluralDisplayName)\n : changeCase.kebabCase(model.displayName);\n}\n\nfunction stripRouteGroups(filePath: string): string {\n const withoutRoot = filePath.startsWith(`${ROUTES_ROOT}/`)\n ? filePath.slice(ROUTES_ROOT.length + 1)\n : filePath;\n const segments = withoutRoot.split(\"/\").filter((segment) => {\n return !(segment.startsWith(\"(\") && segment.endsWith(\")\"));\n });\n return `/${segments.join(\"/\")}`;\n}\n\nfunction extractDynamicParams(filePath: string): string[] {\n const params: string[] = [];\n for (const match of filePath.matchAll(DYNAMIC_PARAM_RE)) {\n params.push(match[1]);\n }\n return params;\n}\n\nfunction validateRouteInput(input: string): void {\n if (input.startsWith(\"/\")) {\n throw new InvalidArgumentError(\n `Route must not start with \"/\". Got: \"${input}\"`,\n );\n }\n if (input.startsWith(`${ROUTES_ROOT}/`) || input === ROUTES_ROOT) {\n throw new InvalidArgumentError(\n `Route must not start with \"${ROUTES_ROOT}/\" — paths are rooted there automatically. Got: \"${input}\"`,\n );\n }\n const segments = input.split(\"/\");\n for (const segment of segments) {\n if (segment.length === 0) {\n throw new InvalidArgumentError(\n `Route must not contain empty segments. Got: \"${input}\"`,\n );\n }\n if (segment === \".\" || segment === \"..\") {\n throw new InvalidArgumentError(\n `Route must not contain \".\" or \"..\" segments. Got: \"${input}\"`,\n );\n }\n if (segment.startsWith(\"_\")) {\n throw new InvalidArgumentError(\n `Route segments must not start with underscore. Got: \"${segment}\"`,\n );\n }\n if (!VALID_SEGMENT_RE.test(segment)) {\n throw new InvalidArgumentError(\n `Route segment \"${segment}\" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`,\n );\n }\n }\n}\n\nfunction hasRouteGroup(input: string): boolean {\n return input\n .split(\"/\")\n .some((segment) => segment.startsWith(\"(\") && segment.endsWith(\")\"));\n}\n\nexport function parseRoute(\n routeInput: string | undefined,\n model: Model,\n options: RouteOptions,\n kind: RouteKind,\n): RouteInfo {\n if (routeInput === undefined || routeInput === \"\") {\n const segment = defaultRouteSegment(model, kind);\n const fileBase = routeFileBase(defaultGroup(options), segment);\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n }\n\n validateRouteInput(routeInput);\n\n const fileBase = routeFileBase(\n hasRouteGroup(routeInput) ? null : defaultGroup(options),\n routeInput,\n );\n\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n}\n\nexport function scaffoldFilePaths(route: RouteInfo): ScaffoldFilePaths {\n return {\n list: route.fileBase,\n new: `${route.fileBase}/new`,\n show: `${route.fileBase}/[id]`,\n edit: `${route.fileBase}/[id]/edit`,\n };\n}\n\nexport function scaffoldUrls(route: RouteInfo): ScaffoldUrls {\n return {\n list: route.urlBase,\n new: `${route.urlBase}/new`,\n show: `${route.urlBase}/[id]`,\n edit: `${route.urlBase}/[id]/edit`,\n };\n}\n","import type {\n File,\n Options,\n Package,\n Provider,\n Result,\n} from \"../../../core/types\";\nimport type { EnvEdit } from \"../../../runtime/env\";\nimport { ZOD } from \"../../../core/constants\";\nimport { resolveUi } from \"../../../core/field/ui\";\nimport {\n providerCreates,\n providerEnvEdits,\n resolveProvider,\n} from \"../../../core/providers\";\nimport { composeCreates, filesFromGlob } from \"../../../core/util\";\nimport { defaultGroup } from \"../../../parse/route\";\n\n/**\n * The providers in prompt order. Each one's `env` key is what the CLI asks\n * for (without echo), what `generate.runtime.ts` writes to `.env` and\n * declares in `src/env.ts`; the generated `src/lib/server/ai.ts` imports it\n * from `$app/env/private`, and `/api/chat` answers 503 while it is blank.\n */\nexport const PROVIDERS: Provider[] = [\n {\n id: \"gateway\",\n label: \"Vercel AI Gateway\",\n env: [\n {\n key: \"AI_GATEWAY_API_KEY\",\n label: \"Vercel AI Gateway API key\",\n secret: true,\n },\n ],\n },\n {\n id: \"openai\",\n label: \"OpenAI\",\n env: [\n {\n key: \"OPENAI_API_KEY\",\n label: \"OpenAI API key\",\n placeholder: \"sk-...\",\n secret: true,\n },\n ],\n },\n {\n id: \"anthropic\",\n label: \"Anthropic\",\n env: [\n {\n key: \"ANTHROPIC_API_KEY\",\n label: \"Anthropic API key\",\n placeholder: \"sk-ant-...\",\n secret: true,\n },\n ],\n },\n];\n\n/**\n * `ai` carries the gateway provider itself; the others are a package each.\n * zod, a peer of `ai`, is installed alongside but is not listed here: it is\n * not the pattern's to uninstall.\n */\nexport const PACKAGES: Package[] = [\"ai@^7.0.107\", \"@ai-sdk/svelte@^5.0.107\"];\nexport const PROVIDER_PACKAGES: Record<string, Package[]> = {\n openai: [\"@ai-sdk/openai@^4.0.71\"],\n anthropic: [\"@ai-sdk/anthropic@^4.0.58\"],\n};\n\n/** What `resolveProvider` needs; `index.ts` spreads the rest of the metadata. */\nexport const META = { slug: \"enable-ai\", providers: PROVIDERS };\n\n/** Where the demo page is stored; `generate` moves it to the project's default group. */\nexport const DEMO_DIR = \"src/routes/(public)/ai/\";\n\n/**\n * The demo page's directory: `(public)/ai`, `(app)/ai` behind sign-in when\n * auth is on, or `ai` straight under `src/routes` in a project without groups.\n */\nexport function demoDir(\n options: Pick<Options, \"features\" | \"routeGroups\">,\n): string {\n return [\"src/routes\", defaultGroup(options), \"ai\"].filter(Boolean).join(\"/\");\n}\n\n/** The `.env` lines for a provider, under a `# AI SDK (<Label>)` heading. */\nexport function envEditsFor(\n provider: Provider,\n supplied: Record<string, string> = {},\n): EnvEdit[] {\n return providerEnvEdits(provider, `AI SDK (${provider.label})`, supplied);\n}\n\nconst createsRaw = import.meta.glob<string>(\"./creates/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n// With auth, the endpoint answers only signed-in users: every reply is\n// billed to the project's API key.\nconst createsAppModeRaw = import.meta.glob<string>(\"./creates-app-mode/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n// A plain project gets the demo page in native elements, at the same path.\nconst variantsRaw = import.meta.glob<string>(\"./variants/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst providersRaw = import.meta.glob<string>(\"./providers/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nexport async function generate(options: Options) {\n const provider = resolveProvider(META, options);\n const ui = resolveUi(options);\n const serverTests = options.input.serverTests ?? true;\n\n const files: Record<string, File> = {};\n const add = (list: File[]) => {\n for (const file of list) files[file.path] = file;\n };\n add(\n composeCreates(\n createsRaw,\n \"./creates/\",\n variantsRaw,\n ui === \"plain\" ? \"plain\" : undefined,\n ),\n );\n if (options.features.auth) {\n add(Object.values(filesFromGlob(createsAppModeRaw, \"./creates-app-mode/\")));\n }\n add(providerCreates(providersRaw, provider.id));\n\n const target = `${demoDir(options)}/`;\n const creates = Object.values(files)\n .filter((file) => serverTests || !file.path.endsWith(\"server.test.ts\"))\n .map((file) =>\n file.path.startsWith(DEMO_DIR)\n ? { ...file, path: target + file.path.slice(DEMO_DIR.length) }\n : file,\n )\n .sort((a, b) => a.path.localeCompare(b.path));\n\n return {\n creates,\n modifies: [],\n deletes: [],\n components: ui === \"plain\" ? [] : [\"button\", \"textarea\"],\n // vela's templates already have zod; a project vela did not create may not.\n packages: [...PACKAGES, ZOD, ...(PROVIDER_PACKAGES[provider.id] ?? [])],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;AACA,IAAMgB,IAAuB,0BACvBC,IAAuB,gCAEvBC,IAA2B,yBAE3BC,IAAuB,kBAEvBC,IAAsB,UAEtBC,IAAmC;AAIzC,SAAgBC,EAAM,GAAO;CACzB,IAAIC,IAASC,EAAM,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O,OAAOyE,CAAK,CAAC,CACjC,QAAQ,MAASD,KAAe,CAACG,EAAK,KAAK,SAAS,gBAAgB,CAAC,CAAC,CACtE,KAAK,MACJA,EAAK,KAAK,WAAA,yBAAmB,IACzB;GAAE,GAAGA;GAAM,MAAMI,IAASJ,EAAK,KAAK,MAAM,EAAe;EAAE,IAC3DA,CACN,CAAC,CACA,MAAM,GAAG,MAAMK,EAAE,KAAK,cAAcC,EAAE,IAAI,CAG3C;EACA,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAYV,MAAO,UAAU,CAAC,IAAI,CAAC,UAAU,UAAU;EAEvD,UAAU;GAAC,GAAGb;GAAUrF;GAAK,GAAIsF,EAAkBK,EAAS,OAAO,CAAC;EAAE;EACtE,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
1
+ {"version":3,"file":"generate-D3mSFPdT.js","names":["changeCase.kebabCase","__import_glob__0_0_","__import_glob__0_1_","__import_glob__0_2_","__import_glob__1_0_","__import_glob__1_1_","__import_glob__2_0_","__import_glob__3_0_","__import_glob__3_1_","__import_glob__3_2_","InvalidArgumentError","ZOD","resolveProvider","providerEnvEdits","providerCreates","resolveUi","SPLIT_LOWER_UPPER_RE","SPLIT_UPPER_UPPER_RE","SPLIT_SEPARATE_NUMBER_RE","DEFAULT_STRIP_REGEXP","SPLIT_REPLACE_VALUE","DEFAULT_PREFIX_SUFFIX_CHARACTERS","split","result","value","start","end","splitSeparateNumbers","words","i","word","match","offset","noCase","prefix","suffix","splitPrefixSuffix","input","options","lowerFactory","camelCase","lower","upper","upperFactory","transform","capitalCaseTransformFactory","pascalCaseTransformFactory","index","pascalCase","capitalCase","kebabCase","snakeCase","locale","char0","splitFn","prefixCharacters","suffixCharacters","prefixIndex","suffixIndex","char","ROUTES_ROOT","DYNAMIC_PARAM_RE","VALID_SEGMENT_RE","defaultGroup","groups","routeGroups","features","routeFileBase","group","route","defaultRouteSegment","kind","model","stripRouteGroups","filePath","segment","extractDynamicParams","params","validateRouteInput","segments","hasRouteGroup","parseRoute","routeInput","fileBase","scaffoldFilePaths","scaffoldUrls","_page_default$1","_server_default$1","server_test_default$1","_server_default","server_test_default","_page_default","ai_default$2","ai_default$1","ai_default","PROVIDERS","PACKAGES","PROVIDER_PACKAGES","META","DEMO_DIR","demoDir","envEditsFor","provider","supplied","createsRaw","createsAppModeRaw","variantsRaw","providersRaw","generate","ui","serverTests","files","add","file","list","composeCreates","filesFromGlob","target","a","b"],"sources":["../../node_modules/change-case/dist/index.js","../../src/parse/route.ts","../../src/patterns/enable/ai/generate.ts"],"sourcesContent":["// Regexps involved with splitting words in various case formats.\nconst SPLIT_LOWER_UPPER_RE = /([\\p{Ll}\\d])(\\p{Lu})/gu;\nconst SPLIT_UPPER_UPPER_RE = /(\\p{Lu})([\\p{Lu}][\\p{Ll}])/gu;\n// Used to iterate over the initial split result and separate numbers.\nconst SPLIT_SEPARATE_NUMBER_RE = /(\\d)\\p{Ll}|(\\p{L})\\d/u;\n// Regexp involved with stripping non-word characters from the result.\nconst DEFAULT_STRIP_REGEXP = /[^\\p{L}\\d]+/giu;\n// The replacement value for splits.\nconst SPLIT_REPLACE_VALUE = \"$1\\0$2\";\n// The default characters to keep after transforming case.\nconst DEFAULT_PREFIX_SUFFIX_CHARACTERS = \"\";\n/**\n * Split any cased input strings into an array of words.\n */\nexport function split(value) {\n let result = value.trim();\n result = result\n .replace(SPLIT_LOWER_UPPER_RE, SPLIT_REPLACE_VALUE)\n .replace(SPLIT_UPPER_UPPER_RE, SPLIT_REPLACE_VALUE);\n result = result.replace(DEFAULT_STRIP_REGEXP, \"\\0\");\n let start = 0;\n let end = result.length;\n // Trim the delimiter from around the output string.\n while (result.charAt(start) === \"\\0\")\n start++;\n if (start === end)\n return [];\n while (result.charAt(end - 1) === \"\\0\")\n end--;\n return result.slice(start, end).split(/\\0/g);\n}\n/**\n * Split the input string into an array of words, separating numbers.\n */\nexport function splitSeparateNumbers(value) {\n const words = split(value);\n for (let i = 0; i < words.length; i++) {\n const word = words[i];\n const match = SPLIT_SEPARATE_NUMBER_RE.exec(word);\n if (match) {\n const offset = match.index + (match[1] ?? match[2]).length;\n words.splice(i, 1, word.slice(0, offset), word.slice(offset));\n }\n }\n return words;\n}\n/**\n * Convert a string to space separated lower case (`foo bar`).\n */\nexport function noCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(lowerFactory(options?.locale)).join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to camel case (`fooBar`).\n */\nexport function camelCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return lower(word);\n return transform(word, index);\n })\n .join(options?.delimiter ?? \"\") +\n suffix);\n}\n/**\n * Convert a string to pascal case (`FooBar`).\n */\nexport function pascalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = options?.mergeAmbiguousCharacters\n ? capitalCaseTransformFactory(lower, upper)\n : pascalCaseTransformFactory(lower, upper);\n return prefix + words.map(transform).join(options?.delimiter ?? \"\") + suffix;\n}\n/**\n * Convert a string to pascal snake case (`Foo_Bar`).\n */\nexport function pascalSnakeCase(input, options) {\n return capitalCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to capital case (`Foo Bar`).\n */\nexport function capitalCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n return (prefix +\n words\n .map(capitalCaseTransformFactory(lower, upper))\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to constant case (`FOO_BAR`).\n */\nexport function constantCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n return (prefix +\n words.map(upperFactory(options?.locale)).join(options?.delimiter ?? \"_\") +\n suffix);\n}\n/**\n * Convert a string to dot case (`foo.bar`).\n */\nexport function dotCase(input, options) {\n return noCase(input, { delimiter: \".\", ...options });\n}\n/**\n * Convert a string to kebab case (`foo-bar`).\n */\nexport function kebabCase(input, options) {\n return noCase(input, { delimiter: \"-\", ...options });\n}\n/**\n * Convert a string to path case (`foo/bar`).\n */\nexport function pathCase(input, options) {\n return noCase(input, { delimiter: \"/\", ...options });\n}\n/**\n * Convert a string to path case (`Foo bar`).\n */\nexport function sentenceCase(input, options) {\n const [prefix, words, suffix] = splitPrefixSuffix(input, options);\n const lower = lowerFactory(options?.locale);\n const upper = upperFactory(options?.locale);\n const transform = capitalCaseTransformFactory(lower, upper);\n return (prefix +\n words\n .map((word, index) => {\n if (index === 0)\n return transform(word);\n return lower(word);\n })\n .join(options?.delimiter ?? \" \") +\n suffix);\n}\n/**\n * Convert a string to snake case (`foo_bar`).\n */\nexport function snakeCase(input, options) {\n return noCase(input, { delimiter: \"_\", ...options });\n}\n/**\n * Convert a string to header case (`Foo-Bar`).\n */\nexport function trainCase(input, options) {\n return capitalCase(input, { delimiter: \"-\", ...options });\n}\nfunction lowerFactory(locale) {\n return locale === false\n ? (input) => input.toLowerCase()\n : (input) => input.toLocaleLowerCase(locale);\n}\nfunction upperFactory(locale) {\n return locale === false\n ? (input) => input.toUpperCase()\n : (input) => input.toLocaleUpperCase(locale);\n}\nfunction capitalCaseTransformFactory(lower, upper) {\n return (word) => `${upper(word[0])}${lower(word.slice(1))}`;\n}\nfunction pascalCaseTransformFactory(lower, upper) {\n return (word, index) => {\n const char0 = word[0];\n const initial = index > 0 && char0 >= \"0\" && char0 <= \"9\" ? \"_\" + char0 : upper(char0);\n return initial + lower(word.slice(1));\n };\n}\nfunction splitPrefixSuffix(input, options = {}) {\n const splitFn = options.split ?? (options.separateNumbers ? splitSeparateNumbers : split);\n const prefixCharacters = options.prefixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n const suffixCharacters = options.suffixCharacters ?? DEFAULT_PREFIX_SUFFIX_CHARACTERS;\n let prefixIndex = 0;\n let suffixIndex = input.length;\n while (prefixIndex < input.length) {\n const char = input.charAt(prefixIndex);\n if (!prefixCharacters.includes(char))\n break;\n prefixIndex++;\n }\n while (suffixIndex > prefixIndex) {\n const index = suffixIndex - 1;\n const char = input.charAt(index);\n if (!suffixCharacters.includes(char))\n break;\n suffixIndex = index;\n }\n return [\n input.slice(0, prefixIndex),\n splitFn(input.slice(prefixIndex, suffixIndex)),\n input.slice(suffixIndex),\n ];\n}\n//# sourceMappingURL=index.js.map","import * as changeCase from \"change-case\";\nimport { APP_DIR, PUBLIC_DIR } from \"../core/constants\";\nimport { InvalidArgumentError } from \"../core/errors\";\nimport type { Options } from \"../core/types\";\nimport type {\n Model,\n RouteInfo,\n RouteKind,\n ScaffoldFilePaths,\n ScaffoldUrls,\n} from \"./types\";\n\nconst ROUTES_ROOT = \"src/routes\";\nconst DYNAMIC_PARAM_RE = /\\[([^\\]]+)\\]/g;\nconst VALID_SEGMENT_RE = /^[a-zA-Z0-9_\\-[\\]()]+$/;\n\ntype RouteOptions = Pick<Options, \"features\" | \"routeGroups\">;\n\n/**\n * The group a route lands in when none is given, or null for a project that\n * has no such group. Without `routeGroups` this is the vela layout.\n */\nexport function defaultGroup({\n features,\n routeGroups,\n}: RouteOptions): string | null {\n const groups = routeGroups ?? { public: PUBLIC_DIR, app: APP_DIR };\n return features.auth ? (groups.app ?? groups.public) : groups.public;\n}\n\nfunction routeFileBase(group: string | null, route: string): string {\n return [ROUTES_ROOT, group, route].filter(Boolean).join(\"/\");\n}\n\nfunction defaultRouteSegment(model: Model, kind: RouteKind): string {\n return kind === \"scaffold\"\n ? changeCase.kebabCase(model.pluralDisplayName)\n : changeCase.kebabCase(model.displayName);\n}\n\nfunction stripRouteGroups(filePath: string): string {\n const withoutRoot = filePath.startsWith(`${ROUTES_ROOT}/`)\n ? filePath.slice(ROUTES_ROOT.length + 1)\n : filePath;\n const segments = withoutRoot.split(\"/\").filter((segment) => {\n return !(segment.startsWith(\"(\") && segment.endsWith(\")\"));\n });\n return `/${segments.join(\"/\")}`;\n}\n\nfunction extractDynamicParams(filePath: string): string[] {\n const params: string[] = [];\n for (const match of filePath.matchAll(DYNAMIC_PARAM_RE)) {\n params.push(match[1]);\n }\n return params;\n}\n\nfunction validateRouteInput(input: string): void {\n if (input.startsWith(\"/\")) {\n throw new InvalidArgumentError(\n `Route must not start with \"/\". Got: \"${input}\"`,\n );\n }\n if (input.startsWith(`${ROUTES_ROOT}/`) || input === ROUTES_ROOT) {\n throw new InvalidArgumentError(\n `Route must not start with \"${ROUTES_ROOT}/\" — paths are rooted there automatically. Got: \"${input}\"`,\n );\n }\n const segments = input.split(\"/\");\n for (const segment of segments) {\n if (segment.length === 0) {\n throw new InvalidArgumentError(\n `Route must not contain empty segments. Got: \"${input}\"`,\n );\n }\n if (segment === \".\" || segment === \"..\") {\n throw new InvalidArgumentError(\n `Route must not contain \".\" or \"..\" segments. Got: \"${input}\"`,\n );\n }\n if (segment.startsWith(\"_\")) {\n throw new InvalidArgumentError(\n `Route segments must not start with underscore. Got: \"${segment}\"`,\n );\n }\n if (!VALID_SEGMENT_RE.test(segment)) {\n throw new InvalidArgumentError(\n `Route segment \"${segment}\" contains invalid characters. Allowed: letters, digits, underscore, dash, brackets, parentheses.`,\n );\n }\n }\n}\n\nfunction hasRouteGroup(input: string): boolean {\n return input\n .split(\"/\")\n .some((segment) => segment.startsWith(\"(\") && segment.endsWith(\")\"));\n}\n\nexport function parseRoute(\n routeInput: string | undefined,\n model: Model,\n options: RouteOptions,\n kind: RouteKind,\n): RouteInfo {\n if (routeInput === undefined || routeInput === \"\") {\n const segment = defaultRouteSegment(model, kind);\n const fileBase = routeFileBase(defaultGroup(options), segment);\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n }\n\n validateRouteInput(routeInput);\n\n const fileBase = routeFileBase(\n hasRouteGroup(routeInput) ? null : defaultGroup(options),\n routeInput,\n );\n\n return {\n fileBase,\n urlBase: stripRouteGroups(fileBase),\n dynamicParams: extractDynamicParams(fileBase),\n };\n}\n\nexport function scaffoldFilePaths(route: RouteInfo): ScaffoldFilePaths {\n return {\n list: route.fileBase,\n new: `${route.fileBase}/new`,\n show: `${route.fileBase}/[id]`,\n edit: `${route.fileBase}/[id]/edit`,\n };\n}\n\nexport function scaffoldUrls(route: RouteInfo): ScaffoldUrls {\n return {\n list: route.urlBase,\n new: `${route.urlBase}/new`,\n show: `${route.urlBase}/[id]`,\n edit: `${route.urlBase}/[id]/edit`,\n };\n}\n","import type {\n File,\n Options,\n Package,\n Provider,\n Result,\n} from \"../../../core/types\";\nimport type { EnvEdit } from \"../../../runtime/env\";\nimport { ZOD } from \"../../../core/constants\";\nimport { resolveUi } from \"../../../core/field/ui\";\nimport {\n providerCreates,\n providerEnvEdits,\n resolveProvider,\n} from \"../../../core/providers\";\nimport { composeCreates, filesFromGlob } from \"../../../core/util\";\nimport { defaultGroup } from \"../../../parse/route\";\n\n/**\n * The providers in prompt order. Each one's `env` key is what the CLI asks\n * for (without echo), what `generate.runtime.ts` writes to `.env` and\n * declares in `src/env.ts`; the generated `src/lib/server/ai.ts` imports it\n * from `$app/env/private`, and `/api/chat` answers 503 while it is blank.\n */\nexport const PROVIDERS: Provider[] = [\n {\n id: \"gateway\",\n label: \"Vercel AI Gateway\",\n env: [\n {\n key: \"AI_GATEWAY_API_KEY\",\n label: \"Vercel AI Gateway API key\",\n secret: true,\n },\n ],\n },\n {\n id: \"openai\",\n label: \"OpenAI\",\n env: [\n {\n key: \"OPENAI_API_KEY\",\n label: \"OpenAI API key\",\n placeholder: \"sk-...\",\n secret: true,\n },\n ],\n },\n {\n id: \"anthropic\",\n label: \"Anthropic\",\n env: [\n {\n key: \"ANTHROPIC_API_KEY\",\n label: \"Anthropic API key\",\n placeholder: \"sk-ant-...\",\n secret: true,\n },\n ],\n },\n];\n\n/**\n * `ai` carries the gateway provider itself; the others are a package each.\n * zod, a peer of `ai`, is installed alongside but is not listed here: it is\n * not the pattern's to uninstall.\n */\nexport const PACKAGES: Package[] = [\"ai@^7.0.107\", \"@ai-sdk/svelte@^5.0.107\"];\nexport const PROVIDER_PACKAGES: Record<string, Package[]> = {\n openai: [\"@ai-sdk/openai@^4.0.71\"],\n anthropic: [\"@ai-sdk/anthropic@^4.0.58\"],\n};\n\n/** What `resolveProvider` needs; `index.ts` spreads the rest of the metadata. */\nexport const META = { slug: \"enable-ai\", providers: PROVIDERS };\n\n/** Where the demo page is stored; `generate` moves it to the project's default group. */\nexport const DEMO_DIR = \"src/routes/(public)/ai/\";\n\n/**\n * The demo page's directory: `(public)/ai`, `(app)/ai` behind sign-in when\n * auth is on, or `ai` straight under `src/routes` in a project without groups.\n */\nexport function demoDir(\n options: Pick<Options, \"features\" | \"routeGroups\">,\n): string {\n return [\"src/routes\", defaultGroup(options), \"ai\"].filter(Boolean).join(\"/\");\n}\n\n/** The `.env` lines for a provider, under a `# AI SDK (<Label>)` heading. */\nexport function envEditsFor(\n provider: Provider,\n supplied: Record<string, string> = {},\n): EnvEdit[] {\n return providerEnvEdits(provider, `AI SDK (${provider.label})`, supplied);\n}\n\nconst createsRaw = import.meta.glob<string>(\"./creates/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n// With auth, the endpoint answers only signed-in users: every reply is\n// billed to the project's API key.\nconst createsAppModeRaw = import.meta.glob<string>(\"./creates-app-mode/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n// A plain project gets the demo page in native elements, at the same path.\nconst variantsRaw = import.meta.glob<string>(\"./variants/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst providersRaw = import.meta.glob<string>(\"./providers/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nexport async function generate(options: Options) {\n const provider = resolveProvider(META, options);\n const ui = resolveUi(options);\n const serverTests = options.input.serverTests ?? true;\n\n const files: Record<string, File> = {};\n const add = (list: File[]) => {\n for (const file of list) files[file.path] = file;\n };\n add(\n composeCreates(\n createsRaw,\n \"./creates/\",\n variantsRaw,\n ui === \"plain\" ? \"plain\" : undefined,\n ),\n );\n if (options.features.auth) {\n add(Object.values(filesFromGlob(createsAppModeRaw, \"./creates-app-mode/\")));\n }\n add(providerCreates(providersRaw, provider.id));\n\n const target = `${demoDir(options)}/`;\n const creates = Object.values(files)\n .filter((file) => serverTests || !file.path.endsWith(\"server.test.ts\"))\n .map((file) =>\n file.path.startsWith(DEMO_DIR)\n ? { ...file, path: target + file.path.slice(DEMO_DIR.length) }\n : file,\n )\n .sort((a, b) => a.path.localeCompare(b.path));\n\n return {\n creates,\n modifies: [],\n deletes: [],\n components: ui === \"plain\" ? [] : [\"button\", \"textarea\"],\n // vela's templates already have zod; a project vela did not create may not.\n packages: [...PACKAGES, ZOD, ...(PROVIDER_PACKAGES[provider.id] ?? [])],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;AACA,IAAMgB,IAAuB,0BACvBC,IAAuB,gCAEvBC,IAA2B,yBAE3BC,IAAuB,kBAEvBC,IAAsB,UAEtBC,IAAmC;AAIzC,SAAgBC,EAAM,GAAO;CACzB,IAAIC,IAASC,EAAM,KAAK;CAIxB,AAHA,IAASD,EACJ,QAAQP,GAAsBI,CAAmB,CAAC,CAClD,QAAQH,GAAsBG,CAAmB,GACtD,IAASG,EAAO,QAAQJ,GAAsB,IAAI;CAClD,IAAIM,IAAQ,GACRC,IAAMH,EAAO;CAEjB,OAAOA,EAAO,OAAOE,CAAK,MAAM,OAC5B;CACJ,IAAIA,MAAUC,GACV,OAAO,CAAC;CACZ,OAAOH,EAAO,OAAOG,IAAM,CAAC,MAAM,OAC9B;CACJ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,SAAS,CAAC;EACV,YAAYV,MAAO,UAAU,CAAC,IAAI,CAAC,UAAU,UAAU;EAEvD,UAAU;GAAC,GAAGb;GAAUrF;GAAK,GAAIsF,EAAkBK,EAAS,OAAO,CAAC;EAAE;EACtE,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,55 +1,58 @@
1
1
  import { a as e } from "./util-BLYliuUK.js";
2
2
  import { t } from "./providers-CL9kQ4hp.js";
3
- import { A as n, C as r, D as i, E as a, F as o, I as s, L as c, M as l, N as u, O as d, P as f, R as p, S as m, T as h, _ as g, a as _, b as v, c as y, d as b, f as x, g as S, h as C, j as w, k as T, l as E, m as D, n as O, o as k, p as A, s as j, u as M, v as N, w as P, x as F, y as I } from "./generate-BClgUH4J.js";
4
- import { t as L } from "./stripe-customer-B3tP8gtD.js";
5
- import { n as R, t as z } from "./_page-DoPdZgZv.js";
3
+ import { A as n, B as r, C as i, D as a, E as o, F as s, I as c, L as l, M as u, N as d, O as f, P as p, R as m, S as h, T as g, V as _, _ as v, a as y, b, c as x, d as S, f as C, g as w, h as T, j as E, k as D, l as O, m as k, n as A, o as j, p as M, s as N, u as P, v as F, w as I, x as L, y as R, z } from "./generate-8FS2ROOJ.js";
4
+ import { t as B } from "./stripe-customer-B3tP8gtD.js";
5
+ import { n as V, t as H } from "./_page-DoPdZgZv.js";
6
6
  //#region src/patterns/disable/payments/generate.ts
7
- var B = /* #__PURE__ */ Object.assign({
8
- "../../enable/payments/providers/shopify/src/lib/components/payments/buy-button.svelte": p,
9
- "../../enable/payments/providers/shopify/src/lib/shopify.ts": c,
10
- "../../enable/payments/providers/stripe/src/lib/components/payments/confirm-dialog.svelte": s,
11
- "../../enable/payments/providers/stripe/src/lib/components/payments/payment-button.svelte": o,
12
- "../../enable/payments/providers/stripe/src/lib/components/payments/payment-dialog.svelte": f,
13
- "../../enable/payments/providers/stripe/src/lib/components/payments/stripe-constants.ts": u,
14
- "../../enable/payments/providers/stripe/src/lib/components/payments/stripe-payment-form.svelte": l,
15
- "../../enable/payments/providers/stripe/src/lib/components/payments/use-payment-intent.svelte.ts": w,
16
- "../../enable/payments/providers/stripe/src/lib/components/payments/use-stripe.svelte.ts": n,
17
- "../../enable/payments/providers/stripe/src/lib/stripe.ts": T,
18
- "../../enable/payments/providers/stripe/src/lib/workflows/stripe-event.ts": d,
19
- "../../enable/payments/providers/stripe/src/lib/workflows/sync-stripe-catalog.ts": i,
20
- "../../enable/payments/providers/stripe/src/routes/api/stripe/payment-intent/+server.ts": a,
21
- "../../enable/payments/providers/stripe/src/routes/api/stripe/payment-intent/server.test.ts": h,
22
- "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/+server.ts": P,
23
- "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/handlers/dispatch.ts": r,
24
- "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/handlers/payment-intent/server.test.ts": m,
25
- "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/handlers/payment-intent/succeeded.ts": F,
26
- "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/server.test.ts": v,
27
- "../../enable/payments/providers-app-mode/stripe/src/lib/components/payments/setup-button.svelte": I,
28
- "../../enable/payments/providers-app-mode/stripe/src/lib/components/payments/setup-dialog.svelte": N,
29
- "../../enable/payments/providers-app-mode/stripe/src/lib/server/stripe-customer.ts": L,
30
- "../../enable/payments/providers-app-mode/stripe/src/lib/workflows/link-stripe-customer.ts": g,
31
- "../../enable/payments/providers-app-mode/stripe/src/lib/workflows/sync-stripe-customers.ts": S,
32
- "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+layout.server.ts": C,
33
- "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.server.ts": R,
34
- "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.svelte": z,
35
- "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/README.md": D,
36
- "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/payment-intent/+server.ts": A,
37
- "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/payment-intent/server.test.ts": x,
38
- "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/setup-intent/+server.ts": b,
39
- "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/setup-intent/server.test.ts": M,
40
- "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/dispatch.ts": E,
41
- "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-intent/server.test.ts": y,
42
- "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-intent/succeeded.ts": j,
43
- "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-method/attached.ts": k,
44
- "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-method/server.test.ts": _
45
- }), V = "src/routes/(public)/payment/+page.svelte";
46
- function H(e) {
47
- let t = e.providers?.payments, n = O.filter((e) => e.id === t);
48
- return n.length > 0 ? n : O;
7
+ var U = /* #__PURE__ */ Object.assign({
8
+ "../../enable/payments/providers/shopify/src/lib/components/payments/buy-button.svelte": _,
9
+ "../../enable/payments/providers/shopify/src/lib/shopify.ts": r,
10
+ "../../enable/payments/providers/stripe/src/lib/components/payments/confirm-dialog.svelte": z,
11
+ "../../enable/payments/providers/stripe/src/lib/components/payments/payment-button.svelte": m,
12
+ "../../enable/payments/providers/stripe/src/lib/components/payments/payment-dialog.svelte": l,
13
+ "../../enable/payments/providers/stripe/src/lib/components/payments/stripe-constants.ts": c,
14
+ "../../enable/payments/providers/stripe/src/lib/components/payments/stripe-payment-form.svelte": s,
15
+ "../../enable/payments/providers/stripe/src/lib/components/payments/use-payment-intent.svelte.ts": p,
16
+ "../../enable/payments/providers/stripe/src/lib/components/payments/use-stripe.svelte.ts": d,
17
+ "../../enable/payments/providers/stripe/src/lib/stripe.ts": u,
18
+ "../../enable/payments/providers/stripe/src/lib/workflows/stripe-event.ts": E,
19
+ "../../enable/payments/providers/stripe/src/lib/workflows/sync-stripe-catalog.ts": n,
20
+ "../../enable/payments/providers/stripe/src/routes/api/stripe/payment-intent/+server.ts": D,
21
+ "../../enable/payments/providers/stripe/src/routes/api/stripe/payment-intent/server.test.ts": f,
22
+ "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/+server.ts": a,
23
+ "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/handlers/dispatch.ts": o,
24
+ "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/handlers/payment-intent/server.test.ts": g,
25
+ "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/handlers/payment-intent/succeeded.ts": I,
26
+ "../../enable/payments/providers/stripe/src/routes/webhooks/stripe/server.test.ts": i,
27
+ "../../enable/payments/providers/whatsapp/src/lib/components/payments/customer-fields.svelte": h,
28
+ "../../enable/payments/providers/whatsapp/src/lib/components/payments/order-button.svelte": L,
29
+ "../../enable/payments/providers/whatsapp/src/lib/order.ts": b,
30
+ "../../enable/payments/providers-app-mode/stripe/src/lib/components/payments/setup-button.svelte": R,
31
+ "../../enable/payments/providers-app-mode/stripe/src/lib/components/payments/setup-dialog.svelte": F,
32
+ "../../enable/payments/providers-app-mode/stripe/src/lib/server/stripe-customer.ts": B,
33
+ "../../enable/payments/providers-app-mode/stripe/src/lib/workflows/link-stripe-customer.ts": v,
34
+ "../../enable/payments/providers-app-mode/stripe/src/lib/workflows/sync-stripe-customers.ts": w,
35
+ "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+layout.server.ts": T,
36
+ "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.server.ts": V,
37
+ "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/+page.svelte": H,
38
+ "../../enable/payments/providers-app-mode/stripe/src/routes/(app)/billing/README.md": k,
39
+ "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/payment-intent/+server.ts": M,
40
+ "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/payment-intent/server.test.ts": C,
41
+ "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/setup-intent/+server.ts": S,
42
+ "../../enable/payments/providers-app-mode/stripe/src/routes/api/stripe/setup-intent/server.test.ts": P,
43
+ "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/dispatch.ts": O,
44
+ "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-intent/server.test.ts": x,
45
+ "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-intent/succeeded.ts": N,
46
+ "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-method/attached.ts": j,
47
+ "../../enable/payments/providers-app-mode/stripe/src/routes/webhooks/stripe/handlers/payment-method/server.test.ts": y
48
+ }), W = "src/routes/(public)/payment/+page.svelte";
49
+ function G(e) {
50
+ let t = e.providers?.payments, n = A.filter((e) => e.id === t);
51
+ return n.length > 0 ? n : A;
49
52
  }
50
- async function U(n) {
51
- let r = /* @__PURE__ */ new Set([V]);
52
- for (let e of H(n)) for (let n of t(B, e.id)) r.add(n);
53
+ async function K(n) {
54
+ let r = /* @__PURE__ */ new Set([W]);
55
+ for (let e of G(n)) for (let n of t(U, e.id)) r.add(n);
53
56
  return {
54
57
  creates: [],
55
58
  modifies: [],
@@ -67,6 +70,6 @@ async function U(n) {
67
70
  };
68
71
  }
69
72
  //#endregion
70
- export { H as n, U as t };
73
+ export { G as n, K as t };
71
74
 
72
- //# sourceMappingURL=generate-ZIOVLH6Q.js.map
75
+ //# sourceMappingURL=generate-jx5Iuq5w.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-jx5Iuq5w.js","names":["__import_glob__0_0_","__import_glob__0_1_","__import_glob__0_2_","__import_glob__0_3_","__import_glob__0_4_","__import_glob__0_5_","__import_glob__0_6_","__import_glob__0_7_","__import_glob__0_8_","__import_glob__0_9_","__import_glob__0_10_","__import_glob__0_11_","__import_glob__0_12_","__import_glob__0_13_","__import_glob__0_14_","__import_glob__0_15_","__import_glob__0_16_","__import_glob__0_17_","__import_glob__0_18_","__import_glob__0_19_","__import_glob__0_20_","__import_glob__0_21_","__import_glob__0_22_","__import_glob__0_23_","__import_glob__0_24_","__import_glob__0_25_","__import_glob__0_26_","__import_glob__0_27_","__import_glob__0_28_","__import_glob__0_29_","__import_glob__0_30_","__import_glob__0_31_","__import_glob__0_32_","__import_glob__0_33_","__import_glob__0_34_","__import_glob__0_35_","__import_glob__0_36_","__import_glob__0_37_","__import_glob__0_38_","__import_glob__0_39_","languageFromPath","sync_stripe_catalog_default","shopify_default","server_test_default$2","_server_default$1","dispatch_default","stripe_payment_form_default","stripe_constants_default","payment_dialog_default","stripe_default","use_stripe_svelte_default","server_test_default","use_payment_intent_svelte_default","payment_button_default","customer_fields_default","server_test_default$1","buy_button_default","link_stripe_customer_default","server_test_default$6","server_test_default$5","_server_default$3","server_test_default$3","sync_stripe_customers_default","_layout_server_default","stripe_event_default","_server_default","dispatch_default$1","README_default","PROVIDERS","attached_default","_server_default$2","succeeded_default$1","server_test_default$4","setup_dialog_default","succeeded_default","order_button_default","setup_button_default","stripe_customer_default","_page_server_default","_page_default","providersRaw","confirm_dialog_default","order_default","DEMO_PAGE","providersToRemove","detected","options","match","provider","generate","paths","path","allProviderPaths"],"sources":["../../src/patterns/disable/payments/generate.ts"],"sourcesContent":["import type { File, Options, Provider, Result } from \"../../../core/types\";\nimport { allProviderPaths } from \"../../../core/providers\";\nimport { languageFromPath } from \"../../../core/util\";\nimport { PROVIDERS } from \"../../enable/payments/generate\";\n\nconst providersRaw = import.meta.glob<string>(\n [\n \"../../enable/payments/providers/**\",\n \"../../enable/payments/providers-app-mode/**\",\n ],\n { query: \"?raw\", import: \"default\", eager: true },\n);\n\n// The demo page enable-payments writes at runtime (it carries the price or\n// variant id), so it is in no template tree: without the payment components it\n// would no longer build.\nconst DEMO_PAGE = \"src/routes/(public)/payment/+page.svelte\";\n\n/**\n * The provider whose files to remove: the one detected, else every one.\n * Removing every provider's files is safe, since a missing path is skipped.\n */\nexport function providersToRemove(\n options: Pick<Options, \"providers\">,\n): Provider[] {\n const detected = options.providers?.payments;\n const match = PROVIDERS.filter((provider) => provider.id === detected);\n return match.length > 0 ? match : PROVIDERS;\n}\n\nexport async function generate(options: Options) {\n // Both the plain and the app-mode files go, whatever auth is now: auth may\n // have been turned on or off since payments was enabled.\n const paths = new Set([DEMO_PAGE]);\n for (const provider of providersToRemove(options)) {\n for (const path of allProviderPaths(providersRaw, provider.id)) {\n paths.add(path);\n }\n }\n\n const deletes: File[] = [...paths].sort().map((path) => ({\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n }));\n\n return {\n creates: [],\n modifies: [],\n deletes,\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;AAKA,IAAMgF,IAAe,uBAAA,OAAA;CAAA,yFAAAhF;CAAA,8DAAAC;CAAA,4FAAAC;CAAA,4FAAAC;CAAA,4FAAAC;CAAA,0FAAAC;CAAA,iGAAAC;CAAA,mGAAAC;CAAA,2FAAAC;CAAA,4DAAAC;CAAA,4EAAAC;CAAA,mFAAAC;CAAA,0FAAAC;CAAA,8FAAAC;CAAA,gFAAAC;CAAA,0FAAAC;CAAA,4GAAAC;CAAA,0GAAAC;CAAA,oFAAAC;CAAA,+FAAAC;CAAA,4FAAAC;CAAA,6DAAAC;CAAA,mGAAAC;CAAA,mGAAAC;CAAA,qFAAAC;CAAA,6FAAAC;CAAA,8FAAAC;CAAA,8FAAAC;CAAA,4FAAAC;CAAA,yFAAAC;CAAA,sFAAAC;CAAA,mGAAAC;CAAA,uGAAAC;CAAA,iGAAAC;CAAA,qGAAAC;CAAA,mGAAAC;CAAA,qHAAAC;CAAA,mHAAAC;CAAA,kHAAAC;CAAA,qHAAAC;AAMrB,CAAA,GAKM4C,IAAY;AAMlB,SAAgBC,EACd,GACY;CACZ,IAAMC,IAAWC,EAAQ,WAAW,UAC9BC,IAAQnB,EAAU,QAAQ,MAAaoB,EAAS,OAAOH,CAAQ;CACrE,OAAOE,EAAM,SAAS,IAAIA,IAAQnB;AACpC;AAEA,eAAsBqB,EAAS,GAAkB;CAG/C,IAAMC,oBAAQ,IAAI,IAAI,CAACP,CAAS,CAAC;CACjC,KAAK,IAAMK,KAAYJ,EAAkBE,CAAO,GAC9C,KAAK,IAAMK,KAAQC,EAAiBZ,GAAcQ,EAAS,EAAE,GAC3D,EAAM,IAAIG,CAAI;CAWlB,OAAO;EACL,SAAS,CAAC;EACV,UAAU,CAAC;EACX,SAVsB,CAAC,GAAGD,CAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAU;GACvD;GACA,UAAUlD,EAAiBmD,CAAI;GAC/B,SAAS;GACT,QAAQ;EACV,EAKE;EACA,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -3,10 +3,10 @@ import { t } from "./dedent-Gq6Krl4n.js";
3
3
  import { n } from "./logger-CQONztPm.js";
4
4
  import { t as r } from "./env-vars-mnRA0hOe.js";
5
5
  import { c as i, i as a, n as o, o as s } from "./ts-morph-helpers-Bepc-Es2.js";
6
- import { r as c } from "./modify-file-Bbhyfiy_.js";
7
- import { modifyEnvVarsFiles as l } from "./env-vars-Bj41Nccm.js";
6
+ import { r as c } from "./modify-file-289rStJ2.js";
7
+ import { modifyEnvVarsFiles as l } from "./env-vars-cqQU0ECK.js";
8
8
  import { r as u } from "./compose-handle-BDlZ7Pif.js";
9
- import { c as d, i as f, n as p, o as m, r as h, t as g } from "./test-setup-DZoyF8Ak.js";
9
+ import { c as d, i as f, n as p, o as m, r as h, t as g } from "./test-setup-CAfgVlwc.js";
10
10
  import _ from "node:fs";
11
11
  import v from "node:path";
12
12
  import { Node as y, Project as b, QuoteKind as x } from "ts-morph";
@@ -161,4 +161,4 @@ async function k(t) {
161
161
  //#endregion
162
162
  export { k as generate };
163
163
 
164
- //# sourceMappingURL=generate.runtime-DlbG-8Xm.js.map
164
+ //# sourceMappingURL=generate.runtime-B2r11K7S.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-DlbG-8Xm.js","names":["languageFromPath","BACKEND_ENV_VARS","pruneUnusedImports","ensureNamedImport","ensureBlankLineAfterImports","formatLikeSource","modifyOutcomeToFile","replaceHandle","modifySvelteConfig","modifyTestSetup","WITH_BACKEND","modifyGitignore","hasVitestConfig","VITEST_CONFIG","fs","path","POCKETBASE_TYPES","VITEST_CONFIGS","ext","modifyTsconfigBackend","filePath","root","original","vitestConfig","name","wanted","config","entry","include","normalize","has","existing","next","insertAfter","index","after","i","indent","POCKETBASE_ENV_NAMES","POCKETBASE_HANDLE","FAILURE_HINT","modifyHooksServerBackend","hooksServerPath","sourceFile","Project","QuoteKind","composed","statement","Node","doc","generate","logger","getLogger","options","modifies","creates","create","adapter","svelteConfigFile","hooksServerFile","envVars","modifyEnvVarsFiles","gitignorePath","gitignoreFile","testSetupPath","testSetupFile","tsconfigPath","tsconfigFile"],"sources":["../../src/patterns/enable/backend/modifies/tsconfig.ts","../../src/patterns/enable/backend/modifies/hooks.server.ts","../../src/patterns/enable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Where `vela sync` writes PocketBase's generated types (`Schemas`, the typed client). */\nexport const POCKETBASE_TYPES = \".svelte-kit/types/pocketbase/*.d.ts\";\n\nconst VITEST_CONFIGS = [\"ts\", \"mts\", \"js\", \"mjs\"].map(\n (ext) => `vitest.config.${ext}`,\n);\n\n/**\n * SvelteKit 3's `$app/tsconfig` lists no files: the project's own `include`\n * decides what is type-checked, and `sv create` writes `[\"src\",\n * \"vite.config.ts\"]`. A backend adds three things that have to be in it, as\n * they are in vela's minimal template: `test` (the server-test context that\n * every `server.test.ts` reads), the vitest config, and PocketBase's generated\n * types, without which `Schemas` is missing from `@velastack/pocketbase`.\n *\n * Entries already there stay, in their order. A tsconfig with no `include`\n * checks everything already; one that is not plain JSON (comments) is left\n * alone with the entries to add.\n */\nexport function modifyTsconfigBackend(root: string): ModifyOutcome {\n const filePath = path.join(root, \"tsconfig.json\");\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n const vitestConfig =\n VITEST_CONFIGS.find((name) => fs.existsSync(path.join(root, name))) ??\n \"vitest.config.ts\";\n const wanted = [\"test\", vitestConfig, POCKETBASE_TYPES];\n\n let config: Record<string, unknown>;\n try {\n config = JSON.parse(original) as Record<string, unknown>;\n } catch {\n return {\n status: \"failed\",\n message: `Add these to the \"include\" array of tsconfig.json: ${wanted\n .map((entry) => JSON.stringify(entry))\n .join(\", \")}`,\n };\n }\n const include = config.include;\n if (include === undefined) {\n return { status: \"success\", changed: false };\n }\n if (!Array.isArray(include)) {\n return {\n status: \"failed\",\n message: `tsconfig.json \"include\" is not an array; it needs ${wanted.join(\", \")}`,\n };\n }\n\n const normalize = (entry: unknown) =>\n typeof entry === \"string\" ? entry.replace(/^\\.\\//, \"\") : entry;\n const has = (entry: string) =>\n include.some((existing) => normalize(existing) === entry);\n const next = [...include] as unknown[];\n const insertAfter = (entry: string, after: (e: unknown) => boolean) => {\n if (has(entry)) return;\n let index = -1;\n next.forEach((e, i) => {\n if (after(e)) index = i;\n });\n next.splice(index === -1 ? next.length : index + 1, 0, entry);\n };\n insertAfter(\"test\", (e) => normalize(e) === \"src\");\n insertAfter(vitestConfig, (e) =>\n /^vite\\.config\\.[cm]?[jt]s$/.test(String(normalize(e))),\n );\n insertAfter(POCKETBASE_TYPES, () => false);\n\n if (next.length === include.length) {\n return { status: \"success\", changed: false };\n }\n config.include = next;\n const indent = original.match(/^\\{\\s*\\n([\\t ]+)/)?.[1] ?? \"\\t\";\n fs.writeFileSync(filePath, `${JSON.stringify(config, null, indent)}\\n`);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node, Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { replaceHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n ensureNamedImport,\n pruneUnusedImports,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** The variables the handle reads, imported from `$app/env/private`. */\nexport const POCKETBASE_ENV_NAMES = [\n \"POCKETBASE_URL\",\n \"POCKETBASE_SUPERUSER_EMAIL\",\n \"POCKETBASE_SUPERUSER_PASSWORD\",\n] as const;\n\n/** The handle `creates/src/hooks.server.ts` exports, for a file that already exists. */\nexport const POCKETBASE_HANDLE = dedent`\n handlePocketbase({\n \tpocketbaseUrl: POCKETBASE_URL,\n \tsuperuserEmail: POCKETBASE_SUPERUSER_EMAIL,\n \tsuperuserPassword: POCKETBASE_SUPERUSER_PASSWORD\n })\n`;\n\nconst FAILURE_HINT = dedent`\n Add the PocketBase handle to the exported handle in src/hooks.server.ts:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import {\n \tPOCKETBASE_URL,\n \tPOCKETBASE_SUPERUSER_EMAIL,\n \tPOCKETBASE_SUPERUSER_PASSWORD\n } from '$app/env/private';\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = sequence(\n \t/* your existing handle */,\n \t${POCKETBASE_HANDLE.replace(/\\n/g, \"\\n\\t\")}\n );\n`;\n\n/**\n * Compose the PocketBase handle into a `hooks.server.ts` the project already\n * has, instead of the create overwriting it: a static site's, or one i18n or\n * content negotiation wrote. It takes `handleStatic()`'s place, since\n * `handlePocketbase` does what that did and more; otherwise it goes last, so\n * the handles already there keep running first.\n */\nexport function modifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // The create writes it.\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const composed = replaceHandle(sourceFile, \"handleStatic\", {\n expression: POCKETBASE_HANDLE,\n name: \"handlePocketbase\",\n position: \"last\",\n });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (composed.status === \"unchanged\") {\n return { status: \"success\", changed: false };\n }\n\n // The static template's comment explains handleStatic(). Where that was the\n // whole handle, replaceHandle already dropped it; in a sequence (i18n or\n // negotiation composed in since) it is still there, describing a handle\n // that is gone.\n const statement = composed.statement;\n if (statement && Node.isJSDocable(statement)) {\n for (const doc of statement.getJsDocs()) {\n if (doc.getText().includes(\"vela legal\")) doc.remove();\n }\n }\n\n pruneUnusedImports(sourceFile, [\"@velastack/kit\"]);\n for (const name of POCKETBASE_ENV_NAMES) {\n ensureNamedImport(sourceFile, \"$app/env/private\", name);\n }\n ensureNamedImport(sourceFile, \"@velastack/pocketbase\", \"handlePocketbase\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\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 { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyTsconfigBackend } from \"./modifies/tsconfig\";\nimport { languageFromPath } from \"../../../core/util\";\nimport {\n hasVitestConfig,\n modifyTestSetup,\n VITEST_CONFIG,\n WITH_BACKEND,\n} from \"./modifies/test-setup\";\nimport { modifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { BACKEND_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const creates: File[] = [];\n const create = (filePath: string, content: string) =>\n creates.push({\n path: filePath,\n language: languageFromPath(filePath),\n content,\n status: \"success\",\n });\n\n logger.info(\"Modifying adapter config\");\n const adapter = modifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(\n adapter.filePath,\n adapter.outcome,\n );\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // A hooks.server.ts the project already has keeps its handles; the create\n // only writes the file where there is none (see `keepMissing` in index.ts).\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerFile) {\n logger.info(\"Modifying hooks.server.ts\");\n modifies.push(hooksServerFile);\n }\n\n // SvelteKit 3 exposes only declared variables: the handle above reads\n // these three from `$app/env/private`.\n logger.info(\"Declaring the PocketBase variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, BACKEND_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Modifying .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n modifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n // A backend brings server tests with it. The static template and a project\n // vela did not create have no harness at all, so what is missing is created:\n // the setup file, and the vitest config that loads it.\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n if (fs.existsSync(testSetupPath)) {\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n modifyTestSetup(testSetupPath),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n } else {\n logger.info(\"Creating test/setup.ts\");\n create(\"test/setup.ts\", WITH_BACKEND);\n }\n\n if (!hasVitestConfig(options.root)) {\n logger.info(\"Creating vitest.config.ts\");\n create(\"vitest.config.ts\", VITEST_CONFIG);\n }\n\n // Kit 3's tsconfig lists no files, so the test harness and PocketBase's\n // generated types are type-checked only when the project's include names them.\n const tsconfigPath = path.join(options.root, \"tsconfig.json\");\n const tsconfigFile = modifyOutcomeToFile(\n tsconfigPath,\n modifyTsconfigBackend(options.root),\n );\n if (tsconfigFile) {\n logger.info(\"Modifying tsconfig.json\");\n modifies.push(tsconfigFile);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAagB,IAAmB,uCAE1BC,IAAiB;CAAC;CAAM;CAAO;CAAM;AAAK,CAAC,CAAC,KAC/C,MAAQ,iBAAiBC,GAC5B;AAcA,SAAgBC,EAAsB,GAA6B;CACjE,IAAMC,IAAWL,EAAK,KAAKM,GAAM,eAAe;CAChD,IAAI,CAACP,EAAG,WAAWM,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAME,IAAWR,EAAG,aAAaM,GAAU,MAAM,GAC3CG,IACJN,EAAe,MAAM,MAASH,EAAG,WAAWC,EAAK,KAAKM,GAAMG,CAAI,CAAC,CAAC,KAClE,oBACIC,IAAS;EAAC;EAAQF;EAAcP;CAAgB,GAElDU;CACJ,IAAI;EACF,IAAS,KAAK,MAAMJ,CAAQ;CAC9B,QAAQ;EACN,OAAO;GACL,QAAQ;GACR,SAAS,sDAAsDG,EAC5D,KAAK,MAAU,KAAK,UAAUE,CAAK,CAAC,CAAC,CACrC,KAAK,IAAI;EACd;CACF;CACA,IAAMC,IAAUF,EAAO;CACvB,IAAIE,MAAY,KAAA,GACd,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAI,CAAC,MAAM,QAAQA,CAAO,GACxB,OAAO;EACL,QAAQ;EACR,SAAS,qDAAqDH,EAAO,KAAK,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.runtime-B2r11K7S.js","names":["languageFromPath","BACKEND_ENV_VARS","pruneUnusedImports","ensureNamedImport","ensureBlankLineAfterImports","formatLikeSource","modifyOutcomeToFile","replaceHandle","modifySvelteConfig","modifyTestSetup","WITH_BACKEND","modifyGitignore","hasVitestConfig","VITEST_CONFIG","fs","path","POCKETBASE_TYPES","VITEST_CONFIGS","ext","modifyTsconfigBackend","filePath","root","original","vitestConfig","name","wanted","config","entry","include","normalize","has","existing","next","insertAfter","index","after","i","indent","POCKETBASE_ENV_NAMES","POCKETBASE_HANDLE","FAILURE_HINT","modifyHooksServerBackend","hooksServerPath","sourceFile","Project","QuoteKind","composed","statement","Node","doc","generate","logger","getLogger","options","modifies","creates","create","adapter","svelteConfigFile","hooksServerFile","envVars","modifyEnvVarsFiles","gitignorePath","gitignoreFile","testSetupPath","testSetupFile","tsconfigPath","tsconfigFile"],"sources":["../../src/patterns/enable/backend/modifies/tsconfig.ts","../../src/patterns/enable/backend/modifies/hooks.server.ts","../../src/patterns/enable/backend/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Where `vela sync` writes PocketBase's generated types (`Schemas`, the typed client). */\nexport const POCKETBASE_TYPES = \".svelte-kit/types/pocketbase/*.d.ts\";\n\nconst VITEST_CONFIGS = [\"ts\", \"mts\", \"js\", \"mjs\"].map(\n (ext) => `vitest.config.${ext}`,\n);\n\n/**\n * SvelteKit 3's `$app/tsconfig` lists no files: the project's own `include`\n * decides what is type-checked, and `sv create` writes `[\"src\",\n * \"vite.config.ts\"]`. A backend adds three things that have to be in it, as\n * they are in vela's minimal template: `test` (the server-test context that\n * every `server.test.ts` reads), the vitest config, and PocketBase's generated\n * types, without which `Schemas` is missing from `@velastack/pocketbase`.\n *\n * Entries already there stay, in their order. A tsconfig with no `include`\n * checks everything already; one that is not plain JSON (comments) is left\n * alone with the entries to add.\n */\nexport function modifyTsconfigBackend(root: string): ModifyOutcome {\n const filePath = path.join(root, \"tsconfig.json\");\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n const original = fs.readFileSync(filePath, \"utf8\");\n const vitestConfig =\n VITEST_CONFIGS.find((name) => fs.existsSync(path.join(root, name))) ??\n \"vitest.config.ts\";\n const wanted = [\"test\", vitestConfig, POCKETBASE_TYPES];\n\n let config: Record<string, unknown>;\n try {\n config = JSON.parse(original) as Record<string, unknown>;\n } catch {\n return {\n status: \"failed\",\n message: `Add these to the \"include\" array of tsconfig.json: ${wanted\n .map((entry) => JSON.stringify(entry))\n .join(\", \")}`,\n };\n }\n const include = config.include;\n if (include === undefined) {\n return { status: \"success\", changed: false };\n }\n if (!Array.isArray(include)) {\n return {\n status: \"failed\",\n message: `tsconfig.json \"include\" is not an array; it needs ${wanted.join(\", \")}`,\n };\n }\n\n const normalize = (entry: unknown) =>\n typeof entry === \"string\" ? entry.replace(/^\\.\\//, \"\") : entry;\n const has = (entry: string) =>\n include.some((existing) => normalize(existing) === entry);\n const next = [...include] as unknown[];\n const insertAfter = (entry: string, after: (e: unknown) => boolean) => {\n if (has(entry)) return;\n let index = -1;\n next.forEach((e, i) => {\n if (after(e)) index = i;\n });\n next.splice(index === -1 ? next.length : index + 1, 0, entry);\n };\n insertAfter(\"test\", (e) => normalize(e) === \"src\");\n insertAfter(vitestConfig, (e) =>\n /^vite\\.config\\.[cm]?[jt]s$/.test(String(normalize(e))),\n );\n insertAfter(POCKETBASE_TYPES, () => false);\n\n if (next.length === include.length) {\n return { status: \"success\", changed: false };\n }\n config.include = next;\n const indent = original.match(/^\\{\\s*\\n([\\t ]+)/)?.[1] ?? \"\\t\";\n fs.writeFileSync(filePath, `${JSON.stringify(config, null, indent)}\\n`);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node, Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { replaceHandle } from \"../../../../runtime/compose-handle\";\nimport {\n ensureBlankLineAfterImports,\n ensureNamedImport,\n pruneUnusedImports,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\n/** The variables the handle reads, imported from `$app/env/private`. */\nexport const POCKETBASE_ENV_NAMES = [\n \"POCKETBASE_URL\",\n \"POCKETBASE_SUPERUSER_EMAIL\",\n \"POCKETBASE_SUPERUSER_PASSWORD\",\n] as const;\n\n/** The handle `creates/src/hooks.server.ts` exports, for a file that already exists. */\nexport const POCKETBASE_HANDLE = dedent`\n handlePocketbase({\n \tpocketbaseUrl: POCKETBASE_URL,\n \tsuperuserEmail: POCKETBASE_SUPERUSER_EMAIL,\n \tsuperuserPassword: POCKETBASE_SUPERUSER_PASSWORD\n })\n`;\n\nconst FAILURE_HINT = dedent`\n Add the PocketBase handle to the exported handle in src/hooks.server.ts:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import {\n \tPOCKETBASE_URL,\n \tPOCKETBASE_SUPERUSER_EMAIL,\n \tPOCKETBASE_SUPERUSER_PASSWORD\n } from '$app/env/private';\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = sequence(\n \t/* your existing handle */,\n \t${POCKETBASE_HANDLE.replace(/\\n/g, \"\\n\\t\")}\n );\n`;\n\n/**\n * Compose the PocketBase handle into a `hooks.server.ts` the project already\n * has, instead of the create overwriting it: a static site's, or one i18n or\n * content negotiation wrote. It takes `handleStatic()`'s place, since\n * `handlePocketbase` does what that did and more; otherwise it goes last, so\n * the handles already there keep running first.\n */\nexport function modifyHooksServerBackend(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n // The create writes it.\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const composed = replaceHandle(sourceFile, \"handleStatic\", {\n expression: POCKETBASE_HANDLE,\n name: \"handlePocketbase\",\n position: \"last\",\n });\n if (composed.status === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (composed.status === \"unchanged\") {\n return { status: \"success\", changed: false };\n }\n\n // The static template's comment explains handleStatic(). Where that was the\n // whole handle, replaceHandle already dropped it; in a sequence (i18n or\n // negotiation composed in since) it is still there, describing a handle\n // that is gone.\n const statement = composed.statement;\n if (statement && Node.isJSDocable(statement)) {\n for (const doc of statement.getJsDocs()) {\n if (doc.getText().includes(\"vela legal\")) doc.remove();\n }\n }\n\n pruneUnusedImports(sourceFile, [\"@velastack/kit\"]);\n for (const name of POCKETBASE_ENV_NAMES) {\n ensureNamedImport(sourceFile, \"$app/env/private\", name);\n }\n ensureNamedImport(sourceFile, \"@velastack/pocketbase\", \"handlePocketbase\");\n\n formatLikeSource(sourceFile);\n ensureBlankLineAfterImports(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== original,\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 { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { modifyTsconfigBackend } from \"./modifies/tsconfig\";\nimport { languageFromPath } from \"../../../core/util\";\nimport {\n hasVitestConfig,\n modifyTestSetup,\n VITEST_CONFIG,\n WITH_BACKEND,\n} from \"./modifies/test-setup\";\nimport { modifyHooksServerBackend } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { BACKEND_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const creates: File[] = [];\n const create = (filePath: string, content: string) =>\n creates.push({\n path: filePath,\n language: languageFromPath(filePath),\n content,\n status: \"success\",\n });\n\n logger.info(\"Modifying adapter config\");\n const adapter = modifySvelteConfig(options.root);\n const svelteConfigFile = modifyOutcomeToFile(\n adapter.filePath,\n adapter.outcome,\n );\n if (svelteConfigFile) modifies.push(svelteConfigFile);\n\n // A hooks.server.ts the project already has keeps its handles; the create\n // only writes the file where there is none (see `keepMissing` in index.ts).\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksServerFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerBackend(hooksServerPath),\n );\n if (hooksServerFile) {\n logger.info(\"Modifying hooks.server.ts\");\n modifies.push(hooksServerFile);\n }\n\n // SvelteKit 3 exposes only declared variables: the handle above reads\n // these three from `$app/env/private`.\n logger.info(\"Declaring the PocketBase variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, BACKEND_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Modifying .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n const gitignoreFile = modifyOutcomeToFile(\n gitignorePath,\n modifyGitignore(gitignorePath),\n );\n if (gitignoreFile) modifies.push(gitignoreFile);\n\n // A backend brings server tests with it. The static template and a project\n // vela did not create have no harness at all, so what is missing is created:\n // the setup file, and the vitest config that loads it.\n const testSetupPath = path.join(options.root, \"test\", \"setup.ts\");\n if (fs.existsSync(testSetupPath)) {\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = modifyOutcomeToFile(\n testSetupPath,\n modifyTestSetup(testSetupPath),\n );\n if (testSetupFile) modifies.push(testSetupFile);\n } else {\n logger.info(\"Creating test/setup.ts\");\n create(\"test/setup.ts\", WITH_BACKEND);\n }\n\n if (!hasVitestConfig(options.root)) {\n logger.info(\"Creating vitest.config.ts\");\n create(\"vitest.config.ts\", VITEST_CONFIG);\n }\n\n // Kit 3's tsconfig lists no files, so the test harness and PocketBase's\n // generated types are type-checked only when the project's include names them.\n const tsconfigPath = path.join(options.root, \"tsconfig.json\");\n const tsconfigFile = modifyOutcomeToFile(\n tsconfigPath,\n modifyTsconfigBackend(options.root),\n );\n if (tsconfigFile) {\n logger.info(\"Modifying tsconfig.json\");\n modifies.push(tsconfigFile);\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,IAAagB,IAAmB,uCAE1BC,IAAiB;CAAC;CAAM;CAAO;CAAM;AAAK,CAAC,CAAC,KAC/C,MAAQ,iBAAiBC,GAC5B;AAcA,SAAgBC,EAAsB,GAA6B;CACjE,IAAMC,IAAWL,EAAK,KAAKM,GAAM,eAAe;CAChD,IAAI,CAACP,EAAG,WAAWM,CAAQ,GACzB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAME,IAAWR,EAAG,aAAaM,GAAU,MAAM,GAC3CG,IACJN,EAAe,MAAM,MAASH,EAAG,WAAWC,EAAK,KAAKM,GAAMG,CAAI,CAAC,CAAC,KAClE,oBACIC,IAAS;EAAC;EAAQF;EAAcP;CAAgB,GAElDU;CACJ,IAAI;EACF,IAAS,KAAK,MAAMJ,CAAQ;CAC9B,QAAQ;EACN,OAAO;GACL,QAAQ;GACR,SAAS,sDAAsDG,EAC5D,KAAK,MAAU,KAAK,UAAUE,CAAK,CAAC,CAAC,CACrC,KAAK,IAAI;EACd;CACF;CACA,IAAMC,IAAUF,EAAO;CACvB,IAAIE,MAAY,KAAA,GACd,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAE7C,IAAI,CAAC,MAAM,QAAQA,CAAO,GACxB,OAAO;EACL,QAAQ;EACR,SAAS,qDAAqDH,EAAO,KAAK,IAAI;CAChF;CAGF,IAAMI,KAAa,MACjB,OAAOF,KAAU,WAAWA,EAAM,QAAQ,SAAS,EAAE,IAAIA,GACrDG,KAAO,MACXF,EAAQ,MAAM,MAAaC,EAAUE,CAAQ,MAAMJ,CAA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;CAC9D,IAAMS,IAAUC,EAAmBR,EAAQ,MAAMpD,CAAgB;CAIjE,AAHI2D,EAAQ,UAAQL,EAAQ,KAAKK,EAAQ,MAAM,GAC3CA,EAAQ,UAAQN,EAAS,KAAKM,EAAQ,MAAM,GAEhDT,EAAO,KAAK,sBAAsB;CAClC,IAAMW,IAAgB/C,EAAK,KAAKsC,EAAQ,MAAM,YAAY,GACpDU,IAAgBzD,EACpBwD,GACAnD,EAAgBmD,CAAa,CAC/B;CACA,AAAIC,KAAeT,EAAS,KAAKS,CAAa;CAK9C,IAAMC,IAAgBjD,EAAK,KAAKsC,EAAQ,MAAM,QAAQ,UAAU;CAChE,IAAIvC,EAAG,WAAWkD,CAAa,GAAG;EAChC,EAAO,KAAK,yBAAyB;EACrC,IAAMC,IAAgB3D,EACpB0D,GACAvD,EAAgBuD,CAAa,CAC/B;EACA,AAAIC,KAAeX,EAAS,KAAKW,CAAa;CAChD,OAEE,AADAd,EAAO,KAAK,wBAAwB,GACpCK,EAAO,iBAAiB9C,CAAY;CAGtC,AAAKE,EAAgByC,EAAQ,IAAI,MAC/BF,EAAO,KAAK,2BAA2B,GACvCK,EAAO,oBAAoB3C,CAAa;CAK1C,IAAMqD,IAAenD,EAAK,KAAKsC,EAAQ,MAAM,eAAe,GACtDc,IAAe7D,EACnB4D,GACA/C,EAAsBkC,EAAQ,IAAI,CACpC;CAMA,OALIc,MACFhB,EAAO,KAAK,yBAAyB,GACrCG,EAAS,KAAKa,CAAY,IAGrB;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { n as e } from "./logger-CQONztPm.js";
2
- import { r as t } from "./modify-file-Bbhyfiy_.js";
3
- import { i as n, n as r } from "./pocketbase-CgwbH1gI.js";
4
- import { i, n as a, o } from "./whatsapp-CguKGTtw.js";
2
+ import { i as t, n } from "./pocketbase-B017Cqjq.js";
3
+ import { r } from "./modify-file-289rStJ2.js";
4
+ import { i, n as a, o } from "./whatsapp-5qJ_xCV1.js";
5
5
  import { swapAuthPages as s } from "./auth-pages-B52ei-4z.js";
6
6
  import c from "node:fs";
7
7
  import l from "node:path";
@@ -9,9 +9,9 @@ import l from "node:path";
9
9
  var u = "https://velastack.dev/docs/disable/whatsapp";
10
10
  async function d(d) {
11
11
  let f = e(d), p = [];
12
- await n(d.root, async (e) => {
12
+ await t(d.root, async (e) => {
13
13
  if (!await i(e)) return;
14
- f.info("Turning off WhatsApp sign-in for users"), await a(e), await r();
14
+ f.info("Turning off WhatsApp sign-in for users"), await a(e), await n();
15
15
  let t = o(d, !1);
16
16
  t && p.push({
17
17
  path: t,
@@ -21,9 +21,9 @@ async function d(d) {
21
21
  });
22
22
  }), f.info("Keeping the phone fields on users, and email optional: they hold your users' data"), f.info("Taking WhatsApp off the login and signup pages");
23
23
  let m = [], h = await s(d.root, "disable", (e) => `${l.relative(d.root, e)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of it by hand: ${u}`);
24
- for (let [e, n] of h) {
25
- let r = t(e, n);
26
- r && m.push(r);
24
+ for (let [e, t] of h) {
25
+ let n = r(e, t);
26
+ n && m.push(n);
27
27
  }
28
28
  return {
29
29
  creates: p,
@@ -39,4 +39,4 @@ async function d(d) {
39
39
  //#endregion
40
40
  export { d as generate };
41
41
 
42
- //# sourceMappingURL=generate.runtime-pMpn0Pbf.js.map
42
+ //# sourceMappingURL=generate.runtime-B4u9C2YH.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-pMpn0Pbf.js","names":["getLogger","modifyOutcomeToFile","withPocketbase","migrationDelay","disableWhatsAppAuth","fs","path","DOCS_URL","generate","logger","options","creates","hasWhatsAppPlugin","pb","file","writeWhatsAppConfigMigration","modifies","outcomes","swapAuthPages","filePath","outcome"],"sources":["../../src/patterns/disable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { migrationDelay, withPocketbase } from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n disableWhatsAppAuth,\n hasWhatsAppPlugin,\n writeWhatsAppConfigMigration,\n} from \"../../enable/whatsapp/runtime/whatsapp\";\nimport { swapAuthPages } from \"../../enable/whatsapp/modifies/auth-pages\";\n\nconst DOCS_URL = \"https://velastack.dev/docs/disable/whatsapp\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n // Without the plugin there is no WhatsApp sign-in to turn off.\n if (!(await hasWhatsAppPlugin(pb))) return;\n\n logger.info(\"Turning off WhatsApp sign-in for users\");\n await disableWhatsAppAuth(pb);\n await migrationDelay();\n const file = writeWhatsAppConfigMigration(options, false);\n if (!file) return;\n creates.push({\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n });\n });\n logger.info(\n \"Keeping the phone fields on users, and email optional: they hold your users' data\",\n );\n\n logger.info(\"Taking WhatsApp off the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"disable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of 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 return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAaA,IAAMO,IAAW;AAEjB,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAAST,EAAUU,CAAO,GAC1BC,IAAkB,CAAC;CAsBzB,AApBA,MAAMT,EAAeQ,EAAQ,MAAM,OAAO,MAAO;EAE/C,IAAI,CAAE,MAAME,EAAkBC,CAAE,GAAI;EAIpC,AAFAJ,EAAO,KAAK,wCAAwC,GACpD,MAAML,EAAoBS,CAAE,GAC5B,MAAMV,EAAe;EACrB,IAAMW,IAAOC,EAA6BL,GAAS,EAAK;EACxD,AAAKI,KACLH,EAAQ,KAAK;GACX,MAAMG;GACN,UAAU;GACV,SAAST,EAAG,aAAaS,GAAM,MAAM;GACrC,QAAQ;EACV,CAAC;CACH,CAAC,GACDL,EAAO,KACL,mFACF,GAEAA,EAAO,KAAK,gDAAgD;CAC5D,IAAMO,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBR,EAAQ,MACR,YACC,MACC,GAAGJ,EAAK,SAASI,EAAQ,MAAMS,CAAQ,EAAE,+GAA+GZ,GAC5J;CACA,KAAK,IAAM,CAACY,GAAUC,MAAYH,GAAU;EAC1C,IAAMH,IAAOb,EAAoBkB,GAAUC,CAAO;EAClD,AAAIN,KAAME,EAAS,KAAKF,CAAI;CAC9B;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
1
+ {"version":3,"file":"generate.runtime-B4u9C2YH.js","names":["getLogger","withPocketbase","disableWhatsAppAuth","fs","path","DOCS_URL","generate","logger","options","creates","hasWhatsAppPlugin","pb","migrationDelay","file","writeWhatsAppConfigMigration","modifies","outcomes","swapAuthPages","filePath","outcome","modifyOutcomeToFile"],"sources":["../../src/patterns/disable/whatsapp/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { migrationDelay, withPocketbase } from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n disableWhatsAppAuth,\n hasWhatsAppPlugin,\n writeWhatsAppConfigMigration,\n} from \"../../enable/whatsapp/runtime/whatsapp\";\nimport { swapAuthPages } from \"../../enable/whatsapp/modifies/auth-pages\";\n\nconst DOCS_URL = \"https://velastack.dev/docs/disable/whatsapp\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n // Without the plugin there is no WhatsApp sign-in to turn off.\n if (!(await hasWhatsAppPlugin(pb))) return;\n\n logger.info(\"Turning off WhatsApp sign-in for users\");\n await disableWhatsAppAuth(pb);\n await migrationDelay();\n const file = writeWhatsAppConfigMigration(options, false);\n if (!file) return;\n creates.push({\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n });\n });\n logger.info(\n \"Keeping the phone fields on users, and email optional: they hold your users' data\",\n );\n\n logger.info(\"Taking WhatsApp off the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"disable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of 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 return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAaA,IAAMK,IAAW;AAEjB,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASP,EAAUQ,CAAO,GAC1BC,IAAkB,CAAC;CAsBzB,AApBA,MAAMR,EAAeO,EAAQ,MAAM,OAAO,MAAO;EAE/C,IAAI,CAAE,MAAME,EAAkBC,CAAE,GAAI;EAIpC,AAFAJ,EAAO,KAAK,wCAAwC,GACpD,MAAML,EAAoBS,CAAE,GAC5B,MAAMC,EAAe;EACrB,IAAMC,IAAOC,EAA6BN,GAAS,EAAK;EACxD,AAAKK,KACLJ,EAAQ,KAAK;GACX,MAAMI;GACN,UAAU;GACV,SAASV,EAAG,aAAaU,GAAM,MAAM;GACrC,QAAQ;EACV,CAAC;CACH,CAAC,GACDN,EAAO,KACL,mFACF,GAEAA,EAAO,KAAK,gDAAgD;CAC5D,IAAMQ,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBT,EAAQ,MACR,YACC,MACC,GAAGJ,EAAK,SAASI,EAAQ,MAAMU,CAAQ,EAAE,+GAA+Gb,GAC5J;CACA,KAAK,IAAM,CAACa,GAAUC,MAAYH,GAAU;EAC1C,IAAMH,IAAOO,EAAoBF,GAAUC,CAAO;EAClD,AAAIN,KAAME,EAAS,KAAKF,CAAI;CAC9B;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -2,8 +2,8 @@ import { t as e } from "./dedent-Gq6Krl4n.js";
2
2
  import { n as t } from "./logger-CQONztPm.js";
3
3
  import { t as n } from "./env-vars-Cr4lbMD_.js";
4
4
  import { o as r } from "./ts-morph-helpers-Bepc-Es2.js";
5
- import { r as i } from "./modify-file-Bbhyfiy_.js";
6
- import { modifyEnvVarsFiles as a } from "./env-vars-Bj41Nccm.js";
5
+ import { r as i } from "./modify-file-289rStJ2.js";
6
+ import { modifyEnvVarsFiles as a } from "./env-vars-cqQU0ECK.js";
7
7
  import o from "node:fs";
8
8
  import s from "node:path";
9
9
  import { Project as c, QuoteKind as l } from "ts-morph";
@@ -89,4 +89,4 @@ async function g(e) {
89
89
  //#endregion
90
90
  export { g as generate };
91
91
 
92
- //# sourceMappingURL=generate.runtime-DetYynf4.js.map
92
+ //# sourceMappingURL=generate.runtime-BRCzUO94.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-DetYynf4.js","names":["dedent","getLogger","WORKFLOWS_ENV_VARS","formatLikeSource","modifyOutcomeToFile","fs","path","INIT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","ensureNamedImport","existing","sourceFile","d","moduleSpecifier","typeOnly","name","ni","hasInitExport","modifyHooksServerWorkflows","hooksServerPath","Project","QuoteKind","generate","logger","options","creates","modifies","hooksFile","envVars","modifyEnvVarsFiles"],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit/hooks';\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"#lib/server/workflows.js\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n // SvelteKit 3 exposes only declared variables; the template declares these\n // already, an older project gets whichever it is missing.\n logger.info(\"Declaring the workflow variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, WORKFLOWS_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAMA,IAAMO,IAAe,CAAM;;;GAKrBC,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;AAS7B,SAASC,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAMC,IAAWC,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAMC,EAAE,wBAAwB,MAAMC,CAAe;CAC9D,IAAI,CAACH,GAAU;EACb,EAAW,qBAAqB;GAC9B,YAAYI;GACZ,cAAc,CAACC,CAAI;GACnB;EACF,CAAC;EACD;CACF;CACA,AAAIL,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAOM,EAAG,QAAQ,MAAMD,CAAI,KAGjEL,EAAS,eACPI,KAAY,CAACJ,EAAS,WAAW,IAAI;EAAE;EAAM,YAAY;CAAK,IAAIK,CACpE;AACF;AAEA,SAASE,EAAc,GAAiC;CAGtD,OAFIN,EAAW,uBAAuB,MAAM,KACxCA,EAAW,YAAY,MAAM,IAAU,KACpCA,EACJ,sBAAsB,CAAC,CACvB,MAAM,MAAMC,EAAE,gBAAgB,CAAC,CAAC,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM,CAAC;AACxE;AAMA,SAAgBM,EACd,GACe;CACf,IAAI,CAACd,EAAG,WAAWe,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAa,SAASX;CAAe;CAIxD,IADiBJ,EAAG,aAAae,GAAi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E_HINT","NOT_FOUND_HINT","ensureNamedImport","existing","sourceFile","d","moduleSpecifier","typeOnly","name","ni","hasInitExport","modifyHooksServerWorkflows","hooksServerPath","Project","QuoteKind","generate","logger","options","creates","modifies","hooksFile","envVars","modifyEnvVarsFiles"],"sources":["../../src/patterns/enable/workflows/modifies/hooks.server.ts","../../src/patterns/enable/workflows/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, type SourceFile } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst INIT_SNIPPET = dedent`\n // Runs once when the server starts: executes the workflows in src/lib/workflows.\n export const init: ServerInit = () => startWorker();\n`;\n\nconst FAILURE_HINT = dedent`\n src/hooks.server.ts already exports an init hook. Start the workflow worker from it:\n\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = async () => {\n await startWorker();\n // ...the rest of your init\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts and start the workflow worker from its init hook:\n\n import type { ServerInit } from '@sveltejs/kit/hooks';\n import { startWorker } from '#lib/server/workflows.js';\n\n export const init: ServerInit = () => startWorker();\n`;\n\nfunction ensureNamedImport(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n name: string,\n typeOnly = false,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({\n isTypeOnly: typeOnly,\n namedImports: [name],\n moduleSpecifier,\n });\n return;\n }\n if (existing.getNamedImports().some((ni) => ni.getName() === name)) return;\n // A declaration that is already `import type` covers the new name; a value\n // import takes the name as an inline `type` specifier.\n existing.addNamedImport(\n typeOnly && !existing.isTypeOnly() ? { name, isTypeOnly: true } : name,\n );\n}\n\nfunction hasInitExport(sourceFile: SourceFile): boolean {\n if (sourceFile.getVariableDeclaration(\"init\")) return true;\n if (sourceFile.getFunction(\"init\")) return true;\n return sourceFile\n .getExportDeclarations()\n .some((d) => d.getNamedExports().some((e) => e.getName() === \"init\"));\n}\n\n/**\n * Adds the `init` hook that starts the workflow worker. Projects created from\n * the base template already have it; this is the upgrade path for older ones.\n */\nexport function modifyHooksServerWorkflows(\n hooksServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"startWorker\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n if (hasInitExport(sourceFile)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"ServerInit\", true);\n ensureNamedImport(sourceFile, \"#lib/server/workflows.js\", \"startWorker\");\n\n // After everything else, so the hook reads as the last thing the server does on start.\n sourceFile.addStatements(`\\n${INIT_SNIPPET}`);\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyHooksServerWorkflows } from \"./modifies/hooks.server\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { WORKFLOWS_ENV_VARS } from \"./env-vars\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const hooksFile = modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerWorkflows(hooksServerPath),\n );\n if (hooksFile) modifies.push(hooksFile);\n\n // SvelteKit 3 exposes only declared variables; the template declares these\n // already, an older project gets whichever it is missing.\n logger.info(\"Declaring the workflow variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, WORKFLOWS_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;AAMA,IAAMO,IAAe,CAAM;;;GAKrBC,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;AAS7B,SAASC,EACP,GACA,GACA,GACA,IAAW,IACX;CACA,IAAMC,IAAWC,EACd,sBAAsB,CAAC,CACvB,MAAM,MAAMC,EAAE,wBAAwB,MAAMC,CAAe;CAC9D,IAAI,CAACH,GAAU;EACb,EAAW,qBAAqB;GAC9B,YAAYI;GACZ,cAAc,CAACC,CAAI;GACnB;EACF,CAAC;EACD;CACF;CACA,AAAIL,EAAS,gBAAgB,CAAC,CAAC,MAAM,MAAOM,EAAG,QAAQ,MAAMD,CAAI,KAGjEL,EAAS,eACPI,KAAY,CAACJ,EAAS,WAAW,IAAI;EAAE;EAAM,YAAY;CAAK,IAAIK,CACpE;AACF;AAEA,SAASE,EAAc,GAAiC;CAGtD,OAFIN,EAAW,uBAAuB,MAAM,KACxCA,EAAW,YAAY,MAAM,IAAU,KACpCA,EACJ,sBAAsB,CAAC,CACvB,MAAM,MAAMC,EAAE,gBAAgB,CAAC,CAAC,MAAM,MAAM,EAAE,QAAQ,MAAM,MAAM,CAAC;AACxE;AAMA,SAAgBM,EACd,GACe;CACf,IAAI,CAACd,EAAG,WAAWe,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAa,SAASX;CAAe;CAIxD,IADiBJ,EAAG,aAAae,GAAiB,MAC9C,CAAA,CAAS,SAAS,aAAa,GACjC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAO7C,IAAMR,IAAa,IAJCS,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAWC,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoBF,CAAe;CAc9D,OAZIF,EAAcN,CAAU,IACnB;EAAE,QAAQ;EAAU,SAASJ;CAAa,KAGnDE,EAAkBE,GAAY,uBAAuB,cAAc,EAAI,GACvEF,EAAkBE,GAAY,4BAA4B,aAAa,GAGvEA,EAAW,cAAc,KAAKL,GAAc,GAE5CJ,EAAiBS,CAAU,GAC3BA,EAAW,SAAS,GACb;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C;;;AC3FA,eAAsBW,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAE1B,EAAO,KAAK,2BAA2B;CACvC,IAAMP,IAAkBd,EAAK,KAAKmB,EAAQ,MAAM,OAAO,iBAAiB,GAClEG,IAAYxB,EAChBgB,GACAD,EAA2BC,CAAe,CAC5C;CAKA,AAJIQ,KAAWD,EAAS,KAAKC,CAAS,GAItCJ,EAAO,KAAK,gDAAgD;CAC5D,IAAMK,IAAUC,EAAmBL,EAAQ,MAAMvB,CAAkB;CAInE,OAHI2B,EAAQ,UAAQH,EAAQ,KAAKG,EAAQ,MAAM,GAC3CA,EAAQ,UAAQF,EAAS,KAAKE,EAAQ,MAAM,GAEzC;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,8 +1,8 @@
1
1
  import { n as e } from "./logger-CQONztPm.js";
2
2
  import { n as t, t as n } from "./_page-DoPdZgZv.js";
3
- import { t as r } from "./shared-D5GOS97l.js";
3
+ import { t as r } from "./shared-BPlAVf-T.js";
4
4
  import { _ as i, h as a, o, u as s } from "./ts-morph-helpers-Bepc-Es2.js";
5
- import { r as c } from "./modify-file-Bbhyfiy_.js";
5
+ import { r as c } from "./modify-file-289rStJ2.js";
6
6
  import { t as l } from "./svelte-file-Dv5-bl79.js";
7
7
  import { t as u } from "./unmodify-load-Bl5vXQiL.js";
8
8
  import { r as d, t as f } from "./modify-nav-user-B8h8WTrM.js";
@@ -215,4 +215,4 @@ async function O(i) {
215
215
  //#endregion
216
216
  export { O as generate };
217
217
 
218
- //# sourceMappingURL=generate.runtime-CcPCAEV0.js.map
218
+ //# sourceMappingURL=generate.runtime-BVavIXtX.js.map