@velastack/patterns 0.0.38 → 0.0.39

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 (36) hide show
  1. package/dist/chunks/_server-B3Rzajf2.js +6 -0
  2. package/dist/chunks/_server-B3Rzajf2.js.map +1 -0
  3. package/dist/chunks/{collections-RlxhqXdR.js → collections-CUtXB8_s.js} +1 -1
  4. package/dist/chunks/{collections-RlxhqXdR.js.map → collections-CUtXB8_s.js.map} +1 -1
  5. package/dist/chunks/{generate.runtime-CFH03New.js → generate.runtime-BQTf0jam.js} +2 -2
  6. package/dist/chunks/{generate.runtime-CFH03New.js.map → generate.runtime-BQTf0jam.js.map} +1 -1
  7. package/dist/chunks/{generate.runtime-BllWzqI_.js → generate.runtime-BS7zL9wC.js} +2 -2
  8. package/dist/chunks/{generate.runtime-BllWzqI_.js.map → generate.runtime-BS7zL9wC.js.map} +1 -1
  9. package/dist/chunks/generate.runtime-BfDfDNO9.js +197 -0
  10. package/dist/chunks/generate.runtime-BfDfDNO9.js.map +1 -0
  11. package/dist/chunks/{generate.runtime-CZwuYNbQ.js → generate.runtime-Bk9nFjoW.js} +2 -2
  12. package/dist/chunks/{generate.runtime-CZwuYNbQ.js.map → generate.runtime-Bk9nFjoW.js.map} +1 -1
  13. package/dist/chunks/{generate.runtime-CdawV-C4.js → generate.runtime-BwbTS71o.js} +2 -2
  14. package/dist/chunks/{generate.runtime-CdawV-C4.js.map → generate.runtime-BwbTS71o.js.map} +1 -1
  15. package/dist/chunks/{generate.runtime-DgYEht-Z.js → generate.runtime-C2Ev291A.js} +1 -1
  16. package/dist/chunks/{generate.runtime-DgYEht-Z.js.map → generate.runtime-C2Ev291A.js.map} +1 -1
  17. package/dist/chunks/{generate.runtime-7N_86Kl1.js → generate.runtime-CJg6JI4m.js} +2 -2
  18. package/dist/chunks/{generate.runtime-7N_86Kl1.js.map → generate.runtime-CJg6JI4m.js.map} +1 -1
  19. package/dist/chunks/{generate.runtime-mjs_qfUh.js → generate.runtime-CXorM210.js} +1 -1
  20. package/dist/chunks/{generate.runtime-mjs_qfUh.js.map → generate.runtime-CXorM210.js.map} +1 -1
  21. package/dist/chunks/{generate.runtime-DhbtqZYL.js → generate.runtime-ClIJQ2E0.js} +2 -2
  22. package/dist/chunks/{generate.runtime-DhbtqZYL.js.map → generate.runtime-ClIJQ2E0.js.map} +1 -1
  23. package/dist/chunks/{generate.runtime-B_Z_225G.js → generate.runtime-CqEWaQXx.js} +2 -2
  24. package/dist/chunks/{generate.runtime-B_Z_225G.js.map → generate.runtime-CqEWaQXx.js.map} +1 -1
  25. package/dist/chunks/{generate.runtime-DmU6R2Ez.js → generate.runtime-KwhuvW-W.js} +2 -2
  26. package/dist/chunks/{generate.runtime-DmU6R2Ez.js.map → generate.runtime-KwhuvW-W.js.map} +1 -1
  27. package/dist/chunks/{shared-CG8Qf95D.js → shared-Bt7uM3CK.js} +2 -2
  28. package/dist/chunks/{shared-CG8Qf95D.js.map → shared-Bt7uM3CK.js.map} +1 -1
  29. package/dist/chunks/{write-result-CjSxx3ZD.js → write-result-DQYWzSqE.js} +2 -2
  30. package/dist/chunks/{write-result-CjSxx3ZD.js.map → write-result-DQYWzSqE.js.map} +1 -1
  31. package/dist/index.d.ts +91 -35
  32. package/dist/index.js +631 -511
  33. package/dist/index.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/chunks/_server-BCbQIYCn.js +0 -6
  36. package/dist/chunks/_server-BCbQIYCn.js.map +0 -1
