@velastack/patterns 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # VelaStack Patterns
2
+
3
+ The registry for VelaStack patterns.
4
+
5
+ ## Runtime
6
+
7
+ There's two modes this library can be used. One is in runtime, by the @velastack/cli. The VelaStack CLI uses
8
+ Commander to get inputs from the CLI and then calls the pattern:
9
+
10
+ The CLI determines what existing features are in use and passes feature flags to the `loadPattern()` function.
11
+ It also takes any additional wizard inputs from the CLI and passes the data as `input`.
12
+
13
+ ```ts
14
+ const pattern = await registry.loadPattern("generate-form", {
15
+ env: "runtime",
16
+ argv: [
17
+ "generate",
18
+ "form",
19
+ "contact",
20
+ "name:text",
21
+ "email:email",
22
+ "message:editor",
23
+ ],
24
+ root: "/user/project",
25
+ features: {
26
+ auth: false,
27
+ payments: false,
28
+ },
29
+ input: {},
30
+ });
31
+ ```
32
+
33
+ ## Preview
34
+
35
+ The other way is for the velastack.dev/patterns website. Each pattern is available for browsing. Each pattern
36
+ is loaded like this:
37
+
38
+ ```ts
39
+ const pattern = await registry.loadPattern("generate-form", {
40
+ env: "preview",
41
+ argv: [
42
+ "generate",
43
+ "form",
44
+ "contact",
45
+ "name:text",
46
+ "email:email",
47
+ "message:editor",
48
+ ],
49
+ });
50
+ ```
51
+
52
+ In the runtime, @velastack/patterns loads libraries like `pocketbase` and `ts-morph` to make modifications to the user's project.
53
+ This isn't possible in the preview environment, so these changes are mocked with stock output. Keeping this separation is important.
54
+ Any libraries or node requirements must only be imported inside of `generate.runtime.ts` files.
55
+
56
+ Those dependencies are specified as `devDependencies` and also `optionalDependencies` for use with the CLI.
57
+
58
+ ## File Structure
59
+
60
+ For each pattern, `generate.ts` is the main generator. As much of the pattern as possible should be configured here.
61
+ Libraries that can't be run in the preview environment are imported only in `generate.runtime.ts`, this async import
62
+ is only called during the runtime.
63
+
64
+ However, we still need examples of what `generate.runtime.ts` outputs, so we have `generate.preview.ts`, containing
65
+ a static version of what we'd typically get from the runtime.
66
+
67
+ Within each pattern, we have `creates`, `modifies` and `preview-modifies` directories.
68
+
69
+ ### Creates
70
+
71
+ The `creates` directory is directly copied into the target project. Each file is bundled into the library using `import.meta.glob`.
72
+
73
+ ### Modifies
74
+
75
+ The `modifies` directory contains scripts that modify the target project. Modifications use `ts-morph` when possible.
76
+ Each modification should have an extensive test suite with `fixtures/expect` and `fixtures/original` to ensure that
77
+ the modifications work across a wide range of project setups.
78
+
79
+ ### Preview-Modifies
80
+
81
+ The `preview-modifies` directory is the mock modify output used only for previews. It's bundled in the same way as the `creates` directory.
@@ -0,0 +1,38 @@
1
+ import { readFileSync as s } from "node:fs";
2
+ import { l as c } from "./index-D5FMXkZu.js";
3
+ import { w as l, g as u } from "./pocketbase-D612ARa5.js";
4
+ function m(o) {
5
+ var n, a, t, e;
6
+ if (((t = (a = (n = o.response) == null ? void 0 : n.data) == null ? void 0 : a.name) == null ? void 0 : t.code) === "validation_not_unique")
7
+ return !0;
8
+ const r = ((e = o.message) == null ? void 0 : e.toLowerCase()) ?? "";
9
+ return r.includes("already exists") || r.includes("must be unique");
10
+ }
11
+ async function h(o, r) {
12
+ if (o.length === 0)
13
+ return [];
14
+ const n = [];
15
+ return await l(r.root, async (a) => {
16
+ for (const t of o) {
17
+ try {
18
+ await a.collections.create(t);
19
+ } catch (i) {
20
+ throw m(
21
+ i
22
+ ) ? new Error(
23
+ `Collection "${t.name}" already exists. Choose a different model name or remove the existing collection first.`
24
+ ) : i;
25
+ }
26
+ const e = u(t.name, "created", r);
27
+ e && n.push({
28
+ path: e,
29
+ language: c(e),
30
+ content: s(e, "utf8")
31
+ });
32
+ }
33
+ }), n;
34
+ }
35
+ export {
36
+ h as createCollections
37
+ };
38
+ //# sourceMappingURL=collections-BRabBN4M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections-BRabBN4M.js","sources":["../../src/runtime/collections.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type { CollectionSpec, File, Options } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { getMigrationFile, withPocketbase } from \"./pocketbase\";\n\ninterface PocketBaseCollectionCreateError {\n response?: {\n data?: {\n name?: {\n code?: string;\n };\n };\n };\n message?: string;\n}\n\nfunction isCollectionAlreadyExistsError(\n error: PocketBaseCollectionCreateError,\n): boolean {\n if (error.response?.data?.name?.code === \"validation_not_unique\") {\n return true;\n }\n\n const message = error.message?.toLowerCase() ?? \"\";\n return message.includes(\"already exists\") || message.includes(\"must be unique\");\n}\n\nexport async function createCollections(\n collections: CollectionSpec[],\n options: Options,\n): Promise<File[]> {\n if (collections.length === 0) {\n return [];\n }\n\n const migrations: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n for (const collection of collections) {\n try {\n await pb.collections.create(collection);\n } catch (error) {\n if (\n isCollectionAlreadyExistsError(\n error as PocketBaseCollectionCreateError,\n )\n ) {\n throw new Error(\n `Collection \"${collection.name}\" already exists. Choose a different model name or remove the existing collection first.`,\n );\n }\n throw error;\n }\n\n const migrationFile = getMigrationFile(collection.name, \"created\", options);\n if (!migrationFile) {\n continue;\n }\n\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n });\n }\n });\n\n return migrations;\n}\n"],"names":["isCollectionAlreadyExistsError","error","_c","_b","_a","message","_d","createCollections","collections","options","migrations","withPocketbase","pb","collection","migrationFile","getMigrationFile","languageFromPath","readFileSync"],"mappings":";;;AAgBA,SAASA,EACPC,GACS;;AACT,QAAIC,KAAAC,KAAAC,IAAAH,EAAM,aAAN,gBAAAG,EAAgB,SAAhB,gBAAAD,EAAsB,SAAtB,gBAAAD,EAA4B,UAAS;AACvC,WAAO;AAGT,QAAMG,MAAUC,IAAAL,EAAM,YAAN,gBAAAK,EAAe,kBAAiB;AAChD,SAAOD,EAAQ,SAAS,gBAAgB,KAAKA,EAAQ,SAAS,gBAAgB;AAChF;AAEA,eAAsBE,EACpBC,GACAC,GACiB;AACjB,MAAID,EAAY,WAAW;AACzB,WAAO,CAAA;AAGT,QAAME,IAAqB,CAAA;AAE3B,eAAMC,EAAeF,EAAQ,MAAM,OAAOG,MAAO;AAC/C,eAAWC,KAAcL,GAAa;AACpC,UAAI;AACF,cAAMI,EAAG,YAAY,OAAOC,CAAU;AAAA,MACxC,SAASZ,GAAO;AACd,cACED;AAAA,UACEC;AAAA,QAAA,IAGI,IAAI;AAAA,UACR,eAAeY,EAAW,IAAI;AAAA,QAAA,IAG5BZ;AAAA,MACR;AAEA,YAAMa,IAAgBC,EAAiBF,EAAW,MAAM,WAAWJ,CAAO;AAC1E,MAAKK,KAILJ,EAAW,KAAK;AAAA,QACd,MAAMI;AAAA,QACN,UAAUE,EAAiBF,CAAa;AAAA,QACxC,SAASG,EAAaH,GAAe,MAAM;AAAA,MAAA,CAC5C;AAAA,IACH;AAAA,EACF,CAAC,GAEMJ;AACT;"}
@@ -0,0 +1,17 @@
1
+ function t(e) {
2
+ return e.features.auth ? [
3
+ {
4
+ id: "users_preview",
5
+ name: "users",
6
+ type: "auth",
7
+ fields: [
8
+ { name: "email", type: "email" },
9
+ { name: "name", type: "text" }
10
+ ]
11
+ }
12
+ ] : [];
13
+ }
14
+ export {
15
+ t as getPreviewCollections
16
+ };
17
+ //# sourceMappingURL=env.preview-HlXZOEL4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.preview-HlXZOEL4.js","sources":["../../src/parse/env.preview.ts"],"sourcesContent":["import type { Options } from \"../core/types\";\nimport type { Collection } from \"./types\";\n\nexport function getPreviewCollections(\n options: Pick<Options, \"features\">,\n): Collection[] {\n if (options.features.auth) {\n return [\n {\n id: \"users_preview\",\n name: \"users\",\n type: \"auth\",\n fields: [\n { name: \"email\", type: \"email\" },\n { name: \"name\", type: \"text\" },\n ],\n },\n ];\n }\n return [];\n}\n"],"names":["getPreviewCollections","options"],"mappings":"AAGO,SAASA,EACdC,GACc;AACd,SAAIA,EAAQ,SAAS,OACZ;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,QACN,EAAE,MAAM,SAAS,MAAM,QAAA;AAAA,QACvB,EAAE,MAAM,QAAQ,MAAM,OAAA;AAAA,MAAO;AAAA,IAC/B;AAAA,EACF,IAGG,CAAA;AACT;"}
@@ -0,0 +1,36 @@
1
+ import { getCollections as i } from "@velastack/pocketbase/internal";
2
+ import s from "node:fs";
3
+ import r from "node:path";
4
+ import t from "node:process";
5
+ import { D as c } from "./index-D5FMXkZu.js";
6
+ function a(o) {
7
+ return s.existsSync(r.join(o, "package.json")) && s.existsSync(r.join(o, c));
8
+ }
9
+ function p(o = t.cwd()) {
10
+ let e = r.resolve(o);
11
+ for (; ; ) {
12
+ if (a(e))
13
+ return e;
14
+ const n = r.dirname(e);
15
+ if (n === e)
16
+ break;
17
+ e = n;
18
+ }
19
+ throw new Error(
20
+ `Could not resolve project root from "${o}". Expected package.json, and ${c}.`
21
+ );
22
+ }
23
+ async function S() {
24
+ const o = p();
25
+ return i({
26
+ pocketbaseUrl: "",
27
+ superuserEmail: t.env.POCKETBASE_SUPERUSER_EMAIL,
28
+ superuserPassword: t.env.POCKETBASE_SUPERUSER_PASSWORD,
29
+ root: o
30
+ });
31
+ }
32
+ export {
33
+ S as getCollections,
34
+ p as resolveProjectRoot
35
+ };
36
+ //# sourceMappingURL=env.runtime-_7lT2q35.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.runtime-_7lT2q35.js","sources":["../../src/parse/env.runtime.ts"],"sourcesContent":["import { getCollections as getCollectionsFromPB } from \"@velastack/pocketbase/internal\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { DATA_DIR } from \"../core/constants\";\nimport type { Collection } from \"./types\";\n\nfunction hasProjectMarkers(dir: string): boolean {\n return (\n fs.existsSync(path.join(dir, \"package.json\")) &&\n fs.existsSync(path.join(dir, DATA_DIR))\n );\n}\n\nexport function resolveProjectRoot(startDir = process.cwd()): string {\n let current = path.resolve(startDir);\n\n while (true) {\n if (hasProjectMarkers(current)) {\n return current;\n }\n\n const parent = path.dirname(current);\n if (parent === current) {\n break;\n }\n current = parent;\n }\n\n throw new Error(\n `Could not resolve project root from \"${startDir}\". Expected package.json, and ${DATA_DIR}.`,\n );\n}\n\nexport async function getCollections(): Promise<Collection[]> {\n const root = resolveProjectRoot();\n\n return getCollectionsFromPB({\n pocketbaseUrl: \"\",\n superuserEmail: process.env.POCKETBASE_SUPERUSER_EMAIL!,\n superuserPassword: process.env.POCKETBASE_SUPERUSER_PASSWORD!,\n root,\n }) as Promise<Collection[]>;\n}\n"],"names":["hasProjectMarkers","dir","fs","path","DATA_DIR","resolveProjectRoot","startDir","process","current","parent","getCollections","root","getCollectionsFromPB"],"mappings":";;;;;AAOA,SAASA,EAAkBC,GAAsB;AAC/C,SACEC,EAAG,WAAWC,EAAK,KAAKF,GAAK,cAAc,CAAC,KAC5CC,EAAG,WAAWC,EAAK,KAAKF,GAAKG,CAAQ,CAAC;AAE1C;AAEO,SAASC,EAAmBC,IAAWC,EAAQ,OAAe;AACnE,MAAIC,IAAUL,EAAK,QAAQG,CAAQ;AAEnC,aAAa;AACX,QAAIN,EAAkBQ,CAAO;AAC3B,aAAOA;AAGT,UAAMC,IAASN,EAAK,QAAQK,CAAO;AACnC,QAAIC,MAAWD;AACb;AAEF,IAAAA,IAAUC;AAAA,EACZ;AAEA,QAAM,IAAI;AAAA,IACR,wCAAwCH,CAAQ,iCAAiCF,CAAQ;AAAA,EAAA;AAE7F;AAEA,eAAsBM,IAAwC;AAC5D,QAAMC,IAAON,EAAA;AAEb,SAAOO,EAAqB;AAAA,IAC1B,eAAe;AAAA,IACf,gBAAgBL,EAAQ,IAAI;AAAA,IAC5B,mBAAmBA,EAAQ,IAAI;AAAA,IAC/B,MAAAI;AAAA,EAAA,CACD;AACH;"}
@@ -0,0 +1,419 @@
1
+ import y from "node:path";
2
+ import g from "node:fs";
3
+ import { w as S, g as A } from "./pocketbase-D612ARa5.js";
4
+ import { d as v } from "./index-D5FMXkZu.js";
5
+ import { Project as b, SyntaxKind as s } from "ts-morph";
6
+ function w(l) {
7
+ if (!g.existsSync(l)) {
8
+ const e = v`
9
+ export const load = async ({ locals }) => {
10
+ return { user: locals.pb.authStore.record };
11
+ };
12
+ `;
13
+ g.writeFileSync(l, e);
14
+ return;
15
+ }
16
+ const n = new b().addSourceFileAtPath(l), o = (e) => {
17
+ !!e.getProperty("user") || e.addPropertyAssignment({
18
+ name: "user",
19
+ initializer: "locals.pb.authStore.record"
20
+ });
21
+ };
22
+ let u, i;
23
+ const f = n.getVariableDeclaration("load");
24
+ if (f) {
25
+ const e = f.getFirstAncestorByKind(s.VariableStatement);
26
+ if (!!(e != null && e.hasExportKeyword())) {
27
+ const c = f.getInitializerIfKind(
28
+ s.ArrowFunction
29
+ );
30
+ if (c)
31
+ u = c;
32
+ else {
33
+ const t = f.getInitializer();
34
+ if (t) {
35
+ const m = t.getFirstDescendantByKind(
36
+ s.ArrowFunction
37
+ );
38
+ if (m)
39
+ u = m;
40
+ else {
41
+ const h = t.getFirstDescendantByKind(
42
+ s.FunctionExpression
43
+ );
44
+ h && (i = h);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ if (!u) {
51
+ const e = n.getFunction("load");
52
+ e && e.isExported() && (i = e);
53
+ }
54
+ if (!u && !i) {
55
+ n.addFunction({
56
+ isExported: !0,
57
+ isAsync: !0,
58
+ name: "load",
59
+ parameters: [{ name: "{ locals }" }],
60
+ statements: "return { user: locals.pb.authStore.record };"
61
+ }), n.formatText(), n.saveSync();
62
+ return;
63
+ }
64
+ const d = u ?? i, p = d.getParameters();
65
+ if (p.length === 0)
66
+ d.insertParameter(0, { name: "{ locals }" });
67
+ else {
68
+ const e = p[0], r = e.getStructure(), c = e.getNameNode();
69
+ if (c.getKind() === s.ObjectBindingPattern) {
70
+ const t = c;
71
+ if (!t.getElements().some((h) => h.getName() === "locals")) {
72
+ const h = t.getElements().map((E) => E.getText()).filter(Boolean), x = h.length > 0 ? ", " + h.join(", ") : "";
73
+ e.set({
74
+ name: `{ locals${x} }`,
75
+ type: r.type,
76
+ initializer: r.initializer
77
+ });
78
+ }
79
+ } else {
80
+ const t = e.getName();
81
+ t !== "locals" && e.set({
82
+ name: `{ locals, ...${t} }`,
83
+ type: r.type,
84
+ initializer: r.initializer
85
+ });
86
+ }
87
+ }
88
+ if (u) {
89
+ const e = u.getBody();
90
+ if (e.getKind() === s.Block)
91
+ e.getDescendantsOfKind(s.ReturnStatement).forEach((c) => {
92
+ const t = c.getExpression();
93
+ if (t) {
94
+ if (t.getKind() === s.ObjectLiteralExpression)
95
+ o(t);
96
+ else if (t.getKind() === s.ParenthesizedExpression) {
97
+ const m = t.getExpression();
98
+ m.getKind() === s.ObjectLiteralExpression && o(m);
99
+ }
100
+ }
101
+ });
102
+ else {
103
+ const r = e;
104
+ if (r.getKind() === s.ParenthesizedExpression) {
105
+ const c = r.getExpression();
106
+ c.getKind() === s.ObjectLiteralExpression && o(c);
107
+ } else r.getKind() === s.ObjectLiteralExpression && o(r);
108
+ }
109
+ } else if (i) {
110
+ const e = i.getBody();
111
+ e && e.getDescendantsOfKind(s.ReturnStatement).forEach((c) => {
112
+ const t = c.getExpression();
113
+ if (t) {
114
+ if (t.getKind() === s.ObjectLiteralExpression)
115
+ o(t);
116
+ else if (t.getKind() === s.ParenthesizedExpression) {
117
+ const m = t.getExpression();
118
+ m.getKind() === s.ObjectLiteralExpression && o(m);
119
+ }
120
+ }
121
+ });
122
+ }
123
+ n.formatText(), n.saveSync();
124
+ }
125
+ function P(l) {
126
+ let a = g.readFileSync(l, "utf8");
127
+ const n = a.match(/<Navbar\.Root>([\s\S]*?)<\/Navbar\.Root>/);
128
+ if (!n)
129
+ return;
130
+ const o = n[1].match(
131
+ /<Navbar\.List>([\s\S]*?)<\/Navbar\.List>/
132
+ );
133
+ if (!o)
134
+ return;
135
+ const u = v`
136
+ import * as AuthMenu from '$lib/components/ui/auth-menu';
137
+ import * as Avatar from '$lib/components/ui/avatar';
138
+ `, i = a.indexOf("<script");
139
+ if (i !== -1) {
140
+ const d = a.indexOf(">", i), p = d !== -1 ? a.indexOf("<\/script>", d + 1) : -1;
141
+ if (d !== -1 && p !== -1) {
142
+ const e = a.slice(d + 1, p);
143
+ let r = -1;
144
+ const c = /^\s*import[\s\S]*?;[ \t]*$/gm;
145
+ let t;
146
+ for (; (t = c.exec(e)) !== null; )
147
+ r = t.index + t[0].length;
148
+ if (r !== -1) {
149
+ const m = e.slice(0, r), h = e.slice(r), x = `${m}
150
+ ${u}
151
+ ${h}`;
152
+ a = a.slice(0, d + 1) + x + a.slice(p);
153
+ } else
154
+ a = a.replace("<\/script>", `${u}
155
+ <\/script>`);
156
+ } else
157
+ a = a.replace("<\/script>", `${u}
158
+ <\/script>`);
159
+ } else
160
+ a = a.replace("<\/script>", `${u}
161
+ <\/script>`);
162
+ const f = o[1] + `
163
+ <Navbar.Item
164
+ class="flex flex-col md:flex-row items-center space-y-2 md:space-y-0 md:space-x-4"
165
+ >
166
+ <AuthMenu.Root>
167
+ {#snippet user()}
168
+ <AuthMenu.Trigger>
169
+ <Avatar.Root>
170
+ {#if data.user?.avatar}
171
+ <Avatar.Image
172
+ src="/api/files/users/{data.user?.id}/{data.user?.avatar}"
173
+ alt={data.user?.email}
174
+ />
175
+ {/if}
176
+ <Avatar.Fallback>
177
+ {data.user?.email?.charAt(0).toUpperCase()}
178
+ </Avatar.Fallback>
179
+ </Avatar.Root>
180
+ </AuthMenu.Trigger>
181
+
182
+ <AuthMenu.Content align="end">
183
+ <AuthMenu.Item href="/dashboard">Dashboard</AuthMenu.Item>
184
+ <AuthMenu.Group>
185
+ <AuthMenu.Item href="/settings">Settings</AuthMenu.Item>
186
+ <AuthMenu.Item>
187
+ <form action="/logout" method="post">
188
+ <button type="submit" class="contents">Logout</button>
189
+ </form>
190
+ </AuthMenu.Item>
191
+ </AuthMenu.Group>
192
+ </AuthMenu.Content>
193
+ {/snippet}
194
+
195
+ {#snippet guest()}
196
+ <Button
197
+ class="w-full justify-start md:justify-center md:w-auto"
198
+ variant="ghost"
199
+ href="/login">Login</Button
200
+ >
201
+ <Button
202
+ class="w-full justify-start md:justify-center md:w-auto"
203
+ variant="outline"
204
+ href="/signup">Sign up</Button
205
+ >
206
+ {/snippet}
207
+ </AuthMenu.Root>
208
+ </Navbar.Item>
209
+ `;
210
+ a = a.replace(o[1], f), g.writeFileSync(l, a);
211
+ }
212
+ function K(l) {
213
+ const n = new b().addSourceFileAtPath(l), o = n.getDescendantsOfKind(s.CallExpression).find((p) => p.getExpression().getText() === "handlePocketbase");
214
+ if (!o) {
215
+ n.saveSync();
216
+ return;
217
+ }
218
+ const u = o.getArguments();
219
+ if (u.length === 0) {
220
+ o.addArgument("{ auth: { protectedRoutes: ['/(app)'] } }"), n.formatText(), n.saveSync();
221
+ return;
222
+ }
223
+ const i = u[0];
224
+ if (i.getKind() !== s.ObjectLiteralExpression) {
225
+ o.insertArgument(0, "{ auth: { protectedRoutes: ['/(app)'] } }"), n.formatText(), n.saveSync();
226
+ return;
227
+ }
228
+ const f = i.asKindOrThrow(s.ObjectLiteralExpression), d = f.getProperty("auth");
229
+ if (!d) {
230
+ f.addPropertyAssignment({
231
+ name: "auth",
232
+ initializer: "{ protectedRoutes: ['/(app)'] }"
233
+ }), n.formatText(), n.saveSync();
234
+ return;
235
+ }
236
+ if (d.getKind() === s.PropertyAssignment) {
237
+ const p = d.getInitializer();
238
+ if (p && p.getKind() === s.ObjectLiteralExpression) {
239
+ const e = p, r = e.getProperty("protectedRoutes");
240
+ if (!r)
241
+ e.addPropertyAssignment({
242
+ name: "protectedRoutes",
243
+ initializer: "['/(app)']"
244
+ });
245
+ else if (r.getKind() === s.PropertyAssignment) {
246
+ const c = r.getInitializer();
247
+ if (c && c.getKind() === s.ArrayLiteralExpression) {
248
+ const t = c;
249
+ t.getElements().some((h) => h.getText().replace(/['"`]/g, "") === "/(app)") || t.addElement("'/(app)'");
250
+ } else
251
+ r.setInitializer(
252
+ "['/(app)']"
253
+ );
254
+ }
255
+ }
256
+ }
257
+ n.formatText(), n.saveSync();
258
+ }
259
+ async function O(l) {
260
+ const { input: a } = l;
261
+ let n = [];
262
+ await S(l.root, async (d) => {
263
+ await d.settings.update({
264
+ meta: {
265
+ senderName: a.senderName,
266
+ senderAddress: a.senderAddress
267
+ }
268
+ });
269
+ const p = await d.collections.getOne("users");
270
+ if (!p)
271
+ throw new Error("Users collection not found");
272
+ const e = p.verificationTemplate.body.replace(
273
+ "{APP_URL}/_/#/auth/confirm-verification/{TOKEN}",
274
+ "{APP_URL}/confirm-verification/{TOKEN}"
275
+ ), r = p.resetPasswordTemplate.body.replace(
276
+ "{APP_URL}/_/#/auth/confirm-password-reset/{TOKEN}",
277
+ "{APP_URL}/confirm-password-reset/{TOKEN}"
278
+ ), c = p.confirmEmailChangeTemplate.body.replace(
279
+ "{APP_URL}/_/#/auth/confirm-email-change/{TOKEN}",
280
+ "{APP_URL}/confirm-email-change/{TOKEN}"
281
+ );
282
+ await d.collections.update("users", {
283
+ listRule: "@request.auth.id = id",
284
+ viewRule: "@request.auth.id = id",
285
+ createRule: "@request.auth.id = id",
286
+ updateRule: "@request.auth.id = id",
287
+ deleteRule: "@request.auth.id = id",
288
+ // Update email templates to VelaStack auth urls
289
+ verificationTemplate: {
290
+ body: e
291
+ },
292
+ resetPasswordTemplate: {
293
+ body: r
294
+ },
295
+ confirmEmailChangeTemplate: {
296
+ body: c
297
+ }
298
+ });
299
+ const t = A("users", "updated", l);
300
+ t && n.push({
301
+ path: t,
302
+ language: "ts",
303
+ content: g.readFileSync(t, "utf8")
304
+ }), await d.collections.create({
305
+ listRule: "@request.auth.id = user.id",
306
+ viewRule: "@request.auth.id = user.id",
307
+ name: "oauth_accounts",
308
+ type: "base",
309
+ fields: [
310
+ {
311
+ collectionId: p.id,
312
+ name: "user",
313
+ type: "relation",
314
+ required: !0,
315
+ maxSelect: 1
316
+ },
317
+ {
318
+ name: "providerId",
319
+ required: !0,
320
+ type: "text"
321
+ },
322
+ {
323
+ name: "provider",
324
+ required: !0,
325
+ type: "text"
326
+ },
327
+ {
328
+ name: "accessToken",
329
+ type: "text"
330
+ },
331
+ {
332
+ name: "refreshToken",
333
+ type: "text"
334
+ },
335
+ {
336
+ name: "avatarURL",
337
+ type: "text"
338
+ },
339
+ {
340
+ name: "expiry",
341
+ type: "date"
342
+ },
343
+ {
344
+ name: "email",
345
+ type: "text"
346
+ },
347
+ {
348
+ name: "name",
349
+ type: "text"
350
+ },
351
+ {
352
+ name: "username",
353
+ type: "text"
354
+ },
355
+ {
356
+ name: "rawUser",
357
+ type: "json"
358
+ }
359
+ ]
360
+ });
361
+ const m = A(
362
+ "oauth_accounts",
363
+ "created",
364
+ l
365
+ );
366
+ m && n.push({
367
+ path: m,
368
+ language: "ts",
369
+ content: g.readFileSync(m, "utf8")
370
+ });
371
+ });
372
+ let o = [];
373
+ const u = y.join(
374
+ l.root,
375
+ "src",
376
+ "routes",
377
+ "+layout.server.ts"
378
+ );
379
+ await w(u), o.push({
380
+ path: u,
381
+ language: "ts",
382
+ content: g.readFileSync(u, "utf8")
383
+ });
384
+ let i = y.join(
385
+ l.root,
386
+ "src",
387
+ "routes",
388
+ "(public)",
389
+ "root-layout.svelte"
390
+ );
391
+ g.existsSync(i) || (i = y.join(l.root, "src", "routes", "root-layout.svelte")), g.existsSync(i) || (i = y.join(
392
+ l.root,
393
+ "src",
394
+ "routes",
395
+ "(public)",
396
+ "+layout.svelte"
397
+ )), g.existsSync(i) || (i = y.join(l.root, "src", "routes", "+layout.svelte")), g.existsSync(i) && (P(i), o.push({
398
+ path: i,
399
+ language: "svelte",
400
+ content: g.readFileSync(i, "utf8")
401
+ }));
402
+ const f = y.join(l.root, "src", "hooks.server.ts");
403
+ return g.existsSync(f) && (K(f), o.push({
404
+ path: f,
405
+ language: "ts",
406
+ content: g.readFileSync(f, "utf8")
407
+ })), {
408
+ creates: [],
409
+ modifies: o,
410
+ deletes: [],
411
+ components: [],
412
+ packages: [],
413
+ collections: []
414
+ };
415
+ }
416
+ export {
417
+ O as generate
418
+ };
419
+ //# sourceMappingURL=generate.runtime-BR_qnQ-6.js.map