@velastack/patterns 0.13.1 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/app-d-ts-h33RrYIv.js +198 -0
- package/dist/chunks/app-d-ts-h33RrYIv.js.map +1 -0
- package/dist/chunks/app-layout.svelte-CZ0hw-pi.js +51 -0
- package/dist/chunks/app-layout.svelte-CZ0hw-pi.js.map +1 -0
- package/dist/chunks/{generate.runtime-DHJqOJTr.js → generate.runtime-Bv_16lWi.js} +2 -2
- package/dist/chunks/{generate.runtime-DHJqOJTr.js.map → generate.runtime-Bv_16lWi.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DvTbN-no.js → generate.runtime-CZKIKP3B.js} +213 -175
- package/dist/chunks/generate.runtime-CZKIKP3B.js.map +1 -0
- package/dist/chunks/{generate.runtime-BEmSIAop.js → generate.runtime-C_SdcnRs.js} +2 -2
- package/dist/chunks/{generate.runtime-BEmSIAop.js.map → generate.runtime-C_SdcnRs.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DGnXHELM.js → generate.runtime-CsP4c8GY.js} +78 -77
- package/dist/chunks/generate.runtime-CsP4c8GY.js.map +1 -0
- package/dist/chunks/{generate.runtime-DWHoDisZ.js → generate.runtime-CzYArKUA.js} +2 -2
- package/dist/chunks/{generate.runtime-DWHoDisZ.js.map → generate.runtime-CzYArKUA.js.map} +1 -1
- package/dist/chunks/generate.runtime-DZUPtJVF.js +429 -0
- package/dist/chunks/generate.runtime-DZUPtJVF.js.map +1 -0
- package/dist/chunks/{generate.runtime-Cgam_XCc.js → generate.runtime-DaPA2NNL.js} +2 -2
- package/dist/chunks/{generate.runtime-Cgam_XCc.js.map → generate.runtime-DaPA2NNL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-i3tMIA1A.js → generate.runtime-pbIrEsa7.js} +45 -45
- package/dist/chunks/generate.runtime-pbIrEsa7.js.map +1 -0
- package/dist/chunks/i18n-BHCytiiO.js +28 -0
- package/dist/chunks/i18n-BHCytiiO.js.map +1 -0
- package/dist/chunks/test-setup-cZj1tqaf.js +176 -0
- package/dist/chunks/test-setup-cZj1tqaf.js.map +1 -0
- package/dist/chunks/translations-CiJnl574.js +189 -0
- package/dist/chunks/translations-CiJnl574.js.map +1 -0
- package/dist/chunks/{ui-Ct6YQuPw.js → ui-IkdkLwmB.js} +2 -2
- package/dist/chunks/{ui-Ct6YQuPw.js.map → ui-IkdkLwmB.js.map} +1 -1
- package/dist/chunks/write-result-C1GYInL8.js +499 -0
- package/dist/chunks/write-result-C1GYInL8.js.map +1 -0
- package/dist/index.js +735 -725
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/_layout-Dju9EYqa.js +0 -60
- package/dist/chunks/_layout-Dju9EYqa.js.map +0 -1
- package/dist/chunks/generate.runtime-DGnXHELM.js.map +0 -1
- package/dist/chunks/generate.runtime-Dtf3tF3-.js +0 -316
- package/dist/chunks/generate.runtime-Dtf3tF3-.js.map +0 -1
- package/dist/chunks/generate.runtime-DvTbN-no.js.map +0 -1
- package/dist/chunks/generate.runtime-i3tMIA1A.js.map +0 -1
- package/dist/chunks/test-setup-CbwhAJT4.js +0 -176
- package/dist/chunks/test-setup-CbwhAJT4.js.map +0 -1
- package/dist/chunks/write-result-B5KFCqxw.js +0 -487
- package/dist/chunks/write-result-B5KFCqxw.js.map +0 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { t as e } from "./dedent-CCUOcPFW.js";
|
|
2
|
+
import { i as t, o as n, r } from "./ts-morph-helpers-B4KZXP44.js";
|
|
3
|
+
import { t as i } from "./package-imports-CcIIHbp5.js";
|
|
4
|
+
import { a, c as o, i as s, l as c, r as l, s as u } from "./load-function-BFvIVsh7.js";
|
|
5
|
+
import d from "node:fs";
|
|
6
|
+
import f from "node:path";
|
|
7
|
+
import { Node as p, Project as m, QuoteKind as h } from "ts-morph";
|
|
8
|
+
// src/patterns/enable/i18n/modifies/prettierignore.ts
|
|
9
|
+
var g = "src/locales/", _ = "# Wuchale";
|
|
10
|
+
function v(e) {
|
|
11
|
+
if (!d.existsSync(e)) return {
|
|
12
|
+
status: "success",
|
|
13
|
+
changed: !1
|
|
14
|
+
};
|
|
15
|
+
let t = d.readFileSync(e, "utf8");
|
|
16
|
+
if (t.split("\n").some((e) => e.trim().replace(/^\//, "") === "src/locales/")) return {
|
|
17
|
+
status: "success",
|
|
18
|
+
changed: !1
|
|
19
|
+
};
|
|
20
|
+
let n = t.length > 0 && !t.endsWith("\n"), r = t.length > 0 ? "\n" : "";
|
|
21
|
+
return d.writeFileSync(e, `${t}${n ? "\n" : ""}${r}${_}\n${g}\n`), {
|
|
22
|
+
status: "success",
|
|
23
|
+
changed: !0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// src/patterns/enable/i18n/modifies/package-imports.ts
|
|
27
|
+
var y = { "#locales/*": "./src/locales/*" };
|
|
28
|
+
function b(e) {
|
|
29
|
+
return i(e, y);
|
|
30
|
+
}
|
|
31
|
+
// src/patterns/enable/i18n/modifies/+layout.ts
|
|
32
|
+
var x = e`
|
|
33
|
+
import { browser } from '$app/env';
|
|
34
|
+
import { loadLocale } from 'wuchale/load-utils';
|
|
35
|
+
|
|
36
|
+
import { getLocale } from '#locales/main.url.js';
|
|
37
|
+
import { hasLocalizedUrl } from '#lib/url.js';
|
|
38
|
+
import '#locales/main.loader.svelte.js';
|
|
39
|
+
import '#locales/js.loader.js';
|
|
40
|
+
`, S = e`
|
|
41
|
+
export const load = async ({ url, data }) => {
|
|
42
|
+
// A public page's language is in its URL. The others follow the visitor's
|
|
43
|
+
// preference, which only the server knows: see src/lib/locale.ts.
|
|
44
|
+
const locale = hasLocalizedUrl(url.pathname) ? getLocale(url) : data.locale;
|
|
45
|
+
|
|
46
|
+
if (browser) {
|
|
47
|
+
await loadLocale(locale);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { ...data, locale };
|
|
51
|
+
};
|
|
52
|
+
`, C = e`
|
|
53
|
+
export const load = async ({ url, data }) => {
|
|
54
|
+
const locale = getLocale(url);
|
|
55
|
+
|
|
56
|
+
if (browser) {
|
|
57
|
+
await loadLocale(locale);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return data;
|
|
61
|
+
};
|
|
62
|
+
`, w = `${x}\n\n${S}`, T = [
|
|
63
|
+
"Merge the wuchale loader into your existing load function in +layout.ts:",
|
|
64
|
+
"",
|
|
65
|
+
w
|
|
66
|
+
].join("\n");
|
|
67
|
+
function E(e) {
|
|
68
|
+
if (!d.existsSync(e)) return d.mkdirSync(f.dirname(e), { recursive: !0 }), d.writeFileSync(e, w + "\n"), {
|
|
69
|
+
status: "success",
|
|
70
|
+
changed: !0
|
|
71
|
+
};
|
|
72
|
+
let i = d.readFileSync(e, "utf8");
|
|
73
|
+
if (i.includes("loadLocale") || i.includes("translateUrl")) return {
|
|
74
|
+
status: "success",
|
|
75
|
+
changed: !1
|
|
76
|
+
};
|
|
77
|
+
if (/\bexport\s+(const|function)\s+load\b/.test(i)) return {
|
|
78
|
+
status: "failed",
|
|
79
|
+
message: T
|
|
80
|
+
};
|
|
81
|
+
let a = new m({
|
|
82
|
+
compilerOptions: { allowJs: !0 },
|
|
83
|
+
manipulationSettings: { quoteKind: h.Single }
|
|
84
|
+
}).addSourceFileAtPath(e);
|
|
85
|
+
return t(a, "$app/env", "browser"), t(a, "wuchale/load-utils", "loadLocale"), t(a, "#locales/main.url.js", "getLocale"), t(a, "#lib/url.js", "hasLocalizedUrl"), r(a, [{ moduleSpecifier: "#locales/main.loader.svelte.js" }, { moduleSpecifier: "#locales/js.loader.js" }]), a.addStatements(`\n${S}\n`), n(a), a.saveSync(), {
|
|
86
|
+
status: "success",
|
|
87
|
+
changed: !0
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// src/patterns/enable/i18n/modifies/layout.server.ts
|
|
91
|
+
var D = e`
|
|
92
|
+
import type { LayoutServerLoad } from './$types';
|
|
93
|
+
|
|
94
|
+
export const load: LayoutServerLoad = async ({ locals }) => {
|
|
95
|
+
// Decided on the server (src/hooks.server.ts), because pages without a
|
|
96
|
+
// language in their URL follow the visitor's preference.
|
|
97
|
+
return { locale: locals.locale };
|
|
98
|
+
};
|
|
99
|
+
`, O = "Return the request's language from the load in src/routes/+layout.server.ts:\n\nreturn {\n // ...what it returns today\n locale: locals.locale\n};";
|
|
100
|
+
function k(e) {
|
|
101
|
+
let t = e.getBody();
|
|
102
|
+
if (!t) return null;
|
|
103
|
+
if (p.isBlock(t)) {
|
|
104
|
+
let n = l(e, t);
|
|
105
|
+
return n ? c(n) : null;
|
|
106
|
+
}
|
|
107
|
+
let n = t;
|
|
108
|
+
for (; p.isParenthesizedExpression(n);) n = n.getExpression();
|
|
109
|
+
return p.isObjectLiteralExpression(n) ? n : null;
|
|
110
|
+
}
|
|
111
|
+
function A(e) {
|
|
112
|
+
if (!d.existsSync(e)) return d.mkdirSync(f.dirname(e), { recursive: !0 }), d.writeFileSync(e, D + "\n"), {
|
|
113
|
+
status: "success",
|
|
114
|
+
changed: !0
|
|
115
|
+
};
|
|
116
|
+
let t = d.readFileSync(e, "utf8");
|
|
117
|
+
if (t.includes("locals.locale")) return {
|
|
118
|
+
status: "success",
|
|
119
|
+
changed: !1
|
|
120
|
+
};
|
|
121
|
+
let r = o().addSourceFileAtPath(e), i = s(r);
|
|
122
|
+
if (!i) return /\bload\b/.test(t) ? {
|
|
123
|
+
status: "failed",
|
|
124
|
+
message: O
|
|
125
|
+
} : (r.addStatements("\n" + D.split("\n").slice(2).join("\n") + "\n"), r.insertStatements(0, D.split("\n")[0]), n(r), r.saveSync(), {
|
|
126
|
+
status: "success",
|
|
127
|
+
changed: !0
|
|
128
|
+
});
|
|
129
|
+
let c = u(i), l = k(i);
|
|
130
|
+
if (c.kind === "unsupported" || !l || a(l, "locale")) return {
|
|
131
|
+
status: "failed",
|
|
132
|
+
message: O
|
|
133
|
+
};
|
|
134
|
+
let p = "locals";
|
|
135
|
+
if (c.kind === "identifier") p = `${c.name}.locals`;
|
|
136
|
+
else if (c.kind === "none") i.addParameter({ name: "{ locals }" });
|
|
137
|
+
else {
|
|
138
|
+
let e = c.pattern.getElements(), t = e.find((e) => (e.getPropertyNameNode()?.getText() ?? e.getName()) === "locals");
|
|
139
|
+
if (t) p = t.getName();
|
|
140
|
+
else if (e.some((e) => e.getDotDotDotToken())) return {
|
|
141
|
+
status: "failed",
|
|
142
|
+
message: O
|
|
143
|
+
};
|
|
144
|
+
else {
|
|
145
|
+
let t = e.map((e) => e.getText());
|
|
146
|
+
c.pattern.replaceWithText(`{ ${["locals", ...t].join(", ")} }`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return l.addPropertyAssignment({
|
|
150
|
+
name: "locale",
|
|
151
|
+
initializer: `${p}.locale`,
|
|
152
|
+
leadingTrivia: (e) => e.writeLine("// Decided on the server (src/hooks.server.ts), because pages without a").writeLine("// language in their URL follow the visitor's preference.")
|
|
153
|
+
}), n(r), r.saveSync(), {
|
|
154
|
+
status: "success",
|
|
155
|
+
changed: !0
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// src/patterns/enable/i18n/modifies/app-d-ts.ts
|
|
159
|
+
var j = "locale: import('#locales/data.js').Locale;", M = "/** The language of this request: see src/lib/locale.ts. */", N = [
|
|
160
|
+
"Declare the request's language on App.Locals in src/app.d.ts:",
|
|
161
|
+
"",
|
|
162
|
+
"interface Locals {",
|
|
163
|
+
` ${M}`,
|
|
164
|
+
` ${j}`,
|
|
165
|
+
"}"
|
|
166
|
+
].join("\n"), P = /^([ \t]*)\/\/\s*interface Locals\s*\{\s*\}[ \t]*$/m, F = /^([ \t]*)interface Locals\s*\{/m;
|
|
167
|
+
function I(e) {
|
|
168
|
+
if (!d.existsSync(e)) return {
|
|
169
|
+
status: "not-found",
|
|
170
|
+
message: N
|
|
171
|
+
};
|
|
172
|
+
let t = d.readFileSync(e, "utf8"), n = F.exec(t);
|
|
173
|
+
if (n) {
|
|
174
|
+
let e = n.index + n[0].length, r = t.indexOf("}", e);
|
|
175
|
+
if (r !== -1 && /\blocale\??\s*:/.test(t.slice(e, r))) return {
|
|
176
|
+
status: "success",
|
|
177
|
+
changed: !1
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
let r = /^\t/m.test(t) ? " " : " ", i = (e) => `${e}${r}${M}\n${e}${r}${j}\n`, a, o = P.exec(t);
|
|
181
|
+
if (n) {
|
|
182
|
+
let e = n.index + n[0].length, r = t.slice(e);
|
|
183
|
+
a = t.slice(0, e) + "\n" + i(n[1]) + (r.startsWith("}") ? n[1] : "") + r.replace(/^[ \t]*\n/, "");
|
|
184
|
+
} else if (o) {
|
|
185
|
+
let e = o[1];
|
|
186
|
+
a = t.replace(P, `${e}interface Locals {\n${i(e)}${e}}`);
|
|
187
|
+
} else return {
|
|
188
|
+
status: "failed",
|
|
189
|
+
message: N
|
|
190
|
+
};
|
|
191
|
+
return d.writeFileSync(e, a), {
|
|
192
|
+
status: "success",
|
|
193
|
+
changed: !0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export { A as a, E as c, g as d, _ as f, D as i, y as l, j as n, C as o, v as p, I as r, S as s, M as t, b as u };
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=app-d-ts-h33RrYIv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-d-ts-h33RrYIv.js","names":["FAILURE_HINT","FAILURE_HINT","dedent","ensureNamedImport","formatLikeSource","ensurePackageImports","newProject","findLoadFunction","returnedObject","findFinalReturn","inspectEventParameter","fs","path","LOCALES_ENTRY","PRETTIERIGNORE_HEADER","modifyPrettierignore","filePath","original","line","needsNewline","separator","LOCALES_IMPORTS","modifyPackageImportsI18n","root","IMPORT_SNIPPET","LOAD_STATEMENT","LEGACY_LOAD_STATEMENT","LOAD_SNIPPET","FAILURE_HINT$2","ensureRootLayoutI18n","layoutPath","existing","sourceFile","Project","QuoteKind","ensureImports","LAYOUT_SERVER_SNIPPET","FAILURE_HINT$1","loadResult","body","fn","Node","returned","expression","modifyLayoutServerLocale","layoutServerPath","event","object","hasProperty","locals","elements","element","kept","writer","LOCALS_MEMBER","LOCALS_COMMENT","FAILURE_HINT","COMMENTED","DECLARED","modifyAppDts","appDtsPath","declared","start","end","unit","member","indent","updated","commented","at","rest"],"sources":["../../src/patterns/enable/i18n/modifies/prettierignore.ts","../../src/patterns/enable/i18n/modifies/package-imports.ts","../../src/patterns/enable/i18n/modifies/+layout.ts","../../src/patterns/enable/i18n/modifies/layout.server.ts","../../src/patterns/enable/i18n/modifies/app-d-ts.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** Where wuchale writes its loaders, proxies and catalogs on every extract. */\nexport const LOCALES_ENTRY = \"src/locales/\";\nexport const PRETTIERIGNORE_HEADER = \"# Wuchale\";\n\n/**\n * wuchale rewrites `src/locales/` in its own style on every extract, which\n * the project's `prettier --check .` would flag. A project without a\n * `.prettierignore` is left alone: without prettier there is nothing to\n * ignore, and with it the file is the project's to start.\n */\nexport function modifyPrettierignore(filePath: string): ModifyOutcome {\n if (!fs.existsSync(filePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(filePath, \"utf8\");\n const ignored = original\n .split(\"\\n\")\n .some((line) => line.trim().replace(/^\\//, \"\") === LOCALES_ENTRY);\n if (ignored) {\n return { status: \"success\", changed: false };\n }\n\n const needsNewline = original.length > 0 && !original.endsWith(\"\\n\");\n const separator = original.length > 0 ? \"\\n\" : \"\";\n fs.writeFileSync(\n filePath,\n `${original}${needsNewline ? \"\\n\" : \"\"}${separator}${PRETTIERIGNORE_HEADER}\\n${LOCALES_ENTRY}\\n`,\n );\n return { status: \"success\", changed: true };\n}\n","import {\n ensurePackageImports,\n type PackageJsonEditResult,\n} from \"../../../../runtime/package-imports\";\n\n/**\n * The package.json `imports` entry the app's `#locales/*.js` specifiers\n * resolve through. wuchale writes its loaders and data to `src/locales`;\n * SvelteKit 3 deprecates `alias`, so the directory is mapped the way `#lib`\n * is. wuchale's own generated imports are relative and never go through it.\n */\nexport const LOCALES_IMPORTS = { \"#locales/*\": \"./src/locales/*\" };\n\n/** Add `#locales/*` to package.json `imports`; a different value already there is reported. */\nexport function modifyPackageImportsI18n(root: string): PackageJsonEditResult {\n return ensurePackageImports(root, LOCALES_IMPORTS);\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Project, QuoteKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n ensureImports,\n ensureNamedImport,\n formatLikeSource,\n} from \"../../../../runtime/ts-morph-helpers\";\n\nconst IMPORT_SNIPPET = dedent`\n import { browser } from '$app/env';\n import { loadLocale } from 'wuchale/load-utils';\n\n import { getLocale } from '#locales/main.url.js';\n import { hasLocalizedUrl } from '#lib/url.js';\n import '#locales/main.loader.svelte.js';\n import '#locales/js.loader.js';\n`;\n\n/** The load `disable-i18n` looks for to take it out again. */\nexport const LOAD_STATEMENT = dedent`\n export const load = async ({ url, data }) => {\n // A public page's language is in its URL. The others follow the visitor's\n // preference, which only the server knows: see src/lib/locale.ts.\n const locale = hasLocalizedUrl(url.pathname) ? getLocale(url) : data.locale;\n\n if (browser) {\n await loadLocale(locale);\n }\n\n return { ...data, locale };\n };\n`;\n\n/**\n * The load enable-i18n wrote while every page took its language from the\n * URL. `disable-i18n` still takes it out of a project enabled back then.\n */\nexport const LEGACY_LOAD_STATEMENT = dedent`\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\n/** The whole file, for a project that had no root `+layout.ts`. */\nexport const LOAD_SNIPPET = `${IMPORT_SNIPPET}\\n\\n${LOAD_STATEMENT}`;\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 fs.mkdirSync(path.dirname(layoutPath), { recursive: true });\n fs.writeFileSync(layoutPath, LOAD_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\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 // No load to merge with, but the file may hold other route options\n // (`export const prerender = true`, say), so the load is added to it\n // rather than written over it.\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n ensureNamedImport(sourceFile, \"$app/env\", \"browser\");\n ensureNamedImport(sourceFile, \"wuchale/load-utils\", \"loadLocale\");\n ensureNamedImport(sourceFile, \"#locales/main.url.js\", \"getLocale\");\n ensureNamedImport(sourceFile, \"#lib/url.js\", \"hasLocalizedUrl\");\n ensureImports(sourceFile, [\n { moduleSpecifier: \"#locales/main.loader.svelte.js\" },\n { moduleSpecifier: \"#locales/js.loader.js\" },\n ]);\n\n sourceFile.addStatements(`\\n${LOAD_STATEMENT}\\n`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node, type ObjectLiteralExpression } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"../../../../runtime/load-function\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\n/**\n * The whole file, for a project that had no root `+layout.server.ts`.\n * `disable-i18n` deletes it again while it is still exactly this.\n */\nexport const LAYOUT_SERVER_SNIPPET = dedent`\n import type { LayoutServerLoad } from './$types';\n\n export const load: LayoutServerLoad = async ({ locals }) => {\n \t// Decided on the server (src/hooks.server.ts), because pages without a\n \t// language in their URL follow the visitor's preference.\n \treturn { locale: locals.locale };\n };\n`;\n\nconst FAILURE_HINT = [\n \"Return the request's language from the load in src/routes/+layout.server.ts:\",\n \"\",\n \"return {\",\n \" // ...what it returns today\",\n \" locale: locals.locale\",\n \"};\",\n].join(\"\\n\");\n\n/** The object a load yields: its final `return`, or an arrow's `({ ... })` body. */\nfunction loadResult(\n fn: NonNullable<ReturnType<typeof findLoadFunction>>,\n): ObjectLiteralExpression | null {\n const body = fn.getBody();\n if (!body) return null;\n if (Node.isBlock(body)) {\n const returned = findFinalReturn(fn, body);\n return returned ? returnedObject(returned) : null;\n }\n let expression: Node = body;\n while (Node.isParenthesizedExpression(expression)) {\n expression = expression.getExpression();\n }\n return Node.isObjectLiteralExpression(expression) ? expression : null;\n}\n\n/**\n * The root layout's server load returns `locale`, the language the hook chose\n * for the request, for `+layout.ts` and the language select to read. Created\n * when the project has no `+layout.server.ts`; otherwise the property joins\n * what the load returns already. A load with several returns, or one that\n * returns something other than an object literal, is reported as `failed`\n * with the line to add and left as it was.\n */\nexport function modifyLayoutServerLocale(\n layoutServerPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, LAYOUT_SERVER_SNIPPET + \"\\n\");\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"locals.locale\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n const fn = findLoadFunction(sourceFile);\n if (!fn) {\n // Route options only (`export const prerender = true`, say).\n if (/\\bload\\b/.test(original)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n sourceFile.addStatements(\n \"\\n\" + LAYOUT_SERVER_SNIPPET.split(\"\\n\").slice(2).join(\"\\n\") + \"\\n\",\n );\n sourceFile.insertStatements(0, LAYOUT_SERVER_SNIPPET.split(\"\\n\")[0]);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const event = inspectEventParameter(fn);\n const object = loadResult(fn);\n if (\n event.kind === \"unsupported\" ||\n !object ||\n hasProperty(object, \"locale\")\n ) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n let locals = \"locals\";\n if (event.kind === \"identifier\") {\n locals = `${event.name}.locals`;\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ locals }\" });\n } else {\n const elements = event.pattern.getElements();\n const existing = elements.find(\n (element) =>\n (element.getPropertyNameNode()?.getText() ?? element.getName()) ===\n \"locals\",\n );\n if (existing) {\n locals = existing.getName();\n } else if (elements.some((element) => element.getDotDotDotToken())) {\n return { status: \"failed\", message: FAILURE_HINT };\n } else {\n const kept = elements.map((element) => element.getText());\n event.pattern.replaceWithText(`{ ${[\"locals\", ...kept].join(\", \")} }`);\n }\n }\n\n // After any spread, so nothing spread in can shadow it.\n object.addPropertyAssignment({\n name: \"locale\",\n initializer: `${locals}.locale`,\n leadingTrivia: (writer) =>\n writer\n .writeLine(\n \"// Decided on the server (src/hooks.server.ts), because pages without a\",\n )\n .writeLine(\"// language in their URL follow the visitor's preference.\"),\n });\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n/** The member `disable-i18n` looks for to take it out again. */\nexport const LOCALS_MEMBER = \"locale: import('#locales/data.js').Locale;\";\nexport const LOCALS_COMMENT =\n \"/** The language of this request: see src/lib/locale.ts. */\";\n\nconst FAILURE_HINT = [\n \"Declare the request's language on App.Locals in src/app.d.ts:\",\n \"\",\n \"interface Locals {\",\n ` ${LOCALS_COMMENT}`,\n ` ${LOCALS_MEMBER}`,\n \"}\",\n].join(\"\\n\");\n\n/** `// interface Locals {}`, as `sv create` leaves it. */\nconst COMMENTED = /^([ \\t]*)\\/\\/\\s*interface Locals\\s*\\{\\s*\\}[ \\t]*$/m;\nconst DECLARED = /^([ \\t]*)interface Locals\\s*\\{/m;\n\n/**\n * `event.locals.locale`, which the i18n handle sets, is declared on\n * `App.Locals`. The interface `sv create` leaves commented out is switched\n * on; one that is declared already gains the member.\n */\nexport function modifyAppDts(appDtsPath: string): ModifyOutcome {\n if (!fs.existsSync(appDtsPath)) {\n return { status: \"not-found\", message: FAILURE_HINT };\n }\n\n const original = fs.readFileSync(appDtsPath, \"utf8\");\n // Whatever its type, a `locale` on Locals is there.\n const declared = DECLARED.exec(original);\n if (declared) {\n const start = declared.index + declared[0].length;\n const end = original.indexOf(\"}\", start);\n if (end !== -1 && /\\blocale\\??\\s*:/.test(original.slice(start, end))) {\n return { status: \"success\", changed: false };\n }\n }\n\n const unit = /^\\t/m.test(original) ? \"\\t\" : \" \";\n const member = (indent: string) =>\n `${indent}${unit}${LOCALS_COMMENT}\\n${indent}${unit}${LOCALS_MEMBER}\\n`;\n\n let updated: string;\n const commented = COMMENTED.exec(original);\n if (declared) {\n const at = declared.index + declared[0].length;\n const rest = original.slice(at);\n updated =\n original.slice(0, at) +\n \"\\n\" +\n member(declared[1]) +\n // `interface Locals {}` on one line: the brace moves to its own.\n (rest.startsWith(\"}\") ? declared[1] : \"\") +\n rest.replace(/^[ \\t]*\\n/, \"\");\n } else if (commented) {\n const indent = commented[1];\n updated = original.replace(\n COMMENTED,\n `${indent}interface Locals {\\n${member(indent)}${indent}}`,\n );\n } else {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(appDtsPath, updated);\n return { status: \"success\", changed: true };\n}\n"],"mappings":";;;;;;;;AAIA,IAAaa,IAAgB,gBAChBC,IAAwB;AAQrC,SAAgBC,EAAqB,GAAiC;CACpE,IAAI,CAACJ,EAAG,WAAWK,CAAQ,GACzB,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EAAS,EAAE,KAEjBS,EAAK,WAAW,GAAG,IAAIT,EAAS,KAAK,MACtCS,EAAK,QAAQ,aAAa,EAAE;CAChC,OAAO,IAAIF,GAAW;EACpB,IAAMF,IAASE,EAAU;EACzB,IAAUnD,EAAS,QACjBwC,GACA,GAAGS,EAAO,sBAAsBD,EAAOC,CAAM,IAAIA,EAAO,EAC1D;CACF,OACE,OAAO;EAAE,QAAQ;EAAU,SAASV;CAAa;CAInD,OADA7C,EAAG,cAAciD,GAAYO,CAAO,GAC7B;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { t as e } from "./dedent-CCUOcPFW.js";
|
|
2
|
+
import { t } from "./svelte-file-DfplF3BU.js";
|
|
3
|
+
import { _ as n, r } from "./ts-morph-helpers-B4KZXP44.js";
|
|
4
|
+
import i from "node:fs";
|
|
5
|
+
import a from "node:path";
|
|
6
|
+
// src/patterns/enable/i18n/modifies/app-layout.svelte.ts
|
|
7
|
+
var o = a.join("src", "routes", "(app)", "+layout.svelte"), s = " <div class=\"ml-auto px-4\">\n <LanguageSelect />\n </div>\n ", c = /[ \t]*<div class="ml-auto px-4">\s*<LanguageSelect\s*\/>\s*<\/div>[ \t]*\r?\n?/g, l = [
|
|
8
|
+
"Add the language select to the <header> of the signed-in layout,",
|
|
9
|
+
"src/routes/(app)/+layout.svelte. Signed-in pages have one URL for every",
|
|
10
|
+
"language, so the select is how a visitor changes it there.",
|
|
11
|
+
"",
|
|
12
|
+
"Import to add to the <script> tag:",
|
|
13
|
+
"",
|
|
14
|
+
e`
|
|
15
|
+
import LanguageSelect from '#lib/components/language-select.svelte';
|
|
16
|
+
`,
|
|
17
|
+
"",
|
|
18
|
+
"Markup to add at the end of <header>:",
|
|
19
|
+
"",
|
|
20
|
+
"<div class=\"ml-auto px-4\">",
|
|
21
|
+
" <LanguageSelect />",
|
|
22
|
+
"</div>"
|
|
23
|
+
].join("\n");
|
|
24
|
+
function u(e) {
|
|
25
|
+
if (!i.existsSync(e)) return {
|
|
26
|
+
status: "success",
|
|
27
|
+
changed: !1
|
|
28
|
+
};
|
|
29
|
+
let a = t.fromPath(e);
|
|
30
|
+
return a.hasElement("LanguageSelect") ? {
|
|
31
|
+
status: "success",
|
|
32
|
+
changed: !1
|
|
33
|
+
} : !a.getScript() || !a.hasElement("header") ? {
|
|
34
|
+
status: "failed",
|
|
35
|
+
message: l
|
|
36
|
+
} : (a.modifyScript((e) => {
|
|
37
|
+
let { source: t } = n(e, (e) => {
|
|
38
|
+
r(e, [{
|
|
39
|
+
defaultImport: "LanguageSelect",
|
|
40
|
+
moduleSpecifier: "#lib/components/language-select.svelte"
|
|
41
|
+
}]);
|
|
42
|
+
});
|
|
43
|
+
return t;
|
|
44
|
+
}), a.insertBeforeClosingTag("header", s), a.writeTo(e), {
|
|
45
|
+
status: "success",
|
|
46
|
+
changed: a.hasChanged()
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export { o as n, u as r, c as t };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=app-layout.svelte-CZ0hw-pi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-layout.svelte-CZ0hw-pi.js","names":["dedent","withInMemoryScript","fs","path","APP_LAYOUT_PATH","LANGUAGE_SELECT_SNIPPET","APP_LANGUAGE_SELECT","FAILURE_HINT","modifyAppLayoutLanguageSelect","layoutPath","file","SvelteFile","out","source","sf"],"sources":["../../src/patterns/enable/i18n/modifies/app-layout.svelte.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\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\n/** The signed-in layout enable-auth writes, relative to the project root. */\nexport const APP_LAYOUT_PATH = path.join(\n \"src\",\n \"routes\",\n \"(app)\",\n \"+layout.svelte\",\n);\n\n/** At the end of the header, pushed to its right edge. */\nconst LANGUAGE_SELECT_SNIPPET = `\t<div class=\"ml-auto px-4\">\n\t\t\t\t\t<LanguageSelect />\n\t\t\t\t</div>\n\t\t\t`;\n\n/** What `disable-i18n` takes back out. */\nexport const APP_LANGUAGE_SELECT =\n /[ \\t]*<div class=\"ml-auto px-4\">\\s*<LanguageSelect\\s*\\/>\\s*<\\/div>[ \\t]*\\r?\\n?/g;\n\nconst IMPORT_SNIPPET = dedent`\n import LanguageSelect from '#lib/components/language-select.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the language select to the <header> of the signed-in layout,\",\n \"src/routes/(app)/+layout.svelte. Signed-in pages have one URL for every\",\n \"language, so the select is how a visitor changes it there.\",\n \"\",\n \"Import to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the end of <header>:\",\n \"\",\n '<div class=\"ml-auto px-4\">',\n \" <LanguageSelect />\",\n \"</div>\",\n].join(\"\\n\");\n\n/**\n * The language select at the end of the signed-in layout's header. Signed-in\n * pages have no language in their URL and no public navbar, so without it a\n * visitor could only change language by going back to a public page.\n *\n * Shared by the two patterns that can be the second one enabled: enable-i18n\n * adds it to the layout enable-auth wrote, and enable-auth adds it to its own\n * layout when the project already has i18n. A project without the layout is\n * left alone.\n */\nexport function modifyAppLayoutLanguageSelect(\n layoutPath: string,\n): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (file.hasElement(\"LanguageSelect\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript() || !file.hasElement(\"header\")) {\n return { status: \"failed\", message: FAILURE_HINT };\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 file.insertBeforeClosingTag(\"header\", LANGUAGE_SELECT_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n"],"mappings":";;;;;;AAWA,IAAaI,IAAkBD,EAAK,KAClC,OACA,UACA,SACA,gBACF,GAGME,IAA0B,2EAMnBC,IACX,mFAMIC,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA,CAX2B;;;CAY3B;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAYX,SAAgBC,EACd,GACe;CACf,IAAI,CAACN,EAAG,WAAWO,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAMC,IAAOC,EAAW,SAASF,CAAU;CAqB3C,OApBIC,EAAK,WAAW,gBAAgB,IAC3B;EAAE,QAAQ;EAAW,SAAS;CAAM,IAEzC,CAACA,EAAK,UAAU,KAAK,CAACA,EAAK,WAAW,QAAQ,IACzC;EAAE,QAAQ;EAAU,SAASH;CAAa,KAGnDG,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQE,MAAQX,EAAmBY,IAAS,MAAO;GACzD,EAAcC,GAAI,CAChB;IACE,eAAe;IACf,iBAAiB;GACnB,CACF,CAAC;EACH,CAAC;EACD,OAAOF;CACT,CAAC,GACDF,EAAK,uBAAuB,UAAUL,CAAuB,GAC7DK,EAAK,QAAQD,CAAU,GAChB;EAAE,QAAQ;EAAW,SAASC,EAAK,WAAW;CAAE;AACzD"}
|
|
@@ -313,7 +313,7 @@ async function O(s) {
|
|
|
313
313
|
f(i(x.filePath, x.outcome));
|
|
314
314
|
let C = await a(s);
|
|
315
315
|
return {
|
|
316
|
-
creates: C ? [C] :
|
|
316
|
+
creates: C ? [...u, C] : u,
|
|
317
317
|
modifies: d,
|
|
318
318
|
deletes: [],
|
|
319
319
|
components: [],
|
|
@@ -325,4 +325,4 @@ async function O(s) {
|
|
|
325
325
|
}
|
|
326
326
|
export { O as generate };
|
|
327
327
|
|
|
328
|
-
//# sourceMappingURL=generate.runtime-
|
|
328
|
+
//# sourceMappingURL=generate.runtime-Bv_16lWi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-DHJqOJTr.js","names":["FAILURE_HINT","NOT_FOUND_HINT","getLogger","withPocketbase","getMigrationFile","modifyOutcomeToFile","ensureSiteFile","dedent","withInMemoryScript","ensurePropsBinding","formatLikeSource","ensureImports","SvelteFile","fs","path","modifyLayoutServer","layoutPath","snippet","originalSource","sourceFile","Project","addUserProp","obj","loadArrow","loadFn","varDecl","SyntaxKind","directArrow","init","innerArrow","innerFnExpr","maybeFn","fnLike","params","first","original","nameNode","obp","el","parts","tail","currentName","body","expr","ret","inner","bodyExpr","AUTH_MENU_NAVBAR_ITEM","IMPORT_SNIPPET","FAILURE_HINT$1","NOT_FOUND_HINT$1","modifyRootLayoutSvelte","file","out","source","sf","FAILURE_HINT","NOT_FOUND_HINT","modifyHooksServer","hooksServerPath","callExpr","ce","args","firstArg","optionsObj","authProp","authInit","authObj","prProp","prInit","arr","COOKIE_LOGIN","modifyTestSetup","setupPath","helper","generate","options","logger","creates","pb","input","migrationDelay","userCollection","verificationTemplate","resetPasswordTemplate","confirmEmailChangeTemplate","migrationFile","modifies","pushResult","layoutServerFile","layoutCandidates","layoutFile","p","hooksServerFile","testSetupFile","remote","modifySvelteConfigRemote","siteFile"],"sources":["../../src/patterns/enable/auth-remote/modifies/+layout.server.ts","../../src/patterns/enable/auth-remote/modifies/root-layout.svelte.ts","../../src/patterns/enable/auth-remote/modifies/hooks.server.ts","../../src/patterns/enable/auth-remote/modifies/test-setup.ts","../../src/patterns/enable/auth-remote/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport function modifyLayoutServer(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n const snippet = dedent`\n\t\t\texport const load = async ({ locals }) => {\n\t\t\t\treturn { user: locals.pb.authStore.record };\n\t\t\t};\n\t\t`;\n\n fs.writeFileSync(layoutPath, snippet);\n return { status: \"success\", changed: true };\n }\n\n const originalSource = fs.readFileSync(layoutPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n // helper to add user property to an object literal if missing\n const addUserProp = (obj: import(\"ts-morph\").ObjectLiteralExpression) => {\n const hasUser = !!obj.getProperty(\"user\");\n if (!hasUser) {\n obj.addPropertyAssignment({\n name: \"user\",\n initializer: \"locals.pb.authStore.record\",\n });\n }\n };\n\n // find existing exported load (function or const with arrow)\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n const isExported = !!vs?.hasExportKeyword();\n if (isExported) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) {\n loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n }\n\n if (!loadArrow) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) {\n loadFn = maybeFn;\n }\n }\n\n // if no load found, create one\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals }\" }],\n statements: `return { user: locals.pb.authStore.record };`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // normalize function-like to a single handle\n const fnLike:\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression = (loadArrow ?? loadFn!) as any;\n\n // ensure first parameter destructures locals, preserving existing information\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const hasLocals = obp\n .getElements()\n .some((el) => el.getName() === \"locals\");\n if (!hasLocals) {\n const parts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const tail = parts.length > 0 ? \", \" + parts.join(\", \") : \"\";\n first.set({\n name: `{ locals${tail} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, ...${currentName} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n }\n }\n\n // add user to returned object literals without altering other properties\n if (loadArrow) {\n const body = loadArrow.getBody();\n if (body.getKind() === SyntaxKind.Block) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n } else {\n // concise body\n const bodyExpr = body as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(bodyExpr as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n } else if (loadFn) {\n const body = loadFn.getBody();\n if (body) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n ensurePropsBinding,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst AUTH_MENU_NAVBAR_ITEM = `\n\t\t<Navbar.Item\n\t\t\tclass=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n\t\t>\n\t\t\t<AuthMenu.Root>\n\t\t\t\t{#snippet user()}\n\t\t\t\t\t<AuthMenu.Trigger>\n\t\t\t\t\t\t<UserAvatar user={data.user} />\n\t\t\t\t\t</AuthMenu.Trigger>\n\n\t\t\t\t\t<AuthMenu.Content align=\"end\">\n\t\t\t\t\t\t<AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n\t\t\t\t\t\t<AuthMenu.Group>\n\t\t\t\t\t\t\t<AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n\t\t\t\t\t\t\t<AuthMenu.Item>\n\t\t\t\t\t\t\t\t<form action=\"/logout\" method=\"post\">\n\t\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"contents\">Logout</button>\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t</AuthMenu.Item>\n\t\t\t\t\t\t</AuthMenu.Group>\n\t\t\t\t\t</AuthMenu.Content>\n\t\t\t\t{/snippet}\n\n\t\t\t\t{#snippet guest()}\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\thref=\"/login\">Login</Button\n\t\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\t\thref=\"/signup\">Sign up</Button\n\t\t\t\t\t>\n\t\t\t\t{/snippet}\n\t\t\t</AuthMenu.Root>\n\t\t</Navbar.Item>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import * as AuthMenu from '#lib/components/ui/auth-menu/index.js';\n import UserAvatar from '#lib/components/user-avatar.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the auth menu inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes an auth menu inside <Navbar.List>.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\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 if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"AuthMenu.Root\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namespaceImport: \"AuthMenu\",\n moduleSpecifier: \"#lib/components/ui/auth-menu/index.js\",\n },\n {\n defaultImport: \"UserAvatar\",\n moduleSpecifier: \"#lib/components/user-avatar.svelte\",\n },\n ]);\n // The menu reads `data.user`; the template's layout takes no props.\n ensurePropsBinding(sf, \"data\");\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", AUTH_MENU_NAVBAR_ITEM);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with the auth option in hooks.server.ts:\n\n handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Find the handlePocketbase(...) call\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(`{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(0, `{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n // Ensure auth property exists\n const authProp = optionsObj.getProperty(\"auth\");\n if (!authProp) {\n optionsObj.addPropertyAssignment({\n name: \"auth\",\n initializer: `{ protectedRoutes: ['/(app)'] }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // If auth exists, ensure protectedRoutes includes '/(app)'\n if (authProp.getKind() === SyntaxKind.PropertyAssignment) {\n const authInit = (\n authProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (authInit && authInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const authObj = authInit as import(\"ts-morph\").ObjectLiteralExpression;\n const prProp = authObj.getProperty(\"protectedRoutes\");\n if (!prProp) {\n authObj.addPropertyAssignment({\n name: \"protectedRoutes\",\n initializer: `['/(app)']`,\n });\n } else if (prProp.getKind() === SyntaxKind.PropertyAssignment) {\n const prInit = (\n prProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (prInit && prInit.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = prInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasApp = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \"/(app)\");\n if (!hasApp) {\n arr.addElement(`'/(app)'`);\n }\n } else {\n (prProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `['/(app)']`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst COOKIE_LOGIN = dedent`\n // Login is a remote function, so there is no form action to post to: carry\n // the session the way the browser does, in the \\`pb_auth\\` cookie.\n async function authenticateUser(agent: Agent, user: { email?: string }) {\n // Logs in with the password, so it needs the email (made optional by\n // enable-whatsapp, for accounts that sign in with a phone number).\n if (!user.email) {\n throw new Error('authenticateUser needs a user with an email');\n }\n const client = new PocketBase(process.env.POCKETBASE_URL!);\n await client.collection(\"users\").authWithPassword(user.email, testUserPassword);\n agent.set(\"Cookie\", client.authStore.exportToCookie().split(\";\")[0]);\n }\n`;\n\n/**\n * The template's server-test helper logs in by posting the `/login` form\n * action, which this pattern replaces with a remote function. A project\n * without the helper (or with its own) has nothing to fix.\n */\nexport function modifyTestSetup(setupPath: string): ModifyOutcome {\n if (!fs.existsSync(setupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(setupPath);\n const helper = sourceFile.getFunction(\"authenticateUser\");\n\n if (!helper || !/\\.post\\(\\s*[\"'`]\\/login[\"'`]\\s*\\)/.test(helper.getText())) {\n return { status: \"success\", changed: false };\n }\n\n helper.replaceWithText(COOKIE_LOGIN);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { Options, Result, File } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { ensureSiteFile } from \"../../../runtime/site\";\nimport { modifySvelteConfigRemote } from \"../../../runtime/modify-svelte-config-remote\";\n\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifyTestSetup } from \"./modifies/test-setup\";\n\nexport async function generate(options: Options) {\n const { input } = options;\n const logger = getLogger(options);\n\n let creates: File[] = [];\n\n // Update PocketBase\n await withPocketbase(options.root, async (pb) => {\n logger.info(\"Updating PocketBase mail settings\");\n await pb.settings.update({\n meta: {\n senderName: input.senderName,\n senderAddress: input.senderAddress,\n },\n });\n await migrationDelay();\n\n const userCollection = await pb.collections.getOne(\"users\");\n\n if (!userCollection) {\n throw new Error(\"Users collection not found\");\n }\n\n const verificationTemplate =\n userCollection.verificationTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\",\n \"{APP_URL}/confirm-verification/{TOKEN}\",\n );\n const resetPasswordTemplate =\n userCollection.resetPasswordTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-reset/{TOKEN}\",\n \"{APP_URL}/confirm-reset/{TOKEN}\",\n );\n const confirmEmailChangeTemplate =\n userCollection.confirmEmailChangeTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\",\n \"{APP_URL}/confirm-email-change/{TOKEN}\",\n );\n\n logger.info(\"Locking down users collection rules and email templates\");\n // Update user auth rules to lock down access to the user's own account\n await pb.collections.update(\"users\", {\n listRule: \"@request.auth.id = id\",\n viewRule: \"@request.auth.id = id\",\n createRule: \"@request.auth.id = id\",\n updateRule: \"@request.auth.id = id\",\n deleteRule: \"@request.auth.id = id\",\n\n // Update email templates to VelaStack auth urls\n verificationTemplate: {\n body: verificationTemplate,\n },\n resetPasswordTemplate: {\n body: resetPasswordTemplate,\n },\n confirmEmailChangeTemplate: {\n body: confirmEmailChangeTemplate,\n },\n });\n await migrationDelay();\n\n const migrationFile = getMigrationFile(\"users\", \"updated\", options);\n if (migrationFile) {\n creates.push({\n path: migrationFile,\n language: \"ts\",\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n });\n\n // Modify files\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying +layout.server.ts\");\n const layoutServerFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(layoutServerFile, modifyLayoutServer(layoutServerFile)),\n );\n\n logger.info(\"Modifying root layout\");\n // TODO: make this more robust by searching for Navbar.Root > Navbar.List\n // src/routes/(public)/root-layout.svelte is what vela creates by default\n const layoutCandidates = [\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 layoutFile =\n layoutCandidates.find((p) => fs.existsSync(p)) ?? layoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(layoutFile, modifyRootLayoutSvelte(layoutFile)),\n );\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerFile = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerFile, modifyHooksServer(hooksServerFile)),\n );\n\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = path.join(options.root, \"test\", \"setup.ts\");\n pushResult(\n modifyOutcomeToFile(testSetupFile, modifyTestSetup(testSetupFile)),\n );\n\n logger.info(\"Modifying config for remote functions\");\n const remote = modifySvelteConfigRemote(options.root);\n pushResult(modifyOutcomeToFile(remote.filePath, remote.outcome));\n\n // The auth pages and the app sidebar show `site.name`.\n const siteFile = await ensureSiteFile(options);\n\n return {\n creates: siteFile ? [siteFile] : [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AAMA,SAAgBe,EAAmB,GAAmC;CACpE,IAAI,CAACF,EAAG,WAAWG,CAAU,GAAG;EAC9B,IAAMC,IAAU,CAAM;;;;;EAOtB,OADAJ,EAAG,cAAcG,GAAYC,CAAO,GAC7B;GAAE,QAAQ;GAAW,SAAS;EAAK;CAC5C;CAEA,IAAMC,IAAiBL,EAAG,aAAaG,GAAY,MAAM,GAEnDG,IAAa,IADCC,EACD,CAAA,CAAQ,oBAAoBJ,CAAU,GAGnDK,KAAe,MAAoD;EAEvE,AADkBC,EAAI,YAAY,MAAM,KAEtCA,EAAI,sBAAsB;GACxB,MAAM;GACN,aAAa;EACf,CAAC;CAEL,GAGIC,GACAC,GAKEC,IAAUN,EAAW,uBAAuB,MAAM;CACxD,IAAIM,KACSA,EAAQ,uBAAuBC,EAAW,iBAChC,CAAA,EAAI,iBAAiB,GAC1B;EACd,IAAMC,IAAcF,EAAQ,qBAC1BC,EAAW,aACb;EACA,IAAIC,GACF,IAAYA;OACP;GACL,IAAMC,IAAOH,EAAQ,eAAe;GACpC,IAAIG,GAAM;IACR,IAAMC,IAAaD,EAAK,yBACtBF,EAAW,aACb;IACA,IAAIG,GACF,IAAYA;SACP;KACL,IAAMC,IAAcF,EAAK,yBACvBF,EAAW,kBACb;KACA,AAAII,MACF,IAASA;IAEb;GACF;EACF;CACF;CAGF,IAAI,CAACP,GAAW;EACd,IAAMQ,IAAUZ,EAAW,YAAY,MAAM;EAC7C,AAAIY,KAAWA,EAAQ,WAAW,MAChC,IAASA;CAEb;CAGA,IAAI,CAACR,KAAa,CAACC,GAUjB,OATAL,EAAW,YAAY;EACrB,YAAY;EACZ,SAAS;EACT,MAAM;EAC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AyBpB,EAAQ,IAAI;CACpD,EAAWvE,EAAoB0F,EAAO,UAAUA,EAAO,OAAO,CAAC;CAG/D,IAAME,IAAW,MAAM3F,EAAesE,CAAO;CAE7C,OAAO;EACL,SAASqB,IAAW,CAACA,CAAQ,IAAI,CAAC;EAClC;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"generate.runtime-Bv_16lWi.js","names":["FAILURE_HINT","NOT_FOUND_HINT","getLogger","withPocketbase","getMigrationFile","modifyOutcomeToFile","ensureSiteFile","dedent","withInMemoryScript","ensurePropsBinding","formatLikeSource","ensureImports","SvelteFile","fs","path","modifyLayoutServer","layoutPath","snippet","originalSource","sourceFile","Project","addUserProp","obj","loadArrow","loadFn","varDecl","SyntaxKind","directArrow","init","innerArrow","innerFnExpr","maybeFn","fnLike","params","first","original","nameNode","obp","el","parts","tail","currentName","body","expr","ret","inner","bodyExpr","AUTH_MENU_NAVBAR_ITEM","IMPORT_SNIPPET","FAILURE_HINT$1","NOT_FOUND_HINT$1","modifyRootLayoutSvelte","file","out","source","sf","FAILURE_HINT","NOT_FOUND_HINT","modifyHooksServer","hooksServerPath","callExpr","ce","args","firstArg","optionsObj","authProp","authInit","authObj","prProp","prInit","arr","COOKIE_LOGIN","modifyTestSetup","setupPath","helper","generate","options","logger","creates","pb","input","migrationDelay","userCollection","verificationTemplate","resetPasswordTemplate","confirmEmailChangeTemplate","migrationFile","modifies","pushResult","layoutServerFile","layoutCandidates","layoutFile","p","hooksServerFile","testSetupFile","remote","modifySvelteConfigRemote","siteFile"],"sources":["../../src/patterns/enable/auth-remote/modifies/+layout.server.ts","../../src/patterns/enable/auth-remote/modifies/root-layout.svelte.ts","../../src/patterns/enable/auth-remote/modifies/hooks.server.ts","../../src/patterns/enable/auth-remote/modifies/test-setup.ts","../../src/patterns/enable/auth-remote/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nexport function modifyLayoutServer(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n const snippet = dedent`\n\t\t\texport const load = async ({ locals }) => {\n\t\t\t\treturn { user: locals.pb.authStore.record };\n\t\t\t};\n\t\t`;\n\n fs.writeFileSync(layoutPath, snippet);\n return { status: \"success\", changed: true };\n }\n\n const originalSource = fs.readFileSync(layoutPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(layoutPath);\n\n // helper to add user property to an object literal if missing\n const addUserProp = (obj: import(\"ts-morph\").ObjectLiteralExpression) => {\n const hasUser = !!obj.getProperty(\"user\");\n if (!hasUser) {\n obj.addPropertyAssignment({\n name: \"user\",\n initializer: \"locals.pb.authStore.record\",\n });\n }\n };\n\n // find existing exported load (function or const with arrow)\n let loadArrow: import(\"ts-morph\").ArrowFunction | undefined;\n let loadFn:\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression\n | undefined;\n\n const varDecl = sourceFile.getVariableDeclaration(\"load\");\n if (varDecl) {\n const vs = varDecl.getFirstAncestorByKind(SyntaxKind.VariableStatement);\n const isExported = !!vs?.hasExportKeyword();\n if (isExported) {\n const directArrow = varDecl.getInitializerIfKind(\n SyntaxKind.ArrowFunction,\n );\n if (directArrow) {\n loadArrow = directArrow;\n } else {\n const init = varDecl.getInitializer();\n if (init) {\n const innerArrow = init.getFirstDescendantByKind(\n SyntaxKind.ArrowFunction,\n );\n if (innerArrow) {\n loadArrow = innerArrow;\n } else {\n const innerFnExpr = init.getFirstDescendantByKind(\n SyntaxKind.FunctionExpression,\n );\n if (innerFnExpr) {\n loadFn = innerFnExpr;\n }\n }\n }\n }\n }\n }\n\n if (!loadArrow) {\n const maybeFn = sourceFile.getFunction(\"load\");\n if (maybeFn && maybeFn.isExported()) {\n loadFn = maybeFn;\n }\n }\n\n // if no load found, create one\n if (!loadArrow && !loadFn) {\n sourceFile.addFunction({\n isExported: true,\n isAsync: true,\n name: \"load\",\n parameters: [{ name: \"{ locals }\" }],\n statements: `return { user: locals.pb.authStore.record };`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // normalize function-like to a single handle\n const fnLike:\n | import(\"ts-morph\").ArrowFunction\n | import(\"ts-morph\").FunctionDeclaration\n | import(\"ts-morph\").FunctionExpression = (loadArrow ?? loadFn!) as any;\n\n // ensure first parameter destructures locals, preserving existing information\n const params = fnLike.getParameters();\n if (params.length === 0) {\n fnLike.insertParameter(0, { name: \"{ locals }\" });\n } else {\n const first = params[0];\n const original = first.getStructure();\n const nameNode = first.getNameNode();\n if (nameNode.getKind() === SyntaxKind.ObjectBindingPattern) {\n const obp = nameNode as import(\"ts-morph\").ObjectBindingPattern;\n const hasLocals = obp\n .getElements()\n .some((el) => el.getName() === \"locals\");\n if (!hasLocals) {\n const parts = obp\n .getElements()\n .map((el) => el.getText())\n .filter(Boolean);\n const tail = parts.length > 0 ? \", \" + parts.join(\", \") : \"\";\n first.set({\n name: `{ locals${tail} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n } else {\n const currentName = first.getName();\n if (currentName !== \"locals\") {\n first.set({\n name: `{ locals, ...${currentName} }`,\n type: original.type,\n initializer: (original as any).initializer,\n });\n }\n }\n }\n\n // add user to returned object literals without altering other properties\n if (loadArrow) {\n const body = loadArrow.getBody();\n if (body.getKind() === SyntaxKind.Block) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n } else {\n // concise body\n const bodyExpr = body as import(\"ts-morph\").Expression;\n if (bodyExpr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n bodyExpr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n } else if (bodyExpr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(bodyExpr as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n } else if (loadFn) {\n const body = loadFn.getBody();\n if (body) {\n const returns = body.getDescendantsOfKind(SyntaxKind.ReturnStatement);\n returns.forEach((ret) => {\n const expr = ret.getExpression();\n if (!expr) return;\n if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(expr as import(\"ts-morph\").ObjectLiteralExpression);\n } else if (expr.getKind() === SyntaxKind.ParenthesizedExpression) {\n const inner = (\n expr as import(\"ts-morph\").ParenthesizedExpression\n ).getExpression();\n if (inner.getKind() === SyntaxKind.ObjectLiteralExpression) {\n addUserProp(inner as import(\"ts-morph\").ObjectLiteralExpression);\n }\n }\n });\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n ensurePropsBinding,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst AUTH_MENU_NAVBAR_ITEM = `\n\t\t<Navbar.Item\n\t\t\tclass=\"flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4\"\n\t\t>\n\t\t\t<AuthMenu.Root>\n\t\t\t\t{#snippet user()}\n\t\t\t\t\t<AuthMenu.Trigger>\n\t\t\t\t\t\t<UserAvatar user={data.user} />\n\t\t\t\t\t</AuthMenu.Trigger>\n\n\t\t\t\t\t<AuthMenu.Content align=\"end\">\n\t\t\t\t\t\t<AuthMenu.Item href=\"/dashboard\">Dashboard</AuthMenu.Item>\n\t\t\t\t\t\t<AuthMenu.Group>\n\t\t\t\t\t\t\t<AuthMenu.Item href=\"/settings\">Settings</AuthMenu.Item>\n\t\t\t\t\t\t\t<AuthMenu.Item>\n\t\t\t\t\t\t\t\t<form action=\"/logout\" method=\"post\">\n\t\t\t\t\t\t\t\t\t<button type=\"submit\" class=\"contents\">Logout</button>\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t</AuthMenu.Item>\n\t\t\t\t\t\t</AuthMenu.Group>\n\t\t\t\t\t</AuthMenu.Content>\n\t\t\t\t{/snippet}\n\n\t\t\t\t{#snippet guest()}\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\thref=\"/login\">Login</Button\n\t\t\t\t\t>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tclass=\"w-full justify-start md:justify-center md:w-auto\"\n\t\t\t\t\t\tvariant=\"outline\"\n\t\t\t\t\t\thref=\"/signup\">Sign up</Button\n\t\t\t\t\t>\n\t\t\t\t{/snippet}\n\t\t\t</AuthMenu.Root>\n\t\t</Navbar.Item>\n\t`;\n\nconst IMPORT_SNIPPET = dedent`\n import * as AuthMenu from '#lib/components/ui/auth-menu/index.js';\n import UserAvatar from '#lib/components/user-avatar.svelte';\n`;\n\nconst FAILURE_HINT = [\n \"Add the auth menu inside your <Navbar.List> in the root layout.\",\n \"\",\n \"Imports to add to the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a root layout that includes an auth menu inside <Navbar.List>.\",\n \"\",\n \"Imports for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup inside <Navbar.List>:\",\n AUTH_MENU_NAVBAR_ITEM,\n].join(\"\\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 if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"AuthMenu.Root\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n {\n namespaceImport: \"AuthMenu\",\n moduleSpecifier: \"#lib/components/ui/auth-menu/index.js\",\n },\n {\n defaultImport: \"UserAvatar\",\n moduleSpecifier: \"#lib/components/user-avatar.svelte\",\n },\n ]);\n // The menu reads `data.user`; the template's layout takes no props.\n ensurePropsBinding(sf, \"data\");\n });\n return out;\n });\n\n file.insertBeforeClosingTag(\"Navbar.List\", AUTH_MENU_NAVBAR_ITEM);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with the auth option in hooks.server.ts:\n\n handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from '@velastack/pocketbase';\n\n export const handle = handlePocketbase({\n auth: { protectedRoutes: ['/(app)'] },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n // Find the handlePocketbase(...) call\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(`{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(0, `{ auth: { protectedRoutes: ['/(app)'] } }`);\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n // Ensure auth property exists\n const authProp = optionsObj.getProperty(\"auth\");\n if (!authProp) {\n optionsObj.addPropertyAssignment({\n name: \"auth\",\n initializer: `{ protectedRoutes: ['/(app)'] }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n // If auth exists, ensure protectedRoutes includes '/(app)'\n if (authProp.getKind() === SyntaxKind.PropertyAssignment) {\n const authInit = (\n authProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (authInit && authInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const authObj = authInit as import(\"ts-morph\").ObjectLiteralExpression;\n const prProp = authObj.getProperty(\"protectedRoutes\");\n if (!prProp) {\n authObj.addPropertyAssignment({\n name: \"protectedRoutes\",\n initializer: `['/(app)']`,\n });\n } else if (prProp.getKind() === SyntaxKind.PropertyAssignment) {\n const prInit = (\n prProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (prInit && prInit.getKind() === SyntaxKind.ArrayLiteralExpression) {\n const arr = prInit as import(\"ts-morph\").ArrayLiteralExpression;\n const hasApp = arr\n .getElements()\n .some((el) => el.getText().replace(/['\"`]/g, \"\") === \"/(app)\");\n if (!hasApp) {\n arr.addElement(`'/(app)'`);\n }\n } else {\n (prProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `['/(app)']`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst COOKIE_LOGIN = dedent`\n // Login is a remote function, so there is no form action to post to: carry\n // the session the way the browser does, in the \\`pb_auth\\` cookie.\n async function authenticateUser(agent: Agent, user: { email?: string }) {\n // Logs in with the password, so it needs the email (made optional by\n // enable-whatsapp, for accounts that sign in with a phone number).\n if (!user.email) {\n throw new Error('authenticateUser needs a user with an email');\n }\n const client = new PocketBase(process.env.POCKETBASE_URL!);\n await client.collection(\"users\").authWithPassword(user.email, testUserPassword);\n agent.set(\"Cookie\", client.authStore.exportToCookie().split(\";\")[0]);\n }\n`;\n\n/**\n * The template's server-test helper logs in by posting the `/login` form\n * action, which this pattern replaces with a remote function. A project\n * without the helper (or with its own) has nothing to fix.\n */\nexport function modifyTestSetup(setupPath: string): ModifyOutcome {\n if (!fs.existsSync(setupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(setupPath);\n const helper = sourceFile.getFunction(\"authenticateUser\");\n\n if (!helper || !/\\.post\\(\\s*[\"'`]\\/login[\"'`]\\s*\\)/.test(helper.getText())) {\n return { status: \"success\", changed: false };\n }\n\n helper.replaceWithText(COOKIE_LOGIN);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { Options, Result, File } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { ensureSiteFile } from \"../../../runtime/site\";\nimport { modifySvelteConfigRemote } from \"../../../runtime/modify-svelte-config-remote\";\n\nimport { modifyLayoutServer } from \"./modifies/+layout.server\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifyTestSetup } from \"./modifies/test-setup\";\n\nexport async function generate(options: Options) {\n const { input } = options;\n const logger = getLogger(options);\n\n const creates: File[] = [];\n\n // Update PocketBase\n await withPocketbase(options.root, async (pb) => {\n logger.info(\"Updating PocketBase mail settings\");\n await pb.settings.update({\n meta: {\n senderName: input.senderName,\n senderAddress: input.senderAddress,\n },\n });\n await migrationDelay();\n\n const userCollection = await pb.collections.getOne(\"users\");\n\n if (!userCollection) {\n throw new Error(\"Users collection not found\");\n }\n\n const verificationTemplate =\n userCollection.verificationTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-verification/{TOKEN}\",\n \"{APP_URL}/confirm-verification/{TOKEN}\",\n );\n const resetPasswordTemplate =\n userCollection.resetPasswordTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-reset/{TOKEN}\",\n \"{APP_URL}/confirm-reset/{TOKEN}\",\n );\n const confirmEmailChangeTemplate =\n userCollection.confirmEmailChangeTemplate.body.replace(\n \"{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}\",\n \"{APP_URL}/confirm-email-change/{TOKEN}\",\n );\n\n logger.info(\"Locking down users collection rules and email templates\");\n // Update user auth rules to lock down access to the user's own account\n await pb.collections.update(\"users\", {\n listRule: \"@request.auth.id = id\",\n viewRule: \"@request.auth.id = id\",\n createRule: \"@request.auth.id = id\",\n updateRule: \"@request.auth.id = id\",\n deleteRule: \"@request.auth.id = id\",\n\n // Update email templates to VelaStack auth urls\n verificationTemplate: {\n body: verificationTemplate,\n },\n resetPasswordTemplate: {\n body: resetPasswordTemplate,\n },\n confirmEmailChangeTemplate: {\n body: confirmEmailChangeTemplate,\n },\n });\n await migrationDelay();\n\n const migrationFile = getMigrationFile(\"users\", \"updated\", options);\n if (migrationFile) {\n creates.push({\n path: migrationFile,\n language: \"ts\",\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n });\n\n // Modify files\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying +layout.server.ts\");\n const layoutServerFile = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(layoutServerFile, modifyLayoutServer(layoutServerFile)),\n );\n\n logger.info(\"Modifying root layout\");\n // TODO: make this more robust by searching for Navbar.Root > Navbar.List\n // src/routes/(public)/root-layout.svelte is what vela creates by default\n const layoutCandidates = [\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 layoutFile =\n layoutCandidates.find((p) => fs.existsSync(p)) ?? layoutCandidates[0];\n pushResult(\n modifyOutcomeToFile(layoutFile, modifyRootLayoutSvelte(layoutFile)),\n );\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerFile = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerFile, modifyHooksServer(hooksServerFile)),\n );\n\n logger.info(\"Modifying test/setup.ts\");\n const testSetupFile = path.join(options.root, \"test\", \"setup.ts\");\n pushResult(\n modifyOutcomeToFile(testSetupFile, modifyTestSetup(testSetupFile)),\n );\n\n logger.info(\"Modifying config for remote functions\");\n const remote = modifySvelteConfigRemote(options.root);\n pushResult(modifyOutcomeToFile(remote.filePath, remote.outcome));\n\n // The auth pages and the app sidebar show `site.name`.\n const siteFile = await ensureSiteFile(options);\n\n return {\n creates: siteFile ? [...creates, siteFile] : creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;AAMA,SAAgBe,EAAmB,GAAmC;CACpE,IAAI,CAACF,EAAG,WAAWG,CAAU,GAAG;EAC9B,IAAMC,IAAU,CAAM;;;;;EAOtB,OADAJ,EAAG,cAAcG,GAAYC,CAAO,GAC7B;GAAE,QAAQ;GAAW,SAAS;EAAK;CAC5C;CAEA,IAAMC,IAAiBL,EAAG,aAAaG,GAAY,MAAM,GAEnDG,IAAa,IADCC,EACD,CAAA,CAAQ,oBAAoBJ,CAAU,GAGnDK,KAAe,MAAoD;EAEvE,AADkBC,EAAI,YAAY,MAAM,KAEtCA,EAAI,sBAAsB;GACxB,MAAM;GACN,aAAa;EACf,CAAC;CAEL,GAGIC,GACAC,GAKEC,IAAUN,EAAW,uBAAuB,MAAM;CACxD,IAAIM,KACSA,EAAQ,uBAAuBC,EAAW,iBAChC,CAAA,EAAI,iBAAiB,GAC1B;EACd,IAAMC,IAAcF,EAAQ,qBAC1BC,EAAW,aACb;EACA,IAAIC,GACF,IAAYA;OACP;GACL,IAAMC,IAAOH,EAAQ,eAAe;GACpC,IAAIG,GAAM;IACR,IAAMC,IAAaD,EAAK,yBACtBF,EAAW,aACb;IACA,IAAIG,GACF,IAAYA;SACP;KACL,IAAMC,IAAcF,EAAK,yBACvBF,EAAW,kBACb;KACA,AAAII,MACF,IAASA;IAEb;GACF;EACF;CACF;CAGF,IAAI,CAACP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