@@ -0,0 +1,197 @@
1
+ import { t as e } from "./dedent-C4qKBQXh.js";
2
+ import { t } from "./taggedTemplateLiteral-Bfbldyfk.js";
3
+ import { n } from "./logger-BpgCb-ZG.js";
4
+ import { modifyOutcomeToFile as r } from "./modify-file-DGBe3ycw.js";
5
+ import { n as i, o as a } from "./ts-morph-helpers-DjpZhZ7I.js";
6
+ import { findSvelteConfigPath as o } from "./modify-svelte-config-remote-C-Wl2nk1.js";
7
+ import s from "node:fs";
8
+ import c from "node:path";
9
+ import { Project as l, QuoteKind as u, SyntaxKind as d } from "ts-morph";
10
+ //#region src/patterns/enable/blog/modifies/svelte.config.ts
11
+ var f = e`
12
+ Enable mdsvex in your svelte.config.js:
13
+
14
+ import { mdsvex } from 'mdsvex';
15
+
16
+ const config = {
17
+ extensions: ['.svelte', '.svx'],
18
+ preprocess: [mdsvex()],
19
+ // ...
20
+ };
21
+ `, p = e`
22
+ Create a Svelte config with mdsvex enabled:
23
+
24
+ import adapter from '@sveltejs/adapter-auto';
25
+ import { mdsvex } from 'mdsvex';
26
+
27
+ const config = {
28
+ extensions: ['.svelte', '.svx'],
29
+ preprocess: [mdsvex()],
30
+ kit: { adapter: adapter() },
31
+ };
32
+
33
+ export default config;
34
+ `;
35
+ function m(e) {
36
+ let t = e.getExportAssignment((e) => !e.isExportEquals())?.getExpression();
37
+ if (t?.getKind() === d.ObjectLiteralExpression) return t;
38
+ if (t?.getKind() === d.Identifier) {
39
+ let n = t.getText(), r = e.getVariableDeclaration(n)?.getInitializer();
40
+ if (r?.getKind() === d.ObjectLiteralExpression) return r;
41
+ }
42
+ return null;
43
+ }
44
+ function h(e) {
45
+ let t = e.getProperty("extensions");
46
+ if (!t) return e.addPropertyAssignment({
47
+ name: "extensions",
48
+ initializer: "['.svelte', '.svx']"
49
+ }), !0;
50
+ if (t.getKind() !== d.PropertyAssignment) return !1;
51
+ let n = t.getInitializer();
52
+ if (!n || n.getKind() !== d.ArrayLiteralExpression) return t.setInitializer("['.svelte', '.svx']"), !0;
53
+ let r = n;
54
+ return r.getElements().some((e) => e.getText().replace(/['"`]/g, "") === ".svx") ? !1 : (r.addElement("'.svx'"), !0);
55
+ }
56
+ function g(e) {
57
+ let t = e.getProperty("preprocess");
58
+ if (!t) return e.addPropertyAssignment({
59
+ name: "preprocess",
60
+ initializer: "[mdsvex()]"
61
+ }), !0;
62
+ if (t.getKind() !== d.PropertyAssignment) return !1;
63
+ let n = t.getInitializer();
64
+ if (!n) return t.setInitializer("[mdsvex()]"), !0;
65
+ if (n.getKind() === d.ArrayLiteralExpression) {
66
+ let e = n;
67
+ return e.getElements().some((e) => /\bmdsvex\s*\(/.test(e.getText())) ? !1 : (e.addElement("mdsvex()"), !0);
68
+ }
69
+ let r = n.getText();
70
+ return /\bmdsvex\s*\(/.test(r) ? !1 : (t.setInitializer(`[${r}, mdsvex()]`), !0);
71
+ }
72
+ function _(e) {
73
+ if (!s.existsSync(e)) return {
74
+ status: "not-found",
75
+ message: p
76
+ };
77
+ let t = new l({
78
+ compilerOptions: { allowJs: !0 },
79
+ manipulationSettings: { quoteKind: u.Single }
80
+ }).addSourceFileAtPath(e), n = t.getFullText(), r = m(t);
81
+ if (!r) return {
82
+ status: "failed",
83
+ message: f
84
+ };
85
+ let a = !1;
86
+ return h(r) && (a = !0), g(r) && (a = !0), !a || (i(t, [{
87
+ namedImports: ["mdsvex"],
88
+ moduleSpecifier: "mdsvex"
89
+ }]), t.formatText(), t.getFullText() === n) ? {
90
+ status: "success",
91
+ changed: !1
92
+ } : (t.saveSync(), {
93
+ status: "success",
94
+ changed: !0
95
+ });
96
+ }
97
+ //#endregion
98
+ //#region src/patterns/enable/blog/modifies/root-layout-svelte.ts
99
+ var v, y = "import '../css/prism-vsc-dark-plus.css';", b = e(v ||= t(["\n Create src/routes/+layout.svelte and import the Prism theme for\n code block highlighting in blog posts:\n\n <script lang=\"ts\">\n import '../app.css';\n ", "\n <\/script>\n"]), y), x = e`
100
+ Import the Prism theme in your root +layout.svelte for blog code
101
+ block highlighting:
102
+
103
+ ${y}
104
+ `;
105
+ function S(e) {
106
+ if (!s.existsSync(e)) return {
107
+ status: "not-found",
108
+ message: b
109
+ };
110
+ let t = a.fromPath(e), n = t.getScript();
111
+ return n ? n.content.includes("prism-vsc-dark-plus.css") ? {
112
+ status: "success",
113
+ changed: !1
114
+ } : (t.modifyScript((e) => {
115
+ let t = e.match(/^(\s*)import\s+['"][^'"]*app\.css['"];?\s*$/m);
116
+ if (t) {
117
+ let n = `\n${t[1] ?? ""}${y}`, r = (t.index ?? 0) + t[0].length;
118
+ return e.slice(0, r) + n + e.slice(r);
119
+ }
120
+ return e.replace(/^/, `\n\t${y}\n`);
121
+ }), t.writeTo(e), {
122
+ status: "success",
123
+ changed: t.hasChanged()
124
+ }) : {
125
+ status: "failed",
126
+ message: x
127
+ };
128
+ }
129
+ //#endregion
130
+ //#region src/patterns/enable/blog/modifies/public-root-layout-svelte.ts
131
+ var C = "\n <Navbar.Item>\n <Button class=\"w-full justify-start md:justify-center md:w-auto\" href=\"/blog\" variant=\"ghost\">\n Blog\n </Button>\n </Navbar.Item>\n ", w = e`
132
+ Add a Blog link inside <Navbar.List> in the public root layout:
133
+
134
+ <Navbar.Item>
135
+ <Button class="w-full justify-start md:justify-center md:w-auto" href="/blog" variant="ghost">
136
+ Blog
137
+ </Button>
138
+ </Navbar.Item>
139
+ `, T = e`
140
+ Create a public root layout with a Blog link in its Navbar.List:
141
+
142
+ <Navbar.Item>
143
+ <Button class="w-full justify-start md:justify-center md:w-auto" href="/blog" variant="ghost">
144
+ Blog
145
+ </Button>
146
+ </Navbar.Item>
147
+ `;
148
+ function E(e) {
149
+ if (!s.existsSync(e)) return {
150
+ status: "not-found",
151
+ message: T
152
+ };
153
+ let t = a.fromPath(e);
154
+ if (!t.hasElement("Navbar.List")) return {
155
+ status: "failed",
156
+ message: w
157
+ };
158
+ let n = s.readFileSync(e, "utf8");
159
+ return /href=["']\/blog["']/.test(n) ? {
160
+ status: "success",
161
+ changed: !1
162
+ } : (t.insertBeforeClosingTag("Navbar.List", C), t.writeTo(e), {
163
+ status: "success",
164
+ changed: t.hasChanged()
165
+ });
166
+ }
167
+ //#endregion
168
+ //#region src/patterns/enable/blog/generate.runtime.ts
169
+ async function D(e) {
170
+ let t = n(e), i = [], a = (e) => {
171
+ e && i.push(e);
172
+ };
173
+ t.info("Modifying svelte.config");
174
+ let l = o(e.root);
175
+ a(r(l, _(l))), t.info("Modifying src/routes/+layout.svelte");
176
+ let u = c.join(e.root, "src", "routes", "+layout.svelte");
177
+ a(r(u, S(u))), t.info("Modifying public root layout");
178
+ let d = [
179
+ c.join(e.root, "src", "routes", "(public)", "root-layout.svelte"),
180
+ c.join(e.root, "src", "routes", "root-layout.svelte"),
181
+ c.join(e.root, "src", "routes", "(public)", "+layout.svelte")
182
+ ], f = d.find((e) => s.existsSync(e)) ?? d[0];
183
+ return a(r(f, E(f))), {
184
+ creates: [],
185
+ modifies: i,
186
+ deletes: [],
187
+ components: [],
188
+ packages: [],
189
+ collections: [],
190
+ collectionPatches: [],
191
+ collectionDrops: []
192
+ };
193
+ }
194
+ //#endregion
195
+ export { D as generate };
196
+
197
+ //# sourceMappingURL=generate.runtime-BfDfDNO9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-BfDfDNO9.js","names":[],"sources":["../../src/patterns/enable/blog/modifies/svelte.config.ts","../../src/patterns/enable/blog/modifies/root-layout-svelte.ts","../../src/patterns/enable/blog/modifies/public-root-layout-svelte.ts","../../src/patterns/enable/blog/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { ensureImports } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Enable mdsvex in your svelte.config.js:\n\n import { mdsvex } from 'mdsvex';\n\n const config = {\n extensions: ['.svelte', '.svx'],\n preprocess: [mdsvex()],\n // ...\n };\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create a Svelte config with mdsvex enabled:\n\n import adapter from '@sveltejs/adapter-auto';\n import { mdsvex } from 'mdsvex';\n\n const config = {\n extensions: ['.svelte', '.svx'],\n preprocess: [mdsvex()],\n kit: { adapter: adapter() },\n };\n\n export default config;\n`;\n\nfunction getConfigObject(\n sourceFile: import(\"ts-morph\").SourceFile,\n): ObjectLiteralExpression | null {\n const defaultExport = sourceFile.getExportAssignment(\n (ea) => !ea.isExportEquals(),\n );\n const exportedExpr = defaultExport?.getExpression();\n if (exportedExpr?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n return exportedExpr as ObjectLiteralExpression;\n }\n if (exportedExpr?.getKind() === SyntaxKind.Identifier) {\n const ident = exportedExpr.getText();\n const varDecl = sourceFile.getVariableDeclaration(ident);\n const init = varDecl?.getInitializer();\n if (init?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n return init as ObjectLiteralExpression;\n }\n }\n return null;\n}\n\nfunction ensureExtensionsSvx(obj: ObjectLiteralExpression): boolean {\n const existing = obj.getProperty(\"extensions\");\n if (!existing) {\n obj.addPropertyAssignment({\n name: \"extensions\",\n initializer: \"['.svelte', '.svx']\",\n });\n return true;\n }\n if (existing.getKind() !== SyntaxKind.PropertyAssignment) return false;\n const init = (\n existing as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!init || init.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n (existing as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"['.svelte', '.svx']\",\n );\n return true;\n }\n const arr = init as ArrayLiteralExpression;\n const hasSvx = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \".svx\");\n if (hasSvx) return false;\n arr.addElement(\"'.svx'\");\n return true;\n}\n\nfunction ensurePreprocessMdsvex(obj: ObjectLiteralExpression): boolean {\n const existing = obj.getProperty(\"preprocess\");\n if (!existing) {\n obj.addPropertyAssignment({\n name: \"preprocess\",\n initializer: \"[mdsvex()]\",\n });\n return true;\n }\n if (existing.getKind() !== SyntaxKind.PropertyAssignment) return false;\n const init = (\n existing as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!init) {\n (existing as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[mdsvex()]\",\n );\n return true;\n }\n if (init.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = init as ArrayLiteralExpression;\n const hasMdsvex = arr\n .getElements()\n .some((el) => /\\bmdsvex\\s*\\(/.test(el.getText()));\n if (hasMdsvex) return false;\n arr.addElement(\"mdsvex()\");\n return true;\n }\n const text = init.getText();\n if (/\\bmdsvex\\s*\\(/.test(text)) return false;\n (existing as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `[${text}, mdsvex()]`,\n );\n return true;\n}\n\nexport function modifySvelteConfigMdsvex(\n svelteConfigPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(svelteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(svelteConfigPath);\n const originalText = sourceFile.getFullText();\n\n const configObj = getConfigObject(sourceFile);\n if (!configObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n let changed = false;\n if (ensureExtensionsSvx(configObj)) changed = true;\n if (ensurePreprocessMdsvex(configObj)) changed = true;\n\n if (!changed) {\n return { status: \"success\", changed: false };\n }\n\n ensureImports(sourceFile, [\n { namedImports: [\"mdsvex\"], moduleSpecifier: \"mdsvex\" },\n ]);\n\n sourceFile.formatText();\n const newText = sourceFile.getFullText();\n if (newText === originalText) {\n return { status: \"success\", changed: false };\n }\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst PRISM_IMPORT = `import '../css/prism-vsc-dark-plus.css';`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/routes/+layout.svelte and import the Prism theme for\n code block highlighting in blog posts:\n\n <script lang=\"ts\">\n import '../app.css';\n ${PRISM_IMPORT}\n </script>\n`;\n\nconst FAILURE_HINT = dedent`\n Import the Prism theme in your root +layout.svelte for blog code\n block highlighting:\n\n ${PRISM_IMPORT}\n`;\n\nexport function modifyRootLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n const script = file.getScript();\n if (!script) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n if (script.content.includes(\"prism-vsc-dark-plus.css\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const appCssMatch = source.match(\n /^(\\s*)import\\s+['\"][^'\"]*app\\.css['\"];?\\s*$/m,\n );\n if (appCssMatch) {\n const indent = appCssMatch[1] ?? \"\";\n const insertion = `\\n${indent}${PRISM_IMPORT}`;\n const end = (appCssMatch.index ?? 0) + appCssMatch[0].length;\n return source.slice(0, end) + insertion + source.slice(end);\n }\n return source.replace(/^/, `\\n\\t${PRISM_IMPORT}\\n`);\n });\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst BLOG_NAVBAR_ITEM = `\n\t\t<Navbar.Item>\n\t\t\t<Button class=\"w-full justify-start md:justify-center md:w-auto\" href=\"/blog\" variant=\"ghost\">\n\t\t\t\tBlog\n\t\t\t</Button>\n\t\t</Navbar.Item>\n\t`;\n\nconst FAILURE_HINT = dedent`\n Add a Blog link inside <Navbar.List> in the public root layout:\n\n <Navbar.Item>\n <Button class=\"w-full justify-start md:justify-center md:w-auto\" href=\"/blog\" variant=\"ghost\">\n Blog\n </Button>\n </Navbar.Item>\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create a public root layout with a Blog link in its Navbar.List:\n\n <Navbar.Item>\n <Button class=\"w-full justify-start md:justify-center md:w-auto\" href=\"/blog\" variant=\"ghost\">\n Blog\n </Button>\n </Navbar.Item>\n`;\n\nexport function modifyPublicRootLayout(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const raw = fs.readFileSync(layoutPath, \"utf8\");\n if (/href=[\"']\\/blog[\"']/.test(raw)) {\n return { status: \"success\", changed: false };\n }\n\n file.insertBeforeClosingTag(\"Navbar.List\", BLOG_NAVBAR_ITEM);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { findSvelteConfigPath } from \"../../../runtime/modify-svelte-config-remote\";\nimport { modifySvelteConfigMdsvex } from \"./modifies/svelte.config\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout-svelte\";\nimport { modifyPublicRootLayout } from \"./modifies/public-root-layout-svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying svelte.config\");\n const svelteConfigPath = findSvelteConfigPath(options.root);\n pushResult(\n modifyOutcomeToFile(\n svelteConfigPath,\n modifySvelteConfigMdsvex(svelteConfigPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const rootLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(rootLayoutPath, modifyRootLayoutSvelte(rootLayoutPath)),\n );\n\n logger.info(\"Modifying public root layout\");\n const publicLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n ];\n const publicLayoutPath =\n publicLayoutCandidates.find((p) => fs.existsSync(p)) ??\n publicLayoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(\n publicLayoutPath,\n modifyPublicRootLayout(publicLayoutPath),\n ),\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":";;;;;;;;;;AAYA,IAAM,IAAe,CAAM;;;;;;;;;;GAYrB,IAAiB,CAAM;;;;;;;;;;;;;;AAe7B,SAAS,EACP,GACgC;CAIhC,IAAM,IAHgB,EAAW,qBAC9B,MAAO,CAAC,EAAG,gBAAgB,CAC7B,EACmC,eAAe;AACnD,KAAI,GAAc,SAAS,KAAK,EAAW,wBACzC,QAAO;AAET,KAAI,GAAc,SAAS,KAAK,EAAW,YAAY;EACrD,IAAM,IAAQ,EAAa,SAAS,EAE9B,IADU,EAAW,uBAAuB,EAAM,EAClC,gBAAgB;AACtC,MAAI,GAAM,SAAS,KAAK,EAAW,wBACjC,QAAO;;AAGX,QAAO;;AAGT,SAAS,EAAoB,GAAuC;CAClE,IAAM,IAAW,EAAI,YAAY,aAAa;AAC9C,KAAI,CAAC,EAKH,QAJA,EAAI,sBAAsB;EACxB,MAAM;EACN,aAAa;EACd,CAAC,EACK;AAET,KAAI,EAAS,SAAS,KAAK,EAAW,mBAAoB,QAAO;CACjE,IAAM,IACJ,EACA,gBAAgB;AAClB,KAAI,CAAC,KAAQ,EAAK,SAAS,KAAK,EAAW,uBAIzC,QAHC,EAAmD,eAClD,sBACD,EACM;CAET,IAAM,IAAM;AAMZ,QALe,EACZ,aAAa,CACb,MAAM,MAAO,EAAG,SAAS,CAAC,QAAQ,UAAU,GAAG,KAAK,OAAO,GAC3C,MACnB,EAAI,WAAW,SAAS,EACjB;;AAGT,SAAS,EAAuB,GAAuC;CACrE,IAAM,IAAW,EAAI,YAAY,aAAa;AAC9C,KAAI,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;EAAW,SAAS,EAAK,YAAY;EAAE;;;;ACxC1D,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,EAAQ,EAC3B,IAAmB,EAAE,EAErB,KAAc,MAAsB;AACxC,EAAI,KAAM,EAAS,KAAK,EAAK;;AAG/B,GAAO,KAAK,0BAA0B;CACtC,IAAM,IAAmB,EAAqB,EAAQ,KAAK;AAQ3D,CAPA,EACE,EACE,GACA,EAAyB,EAAiB,CAC3C,CACF,EAED,EAAO,KAAK,sCAAsC;CAClD,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,UACA,iBACD;AAKD,CAJA,EACE,EAAoB,GAAgB,EAAuB,EAAe,CAAC,CAC5E,EAED,EAAO,KAAK,+BAA+B;CAC3C,IAAM,IAAyB;EAC7B,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,qBAAqB;EAC1E,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,qBAAqB;EAC9D,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,iBAAiB;EACvE,EACK,IACJ,EAAuB,MAAM,MAAM,EAAG,WAAW,EAAE,CAAC,IACpD,EAAuB;AAQzB,QAPA,EACE,EACE,GACA,EAAuB,EAAiB,CACzC,CACF,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
@@ -1,5 +1,5 @@
1
1
  import { n as e } from "./logger-BpgCb-ZG.js";
2
- import { t } from "./shared-CG8Qf95D.js";
2
+ import { t } from "./shared-Bt7uM3CK.js";
3
3
  import { modifyOutcomeToFile as n } from "./modify-file-DGBe3ycw.js";
4
4
  import { i as r, o as i } from "./ts-morph-helpers-DjpZhZ7I.js";
5
5
  import a from "node:fs";
@@ -90,4 +90,4 @@ async function d(r) {
90
90
  //#endregion
91
91
  export { d as generate };
92
92
 
93
- //# sourceMappingURL=generate.runtime-CZwuYNbQ.js.map
93
+ //# sourceMappingURL=generate.runtime-Bk9nFjoW.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-CZwuYNbQ.js","names":[],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAIA,SAAgB,EAAoB,GAAwC;AAC1E,KAAI,CAAC,EAAG,WAAW,EAAgB,CACjC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAiB,EAAG,aAAa,GAAiB,OAAO,EAEzD,IADU,IAAI,GAAS,CACF,oBAAoB,EAAgB,EAEzD,IAAW,EACd,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,mBAAmB;AACpE,KAAI,CAAC,EAAU,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAE3D,IAAM,CAAC,KAAY,EAAS,cAAc;AAC1C,KAAI,CAAC,KAAY,EAAS,SAAS,KAAK,EAAW,wBACjD,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAI9C,IAAM,IADa,EAAS,cAAc,EAAW,wBAAwB,CAClD,YAAY,MAAM;AAC7C,KAAI,CAAC,KAAW,EAAQ,SAAS,KAAK,EAAW,mBAC/C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IACJ,EACA,gBAAgB;AAClB,KAAI,CAAC,KAAW,EAAQ,SAAS,KAAK,EAAW,wBAC/C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAI9C,IAAM,IADS,EACY,YAAY,UAAU;AAUjD,QATK,KAIL,EAAY,QAAQ,EAEpB,EAAW,YAAY,EACvB,EAAW,UAAU,EAEd;EACL,QAAQ;EACR,SAAS,EAAW,aAAa,KAAK;EACvC,IAXQ;EAAE,QAAQ;EAAW,SAAS;EAAO;;;;AClChD,SAAgB,EAAgB,GAAoC;A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"version":3,"file":"generate.runtime-Bk9nFjoW.js","names":[],"sources":["../../src/patterns/disable/api-keys/modifies/hooks.server.ts","../../src/patterns/disable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/disable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n if (!callExpr) return { status: \"success\", changed: false };\n\n const [firstArg] = callExpr.getArguments();\n if (!firstArg || firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp || apiProp.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"success\", changed: false };\n }\n\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!apiInit || apiInit.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n return { status: \"success\", changed: false };\n }\n\n apiKeysProp.remove();\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"success\", changed: false };\n }\n\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (!source.includes(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(source);\n let wasRemoved = false;\n\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (wasRemoved) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"API Keys\",\n \"@lucide/svelte/icons/key-round\",\n );\n if (result.wasRemoved) wasRemoved = true;\n return result.source;\n });\n };\n\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!wasRemoved) tryRemove((fn) => file.modifyScript(fn));\n\n if (!wasRemoved) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(navUserPath, file.toString(), \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\nimport { unmodifyNavUser } from \"./modifies/nav-user.svelte\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, unmodifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Reverting nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, unmodifyNavUser(navUserPath)));\n\n const collectionDrops = await planDropsForCollections([\"api_keys\"], options);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAIA,SAAgB,EAAoB,GAAwC;AAC1E,KAAI,CAAC,EAAG,WAAW,EAAgB,CACjC,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAiB,EAAG,aAAa,GAAiB,OAAO,EAEzD,IADU,IAAI,GAAS,CACF,oBAAoB,EAAgB,EAEzD,IAAW,EACd,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,mBAAmB;AACpE,KAAI,CAAC,EAAU,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAE3D,IAAM,CAAC,KAAY,EAAS,cAAc;AAC1C,KAAI,CAAC,KAAY,EAAS,SAAS,KAAK,EAAW,wBACjD,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAI9C,IAAM,IADa,EAAS,cAAc,EAAW,wBAAwB,CAClD,YAAY,MAAM;AAC7C,KAAI,CAAC,KAAW,EAAQ,SAAS,KAAK,EAAW,mBAC/C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IACJ,EACA,gBAAgB;AAClB,KAAI,CAAC,KAAW,EAAQ,SAAS,KAAK,EAAW,wBAC/C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAI9C,IAAM,IADS,EACY,YAAY,UAAU;AAUjD,QATK,KAIL,EAAY,QAAQ,EAEpB,EAAW,YAAY,EACvB,EAAW,UAAU,EAEd;EACL,QAAQ;EACR,SAAS,EAAW,aAAa,KAAK;EACvC,IAXQ;EAAE,QAAQ;EAAW,SAAS;EAAO;;;;AClChD,SAAgB,EAAgB,GAAoC;AAClE,KAAI,CAAC,EAAG,WAAW,EAAY,CAC7B,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAM,IAAS,E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, i, n as a, o, r as s, s as c, t as l } from "./_server-BCbQIYCn.js";
3
+ import { a as n, c as r, i, n as a, o, r as s, s as c, t as l } from "./_server-B3Rzajf2.js";
4
4
  import { modifyOutcomeToFile as u } from "./modify-file-DGBe3ycw.js";
5
5
  import { a as d, n as f, o as p } from "./ts-morph-helpers-DjpZhZ7I.js";
6
6
  import m from "node:fs";
@@ -306,4 +306,4 @@ async function W(e) {
306
306
  //#endregion
307
307
  export { W as generate };
308
308
 
309
- //# sourceMappingURL=generate.runtime-CdawV-C4.js.map
309
+ //# sourceMappingURL=generate.runtime-BwbTS71o.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-CdawV-C4.js","names":[],"sources":["../../src/patterns/enable/subscriptions/modifies/modify-stripe-hooks.ts","../../src/patterns/enable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-by-template.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/enable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/enable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/enable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst CRON_SNIPPET = dedent`\n cronAdd(\"stripe-subscriptions\", \"*/2 * * * *\", () => {\n const utils = require(\\`\\${__hooks}/utils.js\\`);\n utils.triggerJob(\"/api/stripe/sync/subscriptions\");\n });\n`;\n\nconst FAILURE_HINT = [\n \"Append the stripe-subscriptions cron to data/hooks/stripe.pb.js:\",\n \"\",\n CRON_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Enable payments first — data/hooks/stripe.pb.js is created by enable-payments.\",\n \"\",\n \"Once present, append:\",\n \"\",\n CRON_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyStripeHooks(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (current.includes(\"stripe-subscriptions\")) {\n return { status: \"success\", changed: false };\n }\n if (!current.includes(\"cronAdd(\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const trailing = current.endsWith(\"\\n\") ? \"\" : \"\\n\";\n const next = `${current}${trailing}\\n${CRON_SNIPPET}\\n`;\n fs.writeFileSync(filePath, next, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Wire the subscription event handlers into src/routes/webhooks/stripe/+server.ts:\n\n Add imports:\n import { handleSubscriptionCreated } from \"./handlers/subscription/created\";\n import { handleSubscriptionUpdated } from \"./handlers/subscription/updated\";\n import { handleSubscriptionDeleted } from \"./handlers/subscription/deleted\";\n\n Add switch cases inside the event.type switch:\n case \"customer.subscription.created\":\n await handleSubscriptionCreated(event.data.object, locals);\n break;\n case \"customer.subscription.updated\":\n await handleSubscriptionUpdated(event.data.object, locals);\n break;\n case \"customer.subscription.deleted\":\n await handleSubscriptionDeleted(event.data.object, locals);\n break;\n`;\n\nconst NOT_FOUND_HINT =\n \"Enable payments first — src/routes/webhooks/stripe/+server.ts is created by enable-payments.\";\n\nconst SUBSCRIPTION_CASES_SNIPPET = dedent`\n case \"customer.subscription.created\":\n await handleSubscriptionCreated(event.data.object, locals);\n break;\n\n case \"customer.subscription.updated\":\n await handleSubscriptionUpdated(event.data.object, locals);\n break;\n\n case \"customer.subscription.deleted\":\n await handleSubscriptionDeleted(event.data.object, locals);\n break;\n`;\n\nexport function modifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n if (original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n let addedCases = false;\n const { source } = withInMemoryScript(original, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"handleSubscriptionCreated\"],\n moduleSpecifier: \"./handlers/subscription/created\",\n },\n {\n namedImports: [\"handleSubscriptionUpdated\"],\n moduleSpecifier: \"./handlers/subscription/updated\",\n },\n {\n namedImports: [\"handleSubscriptionDeleted\"],\n moduleSpecifier: \"./handlers/subscription/deleted\",\n },\n ]);\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n const clauses = caseBlock.getClauses();\n const defaultClause = clauses.find(\n (c) => c.getKind() === SyntaxKind.DefaultClause,\n );\n\n // Prepend subscription cases in front of the default clause, or append\n // before the closing brace of the case block if there's no default.\n const prefix = `${SUBSCRIPTION_CASES_SNIPPET}\\n\\n`;\n if (defaultClause) {\n defaultClause.replaceWithText(prefix + defaultClause.getText());\n } else if (clauses.length > 0) {\n const last = clauses[clauses.length - 1];\n last.replaceWithText(last.getText() + `\\n\\n${SUBSCRIPTION_CASES_SNIPPET}`);\n } else {\n return;\n }\n\n sf.formatText();\n addedCases = true;\n });\n\n if (!addedCases) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(filePath, source, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Overwrites a file with the given template content, guarded by an idempotency\n * marker: if the current file already contains the marker, the modify is a\n * no-op. Used for complex rewrites where surgical AST changes aren't worth it\n * (e.g. pages that are largely replaced).\n *\n * Strips leading `// [!code highlight:N]` and `<!-- [!code highlight:N] -->`\n * lines so the same content can be shared with preview-modifies, which uses\n * those comments for documentation highlighting.\n */\nexport function modifyByTemplate(\n filePath: string,\n template: string,\n idempotencyMarker: string,\n notFoundHint: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: notFoundHint };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (current.includes(idempotencyMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(/^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm, \"\");\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.server.ts before enabling subscriptions.\",\n \"Enable auth first — the (app) layout is provided by the velastack-auth baseline.\",\n].join(\"\\n\");\n\nexport function modifyAppLayoutServer(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"loadActiveSubscription\",\n NOT_FOUND_HINT,\n );\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Pass the subscription prop to <AppSidebar> in src/routes/(app)/+layout.svelte:\",\n \"\",\n \"<AppSidebar user={data.user} meta={data.meta} subscription={data.subscription} />\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.svelte with an <AppSidebar /> that receives the subscription prop.\",\n].join(\"\\n\");\n\nexport function modifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const appended = file.appendToAttributes(\n \"AppSidebar\",\n \" subscription={data.subscription}\",\n );\n if (!appended) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst SUBSCRIPTION_TYPE = \"{ id: string; productName: string | null } | null\";\n\nconst FAILURE_HINT = [\n \"Update src/lib/components/app-sidebar.svelte to forward a subscription prop:\",\n \"\",\n \"1. Add `subscription = null` to the destructured $props() call.\",\n `2. Add \\`subscription?: ${SUBSCRIPTION_TYPE}\\` to the props type.`,\n \"3. Pass `{subscription}` to <NavUser>.\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/lib/components/app-sidebar.svelte before enabling subscriptions.\",\n].join(\"\\n\");\n\nfunction updateScript(source: string): {\n source: string;\n wasAdded: boolean;\n} {\n let wasAdded = false;\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n if (elements.some((e) => e.getName() === \"subscription\")) {\n // Already has subscription prop — no-op.\n return;\n }\n\n // Insert subscription?: ... into the props type literal if present.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n if (propTexts.some((t) => /^\\s*subscription\\??\\s*:/.test(t))) {\n continue;\n }\n propTexts.push(`subscription?: ${SUBSCRIPTION_TYPE}`);\n lit.replaceWithText(`{ ${propTexts.join(\"; \")}; }`);\n break;\n }\n }\n\n // Insert `subscription = null` before the first rest/default-only element.\n const elementTexts = elements.map((e) => e.getText());\n let insertIdx = elements.findIndex(\n (e) => e.getDotDotDotToken() || e.getInitializer(),\n );\n if (insertIdx === -1) insertIdx = elementTexts.length;\n elementTexts.splice(insertIdx, 0, \"subscription = null\");\n pattern.replaceWithText(`{ ${elementTexts.join(\", \")} }`);\n wasAdded = true;\n }\n sf.formatText();\n });\n return { source: out, wasAdded };\n}\n\nexport function modifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n if (\n original.includes(\"subscription?: {\") ||\n original.includes(\"subscription={subscription}\") ||\n original.includes(\"{subscription}\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n if (!file.hasElement(\"NavUser\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const scriptChanged = file.modifyScript(\n (src) => updateScript(src).source,\n );\n\n const templateChanged = !file.hasAttribute(\"NavUser\", \"subscription\")\n ? file.appendToAttributes(\"NavUser\", \" {subscription}\")\n : false;\n\n if (!scriptChanged && !templateChanged) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/lib/components/nav-user.svelte is missing.\",\n \"Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user.\",\n].join(\"\\n\");\n\nexport function modifyNavUser(\n filePath: string,\n template: string,\n): ModifyOutcome {\n // `planLabel` is unique to subscriptions — safe idempotency marker.\n return modifyByTemplate(filePath, template, \"planLabel\", NOT_FOUND_HINT);\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/routes/(app)/billing/+page.server.ts is missing.\",\n \"Enable payments first — subscriptions extends the billing page with plan management.\",\n].join(\"\\n\");\n\nexport function modifyBillingPageServer(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"selectPlan\",\n NOT_FOUND_HINT,\n );\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/routes/(app)/billing/+page.svelte is missing.\",\n \"Enable payments first — subscriptions extends the billing page with plan management.\",\n].join(\"\\n\");\n\nexport function modifyBillingPageSvelte(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"availablePlans\",\n NOT_FOUND_HINT,\n );\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 { modifyStripeHooks } from \"./modifies/modify-stripe-hooks\";\nimport { modifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { modifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { modifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { modifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { modifyNavUser } from \"./modifies/modify-nav-user\";\nimport { modifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { modifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Share the final-state files between preview (rendered as-is) and runtime\n// (used as overwrite templates for modifies that amount to full rewrites).\nconst previewRaw = import.meta.glob<string>(\"./preview-modifies/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nfunction template(relativePath: string): string {\n const key = `./preview-modifies/${relativePath}`;\n const content = previewRaw[key];\n if (content === undefined) {\n throw new Error(\n `Missing template for ${relativePath} in subscriptions preview-modifies`,\n );\n }\n return content;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying data/hooks/stripe.pb.js\");\n const stripeHooksPath = path.join(\n options.root,\n \"data\",\n \"hooks\",\n \"stripe.pb.js\",\n );\n pushResult(\n modifyOutcomeToFile(stripeHooksPath, modifyStripeHooks(stripeHooksPath)),\n );\n\n logger.info(\"Modifying webhooks/stripe/+server.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"+server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n modifyWebhookServer(webhookServerPath),\n ),\n );\n\n logger.info(\"Modifying (app)/+layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n modifyAppLayoutServer(\n appLayoutServerPath,\n template(\"src/routes/(app)/+layout.server.ts\"),\n ),\n ),\n );\n\n logger.info(\"Modifying (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n modifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Modifying app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, modifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Modifying nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n navUserPath,\n modifyNavUser(\n navUserPath,\n template(\"src/lib/components/nav-user.svelte\"),\n ),\n ),\n );\n\n logger.info(\"Modifying billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n modifyBillingPageServer(\n billingPageServerPath,\n template(\"src/routes/(app)/billing/+page.server.ts\"),\n ),\n ),\n );\n\n logger.info(\"Modifying billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n modifyBillingPageSvelte(\n billingPageSveltePath,\n template(\"src/routes/(app)/billing/+page.svelte\"),\n ),\n ),\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":";;;;;;;;;AAIA,IAAM,IAAe,CAAM;;;;;GAOrB,IAAe;CACnB;CACA;CACA;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAkB,GAAiC;AACjE,KAAI,CAAC,EAAG,WAAW,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C3C,CACF,EAED,EAAO,KAAK,+BAA+B;CAC3C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,OACA,cACA,qBACD;AAKD,CAJA,EACE,EAAoB,GAAgB,EAAiB,EAAe,CAAC,CACtE,EAED,EAAO,KAAK,4BAA4B;CACxC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,kBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,qCAAqC,CAC/C,CACF,CACF,EAED,EAAO,KAAK,oCAAoC;CAChD,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,kBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,2CAA2C,CACrD,CACF,CACF,EAED,EAAO,KAAK,iCAAiC;CAC7C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,eACD;AAWD,QAVA,EACE,EACE,GACA,EACE,GACA,EAAS,wCAAwC,CAClD,CACF,CACF,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAA;EAClB"}
1
+ {"version":3,"file":"generate.runtime-BwbTS71o.js","names":[],"sources":["../../src/patterns/enable/subscriptions/modifies/modify-stripe-hooks.ts","../../src/patterns/enable/subscriptions/modifies/modify-webhook-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-by-template.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-layout-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-layout-svelte.ts","../../src/patterns/enable/subscriptions/modifies/modify-app-sidebar.ts","../../src/patterns/enable/subscriptions/modifies/modify-nav-user.ts","../../src/patterns/enable/subscriptions/modifies/modify-billing-page-server.ts","../../src/patterns/enable/subscriptions/modifies/modify-billing-page-svelte.ts","../../src/patterns/enable/subscriptions/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst CRON_SNIPPET = dedent`\n cronAdd(\"stripe-subscriptions\", \"*/2 * * * *\", () => {\n const utils = require(\\`\\${__hooks}/utils.js\\`);\n utils.triggerJob(\"/api/stripe/sync/subscriptions\");\n });\n`;\n\nconst FAILURE_HINT = [\n \"Append the stripe-subscriptions cron to data/hooks/stripe.pb.js:\",\n \"\",\n CRON_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Enable payments first — data/hooks/stripe.pb.js is created by enable-payments.\",\n \"\",\n \"Once present, append:\",\n \"\",\n CRON_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyStripeHooks(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (current.includes(\"stripe-subscriptions\")) {\n return { status: \"success\", changed: false };\n }\n if (!current.includes(\"cronAdd(\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const trailing = current.endsWith(\"\\n\") ? \"\" : \"\\n\";\n const next = `${current}${trailing}\\n${CRON_SNIPPET}\\n`;\n fs.writeFileSync(filePath, next, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Wire the subscription event handlers into src/routes/webhooks/stripe/+server.ts:\n\n Add imports:\n import { handleSubscriptionCreated } from \"./handlers/subscription/created\";\n import { handleSubscriptionUpdated } from \"./handlers/subscription/updated\";\n import { handleSubscriptionDeleted } from \"./handlers/subscription/deleted\";\n\n Add switch cases inside the event.type switch:\n case \"customer.subscription.created\":\n await handleSubscriptionCreated(event.data.object, locals);\n break;\n case \"customer.subscription.updated\":\n await handleSubscriptionUpdated(event.data.object, locals);\n break;\n case \"customer.subscription.deleted\":\n await handleSubscriptionDeleted(event.data.object, locals);\n break;\n`;\n\nconst NOT_FOUND_HINT =\n \"Enable payments first — src/routes/webhooks/stripe/+server.ts is created by enable-payments.\";\n\nconst SUBSCRIPTION_CASES_SNIPPET = dedent`\n case \"customer.subscription.created\":\n await handleSubscriptionCreated(event.data.object, locals);\n break;\n\n case \"customer.subscription.updated\":\n await handleSubscriptionUpdated(event.data.object, locals);\n break;\n\n case \"customer.subscription.deleted\":\n await handleSubscriptionDeleted(event.data.object, locals);\n break;\n`;\n\nexport function modifyWebhookServer(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n if (original.includes(\"handleSubscriptionCreated\")) {\n return { status: \"success\", changed: false };\n }\n\n let addedCases = false;\n const { source } = withInMemoryScript(original, (sf) => {\n ensureImports(sf, [\n {\n namedImports: [\"handleSubscriptionCreated\"],\n moduleSpecifier: \"./handlers/subscription/created\",\n },\n {\n namedImports: [\"handleSubscriptionUpdated\"],\n moduleSpecifier: \"./handlers/subscription/updated\",\n },\n {\n namedImports: [\"handleSubscriptionDeleted\"],\n moduleSpecifier: \"./handlers/subscription/deleted\",\n },\n ]);\n\n const switchStmt = sf\n .getDescendantsOfKind(SyntaxKind.SwitchStatement)\n .find((stmt) => stmt.getExpression().getText().includes(\"event.type\"));\n if (!switchStmt) return;\n\n const caseBlock = switchStmt.getCaseBlock();\n const clauses = caseBlock.getClauses();\n const defaultClause = clauses.find(\n (c) => c.getKind() === SyntaxKind.DefaultClause,\n );\n\n // Prepend subscription cases in front of the default clause, or append\n // before the closing brace of the case block if there's no default.\n const prefix = `${SUBSCRIPTION_CASES_SNIPPET}\\n\\n`;\n if (defaultClause) {\n defaultClause.replaceWithText(prefix + defaultClause.getText());\n } else if (clauses.length > 0) {\n const last = clauses[clauses.length - 1];\n last.replaceWithText(last.getText() + `\\n\\n${SUBSCRIPTION_CASES_SNIPPET}`);\n } else {\n return;\n }\n\n sf.formatText();\n addedCases = true;\n });\n\n if (!addedCases) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(filePath, source, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/**\n * Overwrites a file with the given template content, guarded by an idempotency\n * marker: if the current file already contains the marker, the modify is a\n * no-op. Used for complex rewrites where surgical AST changes aren't worth it\n * (e.g. pages that are largely replaced).\n *\n * Strips leading `// [!code highlight:N]` and `<!-- [!code highlight:N] -->`\n * lines so the same content can be shared with preview-modifies, which uses\n * those comments for documentation highlighting.\n */\nexport function modifyByTemplate(\n filePath: string,\n template: string,\n idempotencyMarker: string,\n notFoundHint: string,\n): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: notFoundHint };\n }\n const current = fs.readFileSync(filePath, \"utf8\");\n if (current.includes(idempotencyMarker)) {\n return { status: \"success\", changed: false };\n }\n const stripped = template\n .replace(/^[ \\t]*\\/\\/[ \\t]*\\[!code highlight:\\d+\\][ \\t]*\\r?\\n/gm, \"\")\n .replace(/^[ \\t]*<!--[ \\t]*\\[!code highlight:\\d+\\][ \\t]*-->[ \\t]*\\r?\\n/gm, \"\");\n if (current === stripped) {\n return { status: \"success\", changed: false };\n }\n fs.writeFileSync(filePath, stripped, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.server.ts before enabling subscriptions.\",\n \"Enable auth first — the (app) layout is provided by the velastack-auth baseline.\",\n].join(\"\\n\");\n\nexport function modifyAppLayoutServer(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"loadActiveSubscription\",\n NOT_FOUND_HINT,\n );\n}\n","import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Pass the subscription prop to <AppSidebar> in src/routes/(app)/+layout.svelte:\",\n \"\",\n \"<AppSidebar user={data.user} meta={data.meta} subscription={data.subscription} />\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/routes/(app)/+layout.svelte with an <AppSidebar /> that receives the subscription prop.\",\n].join(\"\\n\");\n\nexport function modifyAppLayoutSvelte(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(filePath);\n if (!file.hasElement(\"AppSidebar\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasAttribute(\"AppSidebar\", \"subscription\")) {\n return { status: \"success\", changed: false };\n }\n\n const appended = file.appendToAttributes(\n \"AppSidebar\",\n \" subscription={data.subscription}\",\n );\n if (!appended) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport { SyntaxKind } from \"ts-morph\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { withInMemoryScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst SUBSCRIPTION_TYPE = \"{ id: string; productName: string | null } | null\";\n\nconst FAILURE_HINT = [\n \"Update src/lib/components/app-sidebar.svelte to forward a subscription prop:\",\n \"\",\n \"1. Add `subscription = null` to the destructured $props() call.\",\n `2. Add \\`subscription?: ${SUBSCRIPTION_TYPE}\\` to the props type.`,\n \"3. Pass `{subscription}` to <NavUser>.\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/lib/components/app-sidebar.svelte before enabling subscriptions.\",\n].join(\"\\n\");\n\nfunction updateScript(source: string): {\n source: string;\n wasAdded: boolean;\n} {\n let wasAdded = false;\n const { source: out } = withInMemoryScript(source, (sf) => {\n for (const decl of sf.getVariableDeclarations()) {\n const init = decl.getInitializer();\n if (!init || init.getText() !== \"$props()\") continue;\n\n const nameNode = decl.getNameNode();\n if (nameNode.getKind() !== SyntaxKind.ObjectBindingPattern) continue;\n const pattern = nameNode.asKindOrThrow(SyntaxKind.ObjectBindingPattern);\n const elements = pattern.getElements();\n if (elements.some((e) => e.getName() === \"subscription\")) {\n // Already has subscription prop — no-op.\n return;\n }\n\n // Insert subscription?: ... into the props type literal if present.\n const typeNode = decl.getTypeNode();\n if (typeNode?.getKind() === SyntaxKind.IntersectionType) {\n const intersection = typeNode.asKindOrThrow(\n SyntaxKind.IntersectionType,\n );\n for (const member of intersection.getTypeNodes()) {\n if (member.getKind() !== SyntaxKind.TypeLiteral) continue;\n const lit = member.asKindOrThrow(SyntaxKind.TypeLiteral);\n const propTexts = lit\n .getProperties()\n .map((p) => p.getText().replace(/[;,]\\s*$/, \"\"));\n if (propTexts.some((t) => /^\\s*subscription\\??\\s*:/.test(t))) {\n continue;\n }\n propTexts.push(`subscription?: ${SUBSCRIPTION_TYPE}`);\n lit.replaceWithText(`{ ${propTexts.join(\"; \")}; }`);\n break;\n }\n }\n\n // Insert `subscription = null` before the first rest/default-only element.\n const elementTexts = elements.map((e) => e.getText());\n let insertIdx = elements.findIndex(\n (e) => e.getDotDotDotToken() || e.getInitializer(),\n );\n if (insertIdx === -1) insertIdx = elementTexts.length;\n elementTexts.splice(insertIdx, 0, \"subscription = null\");\n pattern.replaceWithText(`{ ${elementTexts.join(\", \")} }`);\n wasAdded = true;\n }\n sf.formatText();\n });\n return { source: out, wasAdded };\n}\n\nexport function modifyAppSidebar(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n if (\n original.includes(\"subscription?: {\") ||\n original.includes(\"subscription={subscription}\") ||\n original.includes(\"{subscription}\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const file = new SvelteFile(original);\n if (!file.hasElement(\"NavUser\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const scriptChanged = file.modifyScript(\n (src) => updateScript(src).source,\n );\n\n const templateChanged = !file.hasAttribute(\"NavUser\", \"subscription\")\n ? file.appendToAttributes(\"NavUser\", \" {subscription}\")\n : false;\n\n if (!scriptChanged && !templateChanged) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.writeTo(filePath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/lib/components/nav-user.svelte is missing.\",\n \"Enable auth and payments first; subscriptions layers a plan label on top of the existing nav-user.\",\n].join(\"\\n\");\n\nexport function modifyNavUser(\n filePath: string,\n template: string,\n): ModifyOutcome {\n // `planLabel` is unique to subscriptions — safe idempotency marker.\n return modifyByTemplate(filePath, template, \"planLabel\", NOT_FOUND_HINT);\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/routes/(app)/billing/+page.server.ts is missing.\",\n \"Enable payments first — subscriptions extends the billing page with plan management.\",\n].join(\"\\n\");\n\nexport function modifyBillingPageServer(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"selectPlan\",\n NOT_FOUND_HINT,\n );\n}\n","import { modifyByTemplate } from \"./modify-by-template\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"src/routes/(app)/billing/+page.svelte is missing.\",\n \"Enable payments first — subscriptions extends the billing page with plan management.\",\n].join(\"\\n\");\n\nexport function modifyBillingPageSvelte(\n filePath: string,\n template: string,\n): ModifyOutcome {\n return modifyByTemplate(\n filePath,\n template,\n \"availablePlans\",\n NOT_FOUND_HINT,\n );\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 { modifyStripeHooks } from \"./modifies/modify-stripe-hooks\";\nimport { modifyWebhookServer } from \"./modifies/modify-webhook-server\";\nimport { modifyAppLayoutServer } from \"./modifies/modify-app-layout-server\";\nimport { modifyAppLayoutSvelte } from \"./modifies/modify-app-layout-svelte\";\nimport { modifyAppSidebar } from \"./modifies/modify-app-sidebar\";\nimport { modifyNavUser } from \"./modifies/modify-nav-user\";\nimport { modifyBillingPageServer } from \"./modifies/modify-billing-page-server\";\nimport { modifyBillingPageSvelte } from \"./modifies/modify-billing-page-svelte\";\n\n// Share the final-state files between preview (rendered as-is) and runtime\n// (used as overwrite templates for modifies that amount to full rewrites).\nconst previewRaw = import.meta.glob<string>(\"./preview-modifies/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nfunction template(relativePath: string): string {\n const key = `./preview-modifies/${relativePath}`;\n const content = previewRaw[key];\n if (content === undefined) {\n throw new Error(\n `Missing template for ${relativePath} in subscriptions preview-modifies`,\n );\n }\n return content;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying data/hooks/stripe.pb.js\");\n const stripeHooksPath = path.join(\n options.root,\n \"data\",\n \"hooks\",\n \"stripe.pb.js\",\n );\n pushResult(\n modifyOutcomeToFile(stripeHooksPath, modifyStripeHooks(stripeHooksPath)),\n );\n\n logger.info(\"Modifying webhooks/stripe/+server.ts\");\n const webhookServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"+server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n webhookServerPath,\n modifyWebhookServer(webhookServerPath),\n ),\n );\n\n logger.info(\"Modifying (app)/+layout.server.ts\");\n const appLayoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutServerPath,\n modifyAppLayoutServer(\n appLayoutServerPath,\n template(\"src/routes/(app)/+layout.server.ts\"),\n ),\n ),\n );\n\n logger.info(\"Modifying (app)/+layout.svelte\");\n const appLayoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n appLayoutSveltePath,\n modifyAppLayoutSvelte(appLayoutSveltePath),\n ),\n );\n\n logger.info(\"Modifying app-sidebar.svelte\");\n const appSidebarPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"app-sidebar.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(appSidebarPath, modifyAppSidebar(appSidebarPath)),\n );\n\n logger.info(\"Modifying nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n navUserPath,\n modifyNavUser(\n navUserPath,\n template(\"src/lib/components/nav-user.svelte\"),\n ),\n ),\n );\n\n logger.info(\"Modifying billing/+page.server.ts\");\n const billingPageServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageServerPath,\n modifyBillingPageServer(\n billingPageServerPath,\n template(\"src/routes/(app)/billing/+page.server.ts\"),\n ),\n ),\n );\n\n logger.info(\"Modifying billing/+page.svelte\");\n const billingPageSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(app)\",\n \"billing\",\n \"+page.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n billingPageSveltePath,\n modifyBillingPageSvelte(\n billingPageSveltePath,\n template(\"src/routes/(app)/billing/+page.svelte\"),\n ),\n ),\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":";;;;;;;;;AAIA,IAAM,IAAe,CAAM;;;;;GAOrB,IAAe;CACnB;CACA;CACA;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAkB,GAAiC;AACjE,KAAI,CAAC,EAAG,WAAW,EAAS,CAC1B,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAEzD,IAAM,IAAU,EAAG,aAAa,GAAU,OAAO;AACjD,KAAI,EAAQ,SAAS,uBAAuB,CAC1C,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;AAE9C,KAAI,CAAC,EAAQ,SAAS,WAAW,CAC/B,QAAO;EAAE,QAAQ;EAAU,SAAS;EAAc;CAGpD,IAAM,IAAO,GAAG,IADC,EAAQ,SAAS,KAAK,GAAG,KAAK,KACZ,IAAI,EAAa;AAEpD,QADA,EAAG,cAAc,GAAU,GAAM,OAAO,EACjC;EAAE,QAAQ;EAAW,SAAS;EAAM;;;;AC9B7C,IAAM,IAAe,CAAM;;;;;;;;;;;;;;;;;;GAoBrB,IACJ,gGAEI,IAA6B,CAAM;;;;;;;;;;;;;AAczC,SAAgB,EAAoB,GAAiC;AACnE,KAAI,CAAC,EAAG,WAAW,EAAS,CAC1B,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAGzD,IAAM,IAAW,EAAG,aAAa,GAAU,OAAO;AAClD,KAAI,EAAS,SAAS,4BAA4B,CAChD,QAAO;EAAE,QAAQ;EAAW,SAAS;EAAO;CAG9C,IAAI,IAAa,IACX,EAAE,cAAW,EAAmB,IAAW,MAAO;AACtD,IAAc,GAAI;GAChB;IACE,cAAc,CAAC,4BAA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KAC7B,EAAQ,MACR,OACA,UACA,YACA,UACA,aACD;AAQD,CAPA,EACE,EACE,GACA,EAAoB,EAAkB,CACvC,CACF,EAED,EAAO,KAAK,oCAAoC;CAChD,IAAM,IAAsB,EAAK,KAC/B,EAAQ,MACR,OACA,UACA,SACA,oBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,qCAAqC,CAC/C,CACF,CACF,EAED,EAAO,KAAK,iCAAiC;CAC7C,IAAM,IAAsB,EAAK,KAC/B,EAAQ,MACR,OACA,UACA,SACA,iBACD;AAQD,CAPA,EACE,EACE,GACA,EAAsB,EAAoB,CAC3C,CACF,EAED,EAAO,KAAK,+BAA+B;CAC3C,IAAM,IAAiB,EAAK,KAC1B,EAAQ,MACR,OACA,OACA,cACA,qBACD;AAKD,CAJA,EACE,EAAoB,GAAgB,EAAiB,EAAe,CAAC,CACtE,EAED,EAAO,KAAK,4BAA4B;CACxC,IAAM,IAAc,EAAK,KACvB,EAAQ,MACR,OACA,OACA,cACA,kBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,qCAAqC,CAC/C,CACF,CACF,EAED,EAAO,KAAK,oCAAoC;CAChD,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,kBACD;AAWD,CAVA,EACE,EACE,GACA,EACE,GACA,EAAS,2CAA2C,CACrD,CACF,CACF,EAED,EAAO,KAAK,iCAAiC;CAC7C,IAAM,IAAwB,EAAK,KACjC,EAAQ,MACR,OACA,UACA,SACA,WACA,eACD;AAWD,QAVA,EACE,EACE,GACA,EACE,GACA,EAAS,wCAAwC,CAClD,CACF,CACF,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAA;EAClB"}
@@ -488,4 +488,4 @@ async function L(e) {
488
488
  //#endregion
489
489
  export { L as generate };
490
490
 
491
- //# sourceMappingURL=generate.runtime-DgYEht-Z.js.map
491
+ //# sourceMappingURL=generate.runtime-C2Ev291A.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-DgYEht-Z.js","names":[],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/svelte-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/+layout.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as import(\"ts-morph\").ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n sourceFile.formatText();\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ObjectLiteralExpression,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your Svelte config:\",\n \"\",\n \"kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Svelte config with the $locales alias:\",\n \"\",\n \"/** @type {import('@sveltejs/kit').Config} */\",\n \"const config = {\",\n \" kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \" },\",\n \"};\",\n \"\",\n \"export default config;\",\n].join(\"\\n\");\n\nfunction getOrCreateObjectLiteralProperty(\n obj: ObjectLiteralExpression,\n name: string,\n initializer: string,\n): ObjectLiteralExpression | null {\n const prop = obj.getProperty(name);\n if (!prop) {\n obj.addPropertyAssignment({ name, initializer });\n const added = obj.getProperty(name);\n if (!added || added.getKind() !== SyntaxKind.PropertyAssignment)\n return null;\n const init = (\n added as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!init || init.getKind() !== SyntaxKind.ObjectLiteralExpression)\n return null;\n return init as ObjectLiteralExpression;\n }\n\n if (prop.getKind() !== SyntaxKind.PropertyAssignment) return null;\n const init = (prop as import(\"ts-morph\").PropertyAssignment).getInitializer();\n if (!init) return null;\n if (init.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n (prop as import(\"ts-morph\").PropertyAssignment).setInitializer(initializer);\n const init2 = (\n prop as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n return init2 && init2.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (init2 as ObjectLiteralExpression)\n : null;\n }\n\n return init as ObjectLiteralExpression;\n}\n\nexport function modifySvelteConfig(svelteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(svelteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(svelteConfigPath);\n\n const defaultExport = sourceFile.getExportAssignment(\n (ea) => !ea.isExportEquals(),\n );\n const exportedExpr = defaultExport?.getExpression();\n\n let configObj: ObjectLiteralExpression | null = null;\n if (exportedExpr?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = exportedExpr as ObjectLiteralExpression;\n } else if (exportedExpr?.getKind() === SyntaxKind.Identifier) {\n const ident = exportedExpr.getText();\n const varDecl = sourceFile.getVariableDeclaration(ident);\n const init = varDecl?.getInitializer();\n if (init?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = init as ObjectLiteralExpression;\n }\n }\n\n if (!configObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const kitObj = getOrCreateObjectLiteralProperty(configObj, \"kit\", \"{}\");\n if (!kitObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const aliasObj = getOrCreateObjectLiteralProperty(kitObj, \"alias\", \"{}\");\n if (!aliasObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const existingLocales = aliasObj.getProperty(\"$locales\");\n if (!existingLocales) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (existingLocales.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const init = (\n existingLocales as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current === \"src/locales\") return { status: \"success\", changed: false };\n\n (existingLocales as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"'src/locales'\",\n );\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with an i18n handle:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = handleWuchale;\n`;\n\nfunction ensureNamedImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n name: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) {\n const has = existing.getNamedImports().some((ni) => ni.getName() === name);\n if (!has) existing.addNamedImport(name);\n return;\n }\n sourceFile.addImportDeclaration({ namedImports: [name], moduleSpecifier });\n}\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const handleDecl = sourceFile.getVariableDeclaration(\"handle\");\n if (!handleDecl) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const handleStmt = handleDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!handleStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"$locales/main.url\", \"getLocale\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"locales\");\n ensureNamespaceImport(\n sourceFile,\n \"$locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"$locales/js.loader.server.js\", \"js\");\n\n const statements = sourceFile.getStatements();\n const handleStmtIndex = statements.findIndex((s) => s === handleStmt);\n const i18nHandleName = \"handleWuchale\";\n\n const startupSnippet = dedent`\n loadLocales(main.key, main.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${i18nHandleName} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\n\n if (handleStmtIndex >= 0) {\n sourceFile.insertStatements(\n handleStmtIndex,\n `\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`,\n );\n } else {\n sourceFile.addStatements(`\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`);\n }\n\n const init = handleDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const initText = init.getText();\n if (initText.includes(i18nHandleName) || initText.includes(\"runWithLocale\")) {\n return { status: \"success\", changed: false };\n }\n\n handleDecl.setInitializer(`sequence(${i18nHandleName}, ${initText})`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n if (/lang\\s*=/.test(match)) {\n return match;\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LOAD_SNIPPET = dedent`\n import { browser } from '$app/environment';\n import { loadLocale } from 'wuchale/load-utils';\n\n import { getLocale } from '$locales/main.url';\n import '$locales/main.loader.svelte';\n import '$locales/js.loader';\n\n export const load = async ({ url, data }) => {\n const locale = getLocale(url);\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return data;\n };\n`;\n\nconst FAILURE_HINT = [\n \"Merge the wuchale loader into your existing load function in +layout.ts:\",\n \"\",\n LOAD_SNIPPET,\n].join(\"\\n\");\n\nexport function ensureRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (fs.existsSync(layoutPath)) {\n const existing = fs.readFileSync(layoutPath, \"utf8\");\n if (existing.includes(\"loadLocale\") || existing.includes(\"translateUrl\")) {\n return { status: \"success\", changed: false };\n }\n\n if (/\\bexport\\s+(const|function)\\s+load\\b/.test(existing)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n }\n\n fs.mkdirSync(path.dirname(layoutPath), { recursive: true });\n fs.writeFileSync(layoutPath, LOAD_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '$lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"$lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\n\nfunction findFirstExistingFile(root: string, candidates: string[]): string {\n for (const relPath of candidates) {\n const absPath = path.join(root, relPath);\n if (fs.existsSync(absPath)) {\n return absPath;\n }\n }\n return path.join(root, candidates[0]);\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath = findFirstExistingFile(options.root, [\n \"vite.config.ts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n \"vite.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Modifying svelte.config\");\n const svelteConfigPath = findFirstExistingFile(options.root, [\n \"svelte.config.ts\",\n \"svelte.config.js\",\n \"svelte.config.mjs\",\n \"svelte.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(svelteConfigPath, modifySvelteConfig(svelteConfigPath)),\n );\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n rootLayoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath),\n ),\n );\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAIA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAiB,GAAuC;AACtE,KAAI,CAAC,EAAG,WAAW,EAAe,CAChC,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAOzD,IAAM,IAJU,IAAI,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,IAAM;EAClC,sBAAsB,EAAE,WAAW,EA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,KAAK,wCAAwC;CACpD,IAAM,IAAuB;EAC3B,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,qBAAqB;EAC1E,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,qBAAqB;EAC9D,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,YAAY,iBAAiB;EACtE,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,iBAAiB;EAC3D,EACK,IACJ,EAAqB,MAAM,MAAM,EAAG,WAAW,EAAE,CAAC,IAClD,EAAqB;AAQvB,CAPA,EACE,EACE,GACA,EAA+B,EAAe,CAC/C,CACF,EAED,EAAO,KAAK,sBAAsB;CAClC,IAAM,IAAgB,EAAK,KAAK,EAAQ,MAAM,aAAa;AAK3D,QAJA,EACE,EAAoB,GAAe,EAAgB,EAAc,CAAC,CACnE,EAEM;EACL,SAAS,EAAE;EACX;EACA,SAAS,EAAE;EACX,YAAY,EAAE;EACd,UAAU,EAAE;EACZ,aAAa,EAAE;EACf,mBAAmB,EAAE;EACrB,iBAAiB,EAAE;EACpB"}
1
+ {"version":3,"file":"generate.runtime-C2Ev291A.js","names":[],"sources":["../../src/patterns/enable/i18n/modifies/vite-config.ts","../../src/patterns/enable/i18n/modifies/svelte-config.ts","../../src/patterns/enable/i18n/modifies/hooks.server.ts","../../src/patterns/enable/i18n/modifies/app-html.ts","../../src/patterns/enable/i18n/modifies/gitignore.ts","../../src/patterns/enable/i18n/modifies/+layout.ts","../../src/patterns/enable/i18n/modifies/root-layout.svelte.ts","../../src/patterns/enable/i18n/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the wuchale plugin to your Vite config:\",\n \"\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the wuchale plugin:\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { wuchale } from 'wuchale/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [wuchale()],\",\n \"});\",\n].join(\"\\n\");\n\nexport function modifyViteConfig(viteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"wuchale/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"wuchale\"],\n moduleSpecifier: \"wuchale/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as import(\"ts-morph\").ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: \"[wuchale()]\",\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (\n pluginsProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"[wuchale()]\",\n );\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasWuchale = arr\n .getElements()\n .some((el) => el.getText().replace(/\\s/g, \"\") === \"wuchale()\");\n\n if (!hasWuchale) {\n arr.insertElement(0, \"wuchale()\");\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n sourceFile.formatText();\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ObjectLiteralExpression,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the $locales alias to your Svelte config:\",\n \"\",\n \"kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \"},\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Svelte config with the $locales alias:\",\n \"\",\n \"/** @type {import('@sveltejs/kit').Config} */\",\n \"const config = {\",\n \" kit: {\",\n \" alias: {\",\n \" $locales: 'src/locales',\",\n \" },\",\n \" },\",\n \"};\",\n \"\",\n \"export default config;\",\n].join(\"\\n\");\n\nfunction getOrCreateObjectLiteralProperty(\n obj: ObjectLiteralExpression,\n name: string,\n initializer: string,\n): ObjectLiteralExpression | null {\n const prop = obj.getProperty(name);\n if (!prop) {\n obj.addPropertyAssignment({ name, initializer });\n const added = obj.getProperty(name);\n if (!added || added.getKind() !== SyntaxKind.PropertyAssignment)\n return null;\n const init = (\n added as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (!init || init.getKind() !== SyntaxKind.ObjectLiteralExpression)\n return null;\n return init as ObjectLiteralExpression;\n }\n\n if (prop.getKind() !== SyntaxKind.PropertyAssignment) return null;\n const init = (prop as import(\"ts-morph\").PropertyAssignment).getInitializer();\n if (!init) return null;\n if (init.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n (prop as import(\"ts-morph\").PropertyAssignment).setInitializer(initializer);\n const init2 = (\n prop as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n return init2 && init2.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (init2 as ObjectLiteralExpression)\n : null;\n }\n\n return init as ObjectLiteralExpression;\n}\n\nexport function modifySvelteConfig(svelteConfigPath: string): ModifyOutcome {\n if (!fs.existsSync(svelteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(svelteConfigPath);\n\n const defaultExport = sourceFile.getExportAssignment(\n (ea) => !ea.isExportEquals(),\n );\n const exportedExpr = defaultExport?.getExpression();\n\n let configObj: ObjectLiteralExpression | null = null;\n if (exportedExpr?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = exportedExpr as ObjectLiteralExpression;\n } else if (exportedExpr?.getKind() === SyntaxKind.Identifier) {\n const ident = exportedExpr.getText();\n const varDecl = sourceFile.getVariableDeclaration(ident);\n const init = varDecl?.getInitializer();\n if (init?.getKind() === SyntaxKind.ObjectLiteralExpression) {\n configObj = init as ObjectLiteralExpression;\n }\n }\n\n if (!configObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const kitObj = getOrCreateObjectLiteralProperty(configObj, \"kit\", \"{}\");\n if (!kitObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const aliasObj = getOrCreateObjectLiteralProperty(kitObj, \"alias\", \"{}\");\n if (!aliasObj) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const existingLocales = aliasObj.getProperty(\"$locales\");\n if (!existingLocales) {\n aliasObj.addPropertyAssignment({\n name: \"$locales\",\n initializer: \"'src/locales'\",\n });\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (existingLocales.getKind() !== SyntaxKind.PropertyAssignment) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n const init = (\n existingLocales as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n const current = init?.getText()?.replace(/['\"`]/g, \"\");\n if (current === \"src/locales\") return { status: \"success\", changed: false };\n\n (existingLocales as import(\"ts-morph\").PropertyAssignment).setInitializer(\n \"'src/locales'\",\n );\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = dedent`\n Wrap your exported handle with the wuchale i18n handler:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = sequence(handleWuchale, /* your existing handle */);\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with an i18n handle:\n\n import { sequence } from '@sveltejs/kit/hooks';\n import { runWithLocale, loadLocales } from 'wuchale/load-utils/server';\n import { getLocale } from '$locales/main.url';\n import { locales } from '$locales/data';\n import * as main from '$locales/main.loader.server.svelte.js';\n import * as js from '$locales/js.loader.server.js';\n\n loadLocales(main.key, main.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, js.loadCatalog, locales);\n\n const handleWuchale = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale),\n }),\n );\n };\n\n export const handle = handleWuchale;\n`;\n\nfunction ensureNamedImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n name: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) {\n const has = existing.getNamedImports().some((ni) => ni.getName() === name);\n if (!has) existing.addNamedImport(name);\n return;\n }\n sourceFile.addImportDeclaration({ namedImports: [name], moduleSpecifier });\n}\n\nfunction ensureNamespaceImport(\n sourceFile: import(\"ts-morph\").SourceFile,\n moduleSpecifier: string,\n ns: string,\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({ namespaceImport: ns, moduleSpecifier });\n}\n\nexport function modifyHooksServerI18n(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(hooksServerPath, \"utf8\");\n if (original.includes(\"runWithLocale\") || original.includes(\"loadLocales(\")) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const handleDecl = sourceFile.getVariableDeclaration(\"handle\");\n if (!handleDecl) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const handleStmt = handleDecl.getFirstAncestorByKind(\n SyntaxKind.VariableStatement,\n );\n if (!handleStmt?.hasExportKeyword()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n ensureNamedImport(sourceFile, \"@sveltejs/kit/hooks\", \"sequence\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"runWithLocale\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils/server\", \"loadLocales\");\n ensureNamedImport(sourceFile, \"$locales/main.url\", \"getLocale\");\n ensureNamedImport(sourceFile, \"$locales/data\", \"locales\");\n ensureNamespaceImport(\n sourceFile,\n \"$locales/main.loader.server.svelte.js\",\n \"main\",\n );\n ensureNamespaceImport(sourceFile, \"$locales/js.loader.server.js\", \"js\");\n\n const statements = sourceFile.getStatements();\n const handleStmtIndex = statements.findIndex((s) => s === handleStmt);\n const i18nHandleName = \"handleWuchale\";\n\n const startupSnippet = dedent`\n loadLocales(main.key, main.loadIDs, main.loadCatalog, locales);\n loadLocales(js.key, js.loadIDs, js.loadCatalog, locales);\n `;\n\n const i18nHandleSnippet = dedent`\n const ${i18nHandleName} = async ({ event, resolve }: any) => {\n const locale = getLocale(event.url);\n return await runWithLocale(locale, () =>\n resolve(event, {\n transformPageChunk: ({ html }: { html: string }) =>\n html.replace('%sveltekit.lang%', locale)\n })\n );\n };\n `;\n\n if (handleStmtIndex >= 0) {\n sourceFile.insertStatements(\n handleStmtIndex,\n `\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`,\n );\n } else {\n sourceFile.addStatements(`\\n${startupSnippet}\\n\\n${i18nHandleSnippet}\\n`);\n }\n\n const init = handleDecl.getInitializer();\n if (!init) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const initText = init.getText();\n if (initText.includes(i18nHandleName) || initText.includes(\"runWithLocale\")) {\n return { status: \"success\", changed: false };\n }\n\n handleDecl.setInitializer(`sequence(${i18nHandleName}, ${initText})`);\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the sveltekit lang placeholder to the <html> tag:\",\n \"\",\n '<html lang=\"%sveltekit.lang%\">',\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create src/app.html with a lang placeholder:\",\n \"\",\n \"<!doctype html>\",\n '<html lang=\"%sveltekit.lang%\">',\n \" <head>\",\n ' <meta charset=\"utf-8\" />',\n \" %sveltekit.head%\",\n \" </head>\",\n ' <body data-sveltekit-preload-data=\"hover\">',\n ' <div style=\"display: contents\">%sveltekit.body%</div>',\n \" </body>\",\n \"</html>\",\n].join(\"\\n\");\n\nexport function modifyAppHtml(appHtmlPath: string): ModifyOutcome {\n if (!fs.existsSync(appHtmlPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(appHtmlPath, \"utf8\");\n if (\n original.includes('lang=\"%sveltekit.lang%\"') ||\n original.includes(\"lang='%sveltekit.lang%'\")\n ) {\n return { status: \"success\", changed: false };\n }\n\n const updated = original.replace(/<html(\\s[^>]*?)?>/i, (match) => {\n if (/lang\\s*=/.test(match)) {\n return match;\n }\n return match.replace(/<html/i, '<html lang=\"%sveltekit.lang%\"');\n });\n\n if (updated === original) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n fs.writeFileSync(appHtmlPath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst NOT_FOUND_HINT = [\n \"Create a .gitignore with the wuchale cache ignored:\",\n \"\",\n \"# Wuchale\",\n \"src/locales/.wuchale\",\n].join(\"\\n\");\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n if (original.includes(\"src/locales/.wuchale\")) {\n return { status: \"success\", changed: false };\n }\n\n const block = dedent`\n # Wuchale\n src/locales/.wuchale\n `;\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const updated = original + (needsNewline ? \"\\n\" : \"\") + \"\\n\" + block + \"\\n\";\n fs.writeFileSync(gitignorePath, updated);\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LOAD_SNIPPET = dedent`\n import { browser } from '$app/environment';\n import { loadLocale } from 'wuchale/load-utils';\n\n import { getLocale } from '$locales/main.url';\n import '$locales/main.loader.svelte';\n import '$locales/js.loader';\n\n export const load = async ({ url, data }) => {\n const locale = getLocale(url);\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return data;\n };\n`;\n\nconst FAILURE_HINT = [\n \"Merge the wuchale loader into your existing load function in +layout.ts:\",\n \"\",\n LOAD_SNIPPET,\n].join(\"\\n\");\n\nexport function ensureRootLayoutI18n(layoutPath: string): ModifyOutcome {\n if (fs.existsSync(layoutPath)) {\n const existing = fs.readFileSync(layoutPath, \"utf8\");\n if (existing.includes(\"loadLocale\") || existing.includes(\"translateUrl\")) {\n return { status: \"success\", changed: false };\n }\n\n if (/\\bexport\\s+(const|function)\\s+load\\b/.test(existing)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n }\n\n fs.mkdirSync(path.dirname(layoutPath), { recursive: true });\n fs.writeFileSync(layoutPath, LOAD_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst LANGUAGE_SELECT_SNIPPET = `<Navbar.Item>\n\t\t\t\t<LanguageSelect />\n\t\t\t</Navbar.Item>\n\t\t\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '$lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes a language select inside <Navbar.List>.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup at the end of <Navbar.List>:\",\n LANGUAGE_SELECT_SNIPPET,\n].join(\"\\n\");\n\nexport function modifyRootLayoutLanguageSelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n defaultImport: \"LanguageSelect\",\n moduleSpecifier: \"$lib/components/language-select.svelte\",\n },\n ]);\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport { modifySvelteConfig } from \"./modifies/svelte-config\";\nimport { modifyHooksServerI18n } from \"./modifies/hooks.server\";\nimport { modifyAppHtml } from \"./modifies/app-html\";\nimport { modifyGitignore } from \"./modifies/gitignore\";\nimport { ensureRootLayoutI18n } from \"./modifies/+layout\";\nimport { modifyRootLayoutLanguageSelect } from \"./modifies/root-layout.svelte\";\n\nfunction findFirstExistingFile(root: string, candidates: string[]): string {\n for (const relPath of candidates) {\n const absPath = path.join(root, relPath);\n if (fs.existsSync(absPath)) {\n return absPath;\n }\n }\n return path.join(root, candidates[0]);\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath = findFirstExistingFile(options.root, [\n \"vite.config.ts\",\n \"vite.config.js\",\n \"vite.config.mjs\",\n \"vite.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(viteConfigPath, modifyViteConfig(viteConfigPath)),\n );\n\n logger.info(\"Modifying svelte.config\");\n const svelteConfigPath = findFirstExistingFile(options.root, [\n \"svelte.config.ts\",\n \"svelte.config.js\",\n \"svelte.config.mjs\",\n \"svelte.config.cjs\",\n ]);\n pushResult(\n modifyOutcomeToFile(svelteConfigPath, modifySvelteConfig(svelteConfigPath)),\n );\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerI18n(hooksServerPath),\n ),\n );\n\n logger.info(\"Modifying app.html\");\n const appHtmlPath = path.join(options.root, \"src\", \"app.html\");\n pushResult(modifyOutcomeToFile(appHtmlPath, modifyAppHtml(appHtmlPath)));\n\n logger.info(\"Modifying root +layout.ts\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.ts\");\n pushResult(modifyOutcomeToFile(layoutPath, ensureRootLayoutI18n(layoutPath)));\n\n logger.info(\"Modifying root layout language select\");\n const rootLayoutCandidates = [\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"root-layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"(public)\", \"+layout.svelte\"),\n path.join(options.root, \"src\", \"routes\", \"+layout.svelte\"),\n ];\n const rootLayoutPath =\n rootLayoutCandidates.find((p) => fs.existsSync(p)) ??\n rootLayoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyRootLayoutLanguageSelect(rootLayoutPath),\n ),\n );\n\n logger.info(\"Updating .gitignore\");\n const gitignorePath = path.join(options.root, \".gitignore\");\n pushResult(\n modifyOutcomeToFile(gitignorePath, modifyGitignore(gitignorePath)),\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;AAIA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK,EAEN,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,KAAK,KAAK;AAEZ,SAAgB,EAAiB,GAAuC;AACtE,KAAI,CAAC,EAAG,WAAW,EAAe,CAChC,QAAO;EAAE,QAAQ;EAAa,SAAS;EAAgB;CAOzD,IAAM,IAJU,IAAI,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,IAAM;EAClC,sBAAsB,EAAE,WAAW,EAAU,QAAQ;EACtD,CAAC,CACyB,oBAAoB,EAAe,EAE1D,IAAU,IACV,IAAS;AAMb,CAJkB,EACf,uBAAuB,CACvB,MAAM,MAAM,EAAE,yBAAyB,KAAK,eAAe,KAG5D,EAAW,wBAAwB,GAAG;EACpC,cAAc,CAAC,UAAU;EACzB,iBAAiB;EAClB,CAAC,EACF,IAAU;CAOZ,IAAM,IAJmB,EACtB,qBAAqB,EAAW,eAAe,CAC/C,MAAM,MAAO,EAAG,eAAe,CAAC,SAAS,KAAK,eAAe,EAE5B,cAAc,GAAG,IAC/C,IACJ,GAAW,SAAS,KAAK,EAAW,0BAC/B,IACD;AAEN,KAAI,CAAC,EACH,KAAS;MACJ;EACL,IAAM,IAAc,EAAU,YAAY,UAAU;AACpD,MAAI,CAAC,EAKH,CAJA,EAAU,sBAAsB;GAC9B,MAAM;GACN,aAAa;GACd,CAAC,EACF,IAAU;WACD,EAAY,SAAS,KAAK,EAAW,mBAC9C,KAAS;OACJ;GACL,IAAM,IACJ,EACA,gBAAgB;AAElB,OAAI,CAAC,EAIH,C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