@velastack/patterns 0.0.23 → 0.0.25
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 +9 -16
- package/dist/chunks/{collections-Bzyt18yv.js → collections-DdGJC7Ip.js} +5 -3
- package/dist/chunks/collections-DdGJC7Ip.js.map +1 -0
- package/dist/chunks/{generate.runtime-uPCB71Ki.js → generate.runtime-B0EfMNMf.js} +212 -134
- package/dist/chunks/generate.runtime-B0EfMNMf.js.map +1 -0
- package/dist/chunks/generate.runtime-Bt6kbkWX.js +289 -0
- package/dist/chunks/generate.runtime-Bt6kbkWX.js.map +1 -0
- package/dist/chunks/generate.runtime-BtGvtuWm.js +81 -0
- package/dist/chunks/generate.runtime-BtGvtuWm.js.map +1 -0
- package/dist/chunks/generate.runtime-CcKMIm9M.js +430 -0
- package/dist/chunks/generate.runtime-CcKMIm9M.js.map +1 -0
- package/dist/chunks/generate.runtime-DiJDMdAq.js +207 -0
- package/dist/chunks/generate.runtime-DiJDMdAq.js.map +1 -0
- package/dist/chunks/modify-file-Dxow9QKT.js +22 -0
- package/dist/chunks/modify-file-Dxow9QKT.js.map +1 -0
- package/dist/chunks/{ts-morph-helpers-BiOU9sUx.js → ts-morph-helpers-DmD7iwna.js} +1 -1
- package/dist/chunks/{ts-morph-helpers-BiOU9sUx.js.map → ts-morph-helpers-DmD7iwna.js.map} +1 -1
- package/dist/chunks/{write-result-CSxmq40z.js → write-result-DhQIE6kA.js} +4 -4
- package/dist/chunks/{write-result-CSxmq40z.js.map → write-result-DhQIE6kA.js.map} +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +250 -231
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunks/collections-Bzyt18yv.js.map +0 -1
- package/dist/chunks/generate.runtime-BEuc5hDN.js +0 -225
- package/dist/chunks/generate.runtime-BEuc5hDN.js.map +0 -1
- package/dist/chunks/generate.runtime-CHmm4bBZ.js +0 -154
- package/dist/chunks/generate.runtime-CHmm4bBZ.js.map +0 -1
- package/dist/chunks/generate.runtime-DXkJgkP4.js +0 -232
- package/dist/chunks/generate.runtime-DXkJgkP4.js.map +0 -1
- package/dist/chunks/generate.runtime-egq8I3EA.js +0 -61
- package/dist/chunks/generate.runtime-egq8I3EA.js.map +0 -1
- package/dist/chunks/generate.runtime-uPCB71Ki.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,14 +13,7 @@ It also takes any additional wizard inputs from the CLI and passes the data as `
|
|
|
13
13
|
```ts
|
|
14
14
|
const pattern = await registry.loadPattern("generate-form", {
|
|
15
15
|
env: "runtime",
|
|
16
|
-
argv: [
|
|
17
|
-
"generate",
|
|
18
|
-
"form",
|
|
19
|
-
"contact",
|
|
20
|
-
"name:text",
|
|
21
|
-
"email:email",
|
|
22
|
-
"message:editor",
|
|
23
|
-
],
|
|
16
|
+
argv: ["contact", "name:text", "email:email", "message:editor"],
|
|
24
17
|
root: "/user/project",
|
|
25
18
|
features: {
|
|
26
19
|
auth: false,
|
|
@@ -38,14 +31,7 @@ is loaded like this:
|
|
|
38
31
|
```ts
|
|
39
32
|
const pattern = await registry.loadPattern("generate-form", {
|
|
40
33
|
env: "preview",
|
|
41
|
-
argv: [
|
|
42
|
-
"generate",
|
|
43
|
-
"form",
|
|
44
|
-
"contact",
|
|
45
|
-
"name:text",
|
|
46
|
-
"email:email",
|
|
47
|
-
"message:editor",
|
|
48
|
-
],
|
|
34
|
+
argv: ["contact", "name:text", "email:email", "message:editor"],
|
|
49
35
|
});
|
|
50
36
|
```
|
|
51
37
|
|
|
@@ -91,3 +77,10 @@ The `src/baselines/` directory contains template SvelteKit projects that pattern
|
|
|
91
77
|
Each baseline is a standalone project with its own `package.json`. When working with a baseline locally, run `npm install` inside its directory. The `node_modules` and `.svelte-kit` directories inside baselines are gitignored and must be installed locally before running or testing.
|
|
92
78
|
|
|
93
79
|
Baselines are not bundled into the published package — they are used by the VelaStack CLI's `create` command and by the velastack.dev website.
|
|
80
|
+
|
|
81
|
+
# Workflow for adding new patterns
|
|
82
|
+
|
|
83
|
+
- Develop the pattern in the `src/patterns` directory.
|
|
84
|
+
- Use the demo script to generate a temporary project with the pattern to see applied changes.
|
|
85
|
+
- In the temporary project, run `npm run test:server` to run the tests.
|
|
86
|
+
- Run `npm run lint` and `npm run check` to make sure the code is correct.
|
|
@@ -20,7 +20,8 @@ async function s(n, a, s) {
|
|
|
20
20
|
t && c.push({
|
|
21
21
|
path: t,
|
|
22
22
|
language: e(t),
|
|
23
|
-
content: i(t, "utf8")
|
|
23
|
+
content: i(t, "utf8"),
|
|
24
|
+
status: "success"
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -41,7 +42,8 @@ async function c(o, s) {
|
|
|
41
42
|
o && c.push({
|
|
42
43
|
path: o,
|
|
43
44
|
language: e(o),
|
|
44
|
-
content: i(o, "utf8")
|
|
45
|
+
content: i(o, "utf8"),
|
|
46
|
+
status: "success"
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
}), c;
|
|
@@ -49,4 +51,4 @@ async function c(o, s) {
|
|
|
49
51
|
//#endregion
|
|
50
52
|
export { s as applyCollectionRulePatches, c as createCollections };
|
|
51
53
|
|
|
52
|
-
//# sourceMappingURL=collections-
|
|
54
|
+
//# sourceMappingURL=collections-DdGJC7Ip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections-DdGJC7Ip.js","names":[],"sources":["../../src/runtime/collections.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type {\n CollectionRulesPatch,\n CollectionSpec,\n File,\n Options,\n} from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\nimport { getMigrationFile, migrationDelay, 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 (\n message.includes(\"already exists\") || message.includes(\"must be unique\")\n );\n}\n\nfunction rulePayloadFromPatch(\n patch: CollectionRulesPatch,\n): Record<string, unknown> {\n const payload: Record<string, unknown> = {};\n if (patch.listRule !== undefined) payload.listRule = patch.listRule;\n if (patch.viewRule !== undefined) payload.viewRule = patch.viewRule;\n if (patch.createRule !== undefined) payload.createRule = patch.createRule;\n if (patch.updateRule !== undefined) payload.updateRule = patch.updateRule;\n if (patch.deleteRule !== undefined) payload.deleteRule = patch.deleteRule;\n return payload;\n}\n\n/**\n * Applies API rule updates in array order. Call after all referenced collections exist.\n * Collects migration files produced by each update when `options` is provided.\n */\nexport async function applyCollectionRulePatches(\n pb: {\n collections: {\n getFirstListItem: (filter: string) => Promise<{ id: string }>;\n update: (id: string, body: Record<string, unknown>) => Promise<unknown>;\n };\n },\n patches: CollectionRulesPatch[],\n options?: Options,\n): Promise<File[]> {\n const migrations: File[] = [];\n\n for (const patch of patches) {\n const escaped = patch.collectionName.replace(/'/g, \"''\");\n const col = await pb.collections.getFirstListItem(`name='${escaped}'`);\n await pb.collections.update(col.id, rulePayloadFromPatch(patch));\n await migrationDelay();\n\n if (options) {\n const migrationFile = getMigrationFile(\n patch.collectionName,\n \"updated\",\n options,\n );\n if (migrationFile) {\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n }\n }\n\n return migrations;\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 await migrationDelay();\n\n const migrationFile = getMigrationFile(\n collection.name,\n \"created\",\n options,\n );\n if (!migrationFile) {\n continue;\n }\n\n migrations.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n }\n });\n\n return migrations;\n}\n"],"mappings":";;;;AAqBA,SAAS,EACP,GACS;AACT,KAAI,EAAM,UAAU,MAAM,MAAM,SAAS,wBACvC,QAAO;CAGT,IAAM,IAAU,EAAM,SAAS,aAAa,IAAI;AAChD,QACE,EAAQ,SAAS,iBAAiB,IAAI,EAAQ,SAAS,iBAAiB;;AAI5E,SAAS,EACP,GACyB;CACzB,IAAM,IAAmC,EAAE;AAM3C,QALI,EAAM,aAAa,KAAA,MAAW,EAAQ,WAAW,EAAM,WACvD,EAAM,aAAa,KAAA,MAAW,EAAQ,WAAW,EAAM,WACvD,EAAM,eAAe,KAAA,MAAW,EAAQ,aAAa,EAAM,aAC3D,EAAM,eAAe,KAAA,MAAW,EAAQ,aAAa,EAAM,aAC3D,EAAM,eAAe,KAAA,MAAW,EAAQ,aAAa,EAAM,aACxD;;AAOT,eAAsB,EACpB,GAMA,GACA,GACiB;CACjB,IAAM,IAAqB,EAAE;AAE7B,MAAK,IAAM,KAAS,GAAS;EAC3B,IAAM,IAAU,EAAM,eAAe,QAAQ,MAAM,KAAK,EAClD,IAAM,MAAM,EAAG,YAAY,iBAAiB,SAAS,EAAQ,GAAG;AAItE,MAHA,MAAM,EAAG,YAAY,OAAO,EAAI,IAAI,EAAqB,EAAM,CAAC,EAChE,MAAM,GAAgB,EAElB,GAAS;GACX,IAAM,IAAgB,EACpB,EAAM,gBACN,WACA,EACD;AACD,GAAI,KACF,EAAW,KAAK;IACd,MAAM;IACN,UAAU,EAAiB,EAAc;IACzC,SAAS,EAAa,GAAe,OAAO;IAC5C,QAAQ;IACT,CAAC;;;AAKR,QAAO;;AAGT,eAAsB,EACpB,GACA,GACiB;AACjB,KAAI,EAAY,WAAW,EACzB,QAAO,EAAE;CAGX,IAAM,IAAqB,EAAE;AAsC7B,QApCA,MAAM,EAAe,EAAQ,MAAM,OAAO,MAAO;AAC/C,OAAK,IAAM,KAAc,GAAa;AACpC,OAAI;AACF,UAAM,EAAG,YAAY,OAAO,EAAW;YAChC,GAAO;AAUd,UARE,EACE,EACD,GAES,MACR,eAAe,EAAW,KAAK,0FAChC,GAEG;;AAER,SAAM,GAAgB;GAEtB,IAAM,IAAgB,EACpB,EAAW,MACX,WACA,EACD;AACI,QAIL,EAAW,KAAK;IACd,MAAM;IACN,UAAU,EAAiB,EAAc;IACzC,SAAS,EAAa,GAAe,OAAO;IAC5C,QAAQ;IACT,CAAC;;GAEJ,EAEK"}
|
|
@@ -2,23 +2,69 @@ import { t as e } from "./dedent-BFNYR8cb.js";
|
|
|
2
2
|
import { n as t } from "./util-k-qPjL06.js";
|
|
3
3
|
import { t as n } from "./pocketbase-CSl9ydRr.js";
|
|
4
4
|
import { n as r, r as i, t as a } from "./pocketbase-CPRrN7Qs.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import d from "
|
|
8
|
-
import f from "node:
|
|
9
|
-
import
|
|
5
|
+
import { t as o } from "./modify-file-Dxow9QKT.js";
|
|
6
|
+
import { i as s, n as c, r as l, t as u } from "./ts-morph-helpers-DmD7iwna.js";
|
|
7
|
+
import { applyCollectionRulePatches as d } from "./collections-DdGJC7Ip.js";
|
|
8
|
+
import f from "node:fs";
|
|
9
|
+
import p from "node:path";
|
|
10
|
+
import { Project as m, SyntaxKind as h } from "ts-morph";
|
|
10
11
|
//#region src/patterns/enable/teams/modifies/modify-app-layout.ts
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var g = [
|
|
13
|
+
"Pass team props to <AppSidebar> in your app layout:",
|
|
14
|
+
"",
|
|
15
|
+
"<AppSidebar team={data.team} teams={data.teams ?? []} />"
|
|
16
|
+
].join("\n"), _ = [
|
|
17
|
+
"Create an app layout that renders <AppSidebar> with team props:",
|
|
18
|
+
"",
|
|
19
|
+
"<AppSidebar team={data.team} teams={data.teams ?? []} />"
|
|
20
|
+
].join("\n");
|
|
21
|
+
function v(e) {
|
|
22
|
+
if (!f.existsSync(e)) return {
|
|
23
|
+
status: "not-found",
|
|
24
|
+
message: _
|
|
25
|
+
};
|
|
26
|
+
let t = s.fromPath(e);
|
|
27
|
+
return t.hasElement("AppSidebar") ? t.hasAttribute("AppSidebar", "teams") ? {
|
|
28
|
+
status: "success",
|
|
29
|
+
changed: !1
|
|
30
|
+
} : (t.appendToAttributes("AppSidebar", " team={data.team} teams={data.teams ?? []}"), t.writeTo(e), {
|
|
31
|
+
status: "success",
|
|
32
|
+
changed: t.hasChanged()
|
|
33
|
+
}) : {
|
|
34
|
+
status: "failed",
|
|
35
|
+
message: g
|
|
36
|
+
};
|
|
15
37
|
}
|
|
16
38
|
//#endregion
|
|
17
39
|
//#region src/patterns/enable/teams/modifies/modify-app-sidebar.ts
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
40
|
+
var y = "<Sidebar.Header>\n <Sidebar.Menu>\n <TeamSwitcher {teams}>\n {#snippet children()}\n {@const activeTeam = teams.find((t) => t.id === team)}\n {#if activeTeam}\n <Avatar.Root class=\"size-8 rounded-lg\">\n <Avatar.Fallback class=\"rounded-lg bg-primary text-primary-foreground font-medium\">\n {activeTeam.name?.charAt(0).toUpperCase()}\n </Avatar.Fallback>\n </Avatar.Root>\n <div class=\"grid flex-1 text-left text-sm leading-tight\">\n <span class=\"truncate font-medium\">\n {activeTeam.name}\n </span>\n </div>\n {:else}\n <div\n class=\"bg-sidebar-accent text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg\"\n >\n <img src=\"/favicon.svg\" alt=\"logo\" class=\"size-6\" />\n </div>\n <div class=\"grid flex-1 text-left text-sm leading-tight\">\n <span class=\"truncate font-medium\">{meta.appName}</span>\n </div>\n {/if}\n <ChevronsUpDownIcon class=\"ml-auto\" />\n {/snippet}\n </TeamSwitcher>\n </Sidebar.Menu>\n </Sidebar.Header>", b = [
|
|
41
|
+
"import TeamSwitcher from '$lib/components/team-switcher.svelte';",
|
|
42
|
+
"import ChevronsUpDownIcon from '@lucide/svelte/icons/chevrons-up-down';",
|
|
43
|
+
"import * as Avatar from '$lib/components/ui/avatar';"
|
|
44
|
+
].join("\n"), x = [
|
|
45
|
+
"Replace the <Sidebar.Header> in your app sidebar with the team switcher.",
|
|
46
|
+
"",
|
|
47
|
+
"Imports to add to the <script> tag:",
|
|
48
|
+
"",
|
|
49
|
+
b,
|
|
50
|
+
"",
|
|
51
|
+
"Props to destructure in $props(): team, teams = []",
|
|
52
|
+
"",
|
|
53
|
+
"Markup to use as the header:",
|
|
54
|
+
y
|
|
55
|
+
].join("\n"), S = [
|
|
56
|
+
"Create an app sidebar with a <Sidebar.Header> containing the team switcher.",
|
|
57
|
+
"",
|
|
58
|
+
"Imports:",
|
|
59
|
+
"",
|
|
60
|
+
b,
|
|
61
|
+
"",
|
|
62
|
+
"Header markup:",
|
|
63
|
+
y
|
|
64
|
+
].join("\n");
|
|
65
|
+
function C(e) {
|
|
66
|
+
let { source: t } = l(e, (e) => {
|
|
67
|
+
c(e, [
|
|
22
68
|
{
|
|
23
69
|
defaultImport: "TeamSwitcher",
|
|
24
70
|
moduleSpecifier: "$lib/components/team-switcher.svelte"
|
|
@@ -36,15 +82,15 @@ function _(e) {
|
|
|
36
82
|
let e = t.getInitializer();
|
|
37
83
|
if (!e || e.getText() !== "$props()") continue;
|
|
38
84
|
let n = t.getNameNode();
|
|
39
|
-
if (n.getKind() !==
|
|
40
|
-
let r = n.asKindOrThrow(
|
|
85
|
+
if (n.getKind() !== h.ObjectBindingPattern) continue;
|
|
86
|
+
let r = n.asKindOrThrow(h.ObjectBindingPattern), i = r.getElements();
|
|
41
87
|
if (i.some((e) => e.getName() === "team")) continue;
|
|
42
88
|
let a = t.getTypeNode();
|
|
43
|
-
if (a?.getKind() ===
|
|
44
|
-
let e = a.asKindOrThrow(
|
|
89
|
+
if (a?.getKind() === h.IntersectionType) {
|
|
90
|
+
let e = a.asKindOrThrow(h.IntersectionType);
|
|
45
91
|
for (let t of e.getTypeNodes()) {
|
|
46
|
-
if (t.getKind() !==
|
|
47
|
-
let e = t.asKindOrThrow(
|
|
92
|
+
if (t.getKind() !== h.TypeLiteral) continue;
|
|
93
|
+
let e = t.asKindOrThrow(h.TypeLiteral), n = e.getProperties().map((e) => e.getText().replace(/[;,]\s*$/, ""));
|
|
48
94
|
if (n.some((e) => /^team\b/.test(e))) break;
|
|
49
95
|
n.push("team?: string | undefined", "teams?: { id: string; name: string }[]"), e.replaceWithText(`{ ${n.join("; ")}; }`);
|
|
50
96
|
break;
|
|
@@ -57,15 +103,27 @@ function _(e) {
|
|
|
57
103
|
});
|
|
58
104
|
return t;
|
|
59
105
|
}
|
|
60
|
-
function
|
|
61
|
-
if (!
|
|
62
|
-
|
|
63
|
-
|
|
106
|
+
function w(e) {
|
|
107
|
+
if (!f.existsSync(e)) return {
|
|
108
|
+
status: "not-found",
|
|
109
|
+
message: S
|
|
110
|
+
};
|
|
111
|
+
let t = s.fromPath(e);
|
|
112
|
+
return t.hasElement("TeamSwitcher") ? {
|
|
113
|
+
status: "success",
|
|
114
|
+
changed: !1
|
|
115
|
+
} : t.hasElement("Sidebar.Header") ? (t.modifyScript(C), t.replaceElement("Sidebar.Header", y), t.writeTo(e), {
|
|
116
|
+
status: "success",
|
|
117
|
+
changed: t.hasChanged()
|
|
118
|
+
}) : {
|
|
119
|
+
status: "failed",
|
|
120
|
+
message: x
|
|
121
|
+
};
|
|
64
122
|
}
|
|
65
123
|
//#endregion
|
|
66
124
|
//#region src/patterns/enable/teams/modifies/+layout.server.ts
|
|
67
|
-
function
|
|
68
|
-
if (!
|
|
125
|
+
function T(t) {
|
|
126
|
+
if (!f.existsSync(t)) {
|
|
69
127
|
let n = e`
|
|
70
128
|
export const load = async ({ locals, depends }) => {
|
|
71
129
|
const user = locals.pb.authStore.record!;
|
|
@@ -77,57 +135,59 @@ function y(t) {
|
|
|
77
135
|
return { user, team, teams, breadcrumbs };
|
|
78
136
|
};
|
|
79
137
|
`;
|
|
80
|
-
|
|
81
|
-
|
|
138
|
+
return f.writeFileSync(t, n), {
|
|
139
|
+
status: "success",
|
|
140
|
+
changed: !0
|
|
141
|
+
};
|
|
82
142
|
}
|
|
83
|
-
let n = new
|
|
143
|
+
let n = f.readFileSync(t, "utf8"), r = new m().addSourceFileAtPath(t), i = (e, t, n) => {
|
|
84
144
|
e.getProperty(t) || (t === n ? e.addShorthandPropertyAssignment({ name: t }) : e.addPropertyAssignment({
|
|
85
145
|
name: t,
|
|
86
146
|
initializer: n
|
|
87
147
|
}));
|
|
88
|
-
},
|
|
89
|
-
if (
|
|
90
|
-
let e =
|
|
91
|
-
if (e)
|
|
148
|
+
}, a, o, s = r.getVariableDeclaration("load");
|
|
149
|
+
if (s && s.getFirstAncestorByKind(h.VariableStatement)?.hasExportKeyword()) {
|
|
150
|
+
let e = s.getInitializerIfKind(h.ArrowFunction);
|
|
151
|
+
if (e) a = e;
|
|
92
152
|
else {
|
|
93
|
-
let e =
|
|
153
|
+
let e = s.getInitializer();
|
|
94
154
|
if (e) {
|
|
95
|
-
let t = e.getFirstDescendantByKind(
|
|
96
|
-
if (t)
|
|
155
|
+
let t = e.getFirstDescendantByKind(h.ArrowFunction);
|
|
156
|
+
if (t) a = t;
|
|
97
157
|
else {
|
|
98
|
-
let t = e.getFirstDescendantByKind(
|
|
99
|
-
t && (
|
|
158
|
+
let t = e.getFirstDescendantByKind(h.FunctionExpression);
|
|
159
|
+
t && (o = t);
|
|
100
160
|
}
|
|
101
161
|
}
|
|
102
162
|
}
|
|
103
163
|
}
|
|
104
|
-
if (!
|
|
105
|
-
let e =
|
|
106
|
-
e && e.isExported() && (
|
|
107
|
-
}
|
|
108
|
-
if (!i && !a) {
|
|
109
|
-
n.addFunction({
|
|
110
|
-
isExported: !0,
|
|
111
|
-
isAsync: !0,
|
|
112
|
-
name: "load",
|
|
113
|
-
parameters: [{ name: "{ locals, depends }" }],
|
|
114
|
-
statements: [
|
|
115
|
-
"const user = locals.pb.authStore.record!;",
|
|
116
|
-
"const team = locals.team;",
|
|
117
|
-
"const teams = await locals.pb.collection(\"teams\").getFullList();",
|
|
118
|
-
"depends(\"app:team\");",
|
|
119
|
-
"",
|
|
120
|
-
"const breadcrumbs = [{ title: \"Home\", url: \"/dashboard\" }];",
|
|
121
|
-
"return { user, team, teams, breadcrumbs };"
|
|
122
|
-
]
|
|
123
|
-
}), n.formatText(), n.saveSync();
|
|
124
|
-
return;
|
|
164
|
+
if (!a) {
|
|
165
|
+
let e = r.getFunction("load");
|
|
166
|
+
e && e.isExported() && (o = e);
|
|
125
167
|
}
|
|
126
|
-
|
|
127
|
-
|
|
168
|
+
if (!a && !o) return r.addFunction({
|
|
169
|
+
isExported: !0,
|
|
170
|
+
isAsync: !0,
|
|
171
|
+
name: "load",
|
|
172
|
+
parameters: [{ name: "{ locals, depends }" }],
|
|
173
|
+
statements: [
|
|
174
|
+
"const user = locals.pb.authStore.record!;",
|
|
175
|
+
"const team = locals.team;",
|
|
176
|
+
"const teams = await locals.pb.collection(\"teams\").getFullList();",
|
|
177
|
+
"depends(\"app:team\");",
|
|
178
|
+
"",
|
|
179
|
+
"const breadcrumbs = [{ title: \"Home\", url: \"/dashboard\" }];",
|
|
180
|
+
"return { user, team, teams, breadcrumbs };"
|
|
181
|
+
]
|
|
182
|
+
}), r.formatText(), r.saveSync(), {
|
|
183
|
+
status: "success",
|
|
184
|
+
changed: !0
|
|
185
|
+
};
|
|
186
|
+
let c = a ?? o, l = c.getParameters();
|
|
187
|
+
if (l.length === 0) c.insertParameter(0, { name: "{ locals, depends }" });
|
|
128
188
|
else {
|
|
129
|
-
let e =
|
|
130
|
-
if (n.getKind() ===
|
|
189
|
+
let e = l[0], t = e.getStructure(), n = e.getNameNode();
|
|
190
|
+
if (n.getKind() === h.ObjectBindingPattern) {
|
|
131
191
|
let r = n, i = r.getElements().some((e) => e.getName() === "depends"), a = r.getElements().some((e) => e.getName() === "locals");
|
|
132
192
|
if (!i) {
|
|
133
193
|
let n = r.getElements().map((e) => e.getText()).filter(Boolean), i = n.length > 0 ? ", " + n.join(", ") : "";
|
|
@@ -154,97 +214,129 @@ function y(t) {
|
|
|
154
214
|
});
|
|
155
215
|
}
|
|
156
216
|
}
|
|
157
|
-
|
|
158
|
-
let
|
|
159
|
-
if (
|
|
160
|
-
let e =
|
|
217
|
+
a && !a.isAsync() ? a.setIsAsync(!0) : o && !o.isAsync() && o.setIsAsync(!0);
|
|
218
|
+
let u = c.getBody();
|
|
219
|
+
if (u && u.getKind() === h.Block) {
|
|
220
|
+
let e = u, t = e.getStatements(), n = t.some((e) => e.getKind() === h.VariableStatement && e.getDescendantsOfKind(h.Identifier).some((e) => e.getText() === "team")), r = t.some((e) => e.getKind() === h.VariableStatement && e.getDescendantsOfKind(h.Identifier).some((e) => e.getText() === "teams")), i = t.some((e) => e.getKind() === h.ExpressionStatement && e.getDescendantsOfKind(h.CallExpression).some((e) => {
|
|
161
221
|
if (e.getExpression().getText() !== "depends") return !1;
|
|
162
222
|
let t = e.getArguments(), n = t[0]?.getText() ?? "";
|
|
163
223
|
return t.length === 1 && (n === "'app:team'" || n === "\"app:team\"");
|
|
164
224
|
}));
|
|
165
225
|
n || e.insertStatements(1, "const team = locals.team;"), r || e.insertStatements(2, "const teams = await locals.pb.collection(\"teams\").getFullList();"), i || e.insertStatements(3, "depends(\"app:team\");");
|
|
166
226
|
}
|
|
167
|
-
if (
|
|
168
|
-
let e =
|
|
169
|
-
if (e.getKind() ===
|
|
227
|
+
if (a) {
|
|
228
|
+
let e = a.getBody();
|
|
229
|
+
if (e.getKind() === h.Block) e.getDescendantsOfKind(h.ReturnStatement).forEach((e) => {
|
|
170
230
|
let t = e.getExpression();
|
|
171
231
|
if (t) {
|
|
172
|
-
if (t.getKind() ===
|
|
232
|
+
if (t.getKind() === h.ObjectLiteralExpression) {
|
|
173
233
|
let e = t;
|
|
174
|
-
|
|
175
|
-
} else if (t.getKind() ===
|
|
234
|
+
i(e, "team", "team"), i(e, "teams", "teams");
|
|
235
|
+
} else if (t.getKind() === h.ParenthesizedExpression) {
|
|
176
236
|
let e = t.getExpression();
|
|
177
|
-
if (e.getKind() ===
|
|
237
|
+
if (e.getKind() === h.ObjectLiteralExpression) {
|
|
178
238
|
let t = e;
|
|
179
|
-
|
|
239
|
+
i(t, "team", "team"), i(t, "teams", "teams");
|
|
180
240
|
}
|
|
181
241
|
}
|
|
182
242
|
}
|
|
183
243
|
});
|
|
184
244
|
else {
|
|
185
245
|
let t = e;
|
|
186
|
-
if (t.getKind() ===
|
|
246
|
+
if (t.getKind() === h.ParenthesizedExpression) {
|
|
187
247
|
let e = t.getExpression();
|
|
188
|
-
if (e.getKind() ===
|
|
248
|
+
if (e.getKind() === h.ObjectLiteralExpression) {
|
|
189
249
|
let t = e;
|
|
190
|
-
|
|
250
|
+
i(t, "team", "team"), i(t, "teams", "teams");
|
|
191
251
|
}
|
|
192
|
-
} else if (t.getKind() ===
|
|
252
|
+
} else if (t.getKind() === h.ObjectLiteralExpression) {
|
|
193
253
|
let e = t;
|
|
194
|
-
|
|
254
|
+
i(e, "team", "team"), i(e, "teams", "teams");
|
|
195
255
|
}
|
|
196
256
|
}
|
|
197
|
-
} else if (
|
|
198
|
-
let e =
|
|
199
|
-
e && e.getDescendantsOfKind(
|
|
257
|
+
} else if (o) {
|
|
258
|
+
let e = o.getBody();
|
|
259
|
+
e && e.getDescendantsOfKind(h.ReturnStatement).forEach((e) => {
|
|
200
260
|
let t = e.getExpression();
|
|
201
261
|
if (t) {
|
|
202
|
-
if (t.getKind() ===
|
|
262
|
+
if (t.getKind() === h.ObjectLiteralExpression) {
|
|
203
263
|
let e = t;
|
|
204
|
-
|
|
205
|
-
} else if (t.getKind() ===
|
|
264
|
+
i(e, "team", "team"), i(e, "teams", "teams");
|
|
265
|
+
} else if (t.getKind() === h.ParenthesizedExpression) {
|
|
206
266
|
let e = t.getExpression();
|
|
207
|
-
if (e.getKind() ===
|
|
267
|
+
if (e.getKind() === h.ObjectLiteralExpression) {
|
|
208
268
|
let t = e;
|
|
209
|
-
|
|
269
|
+
i(t, "team", "team"), i(t, "teams", "teams");
|
|
210
270
|
}
|
|
211
271
|
}
|
|
212
272
|
}
|
|
213
273
|
});
|
|
214
274
|
}
|
|
215
|
-
|
|
275
|
+
return r.formatText(), r.saveSync(), {
|
|
276
|
+
status: "success",
|
|
277
|
+
changed: r.getFullText() !== n
|
|
278
|
+
};
|
|
216
279
|
}
|
|
217
280
|
//#endregion
|
|
218
281
|
//#region src/patterns/enable/teams/modifies/modify-nav-user.ts
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
282
|
+
var E = [
|
|
283
|
+
"import UsersIcon from '@lucide/svelte/icons/users';",
|
|
284
|
+
"",
|
|
285
|
+
"// Add to your navUser array:",
|
|
286
|
+
"{ title: 'Teams', url: '/teams', icon: UsersIcon }"
|
|
287
|
+
].join("\n"), D = [
|
|
288
|
+
"Add a Teams nav item to nav-user.svelte:",
|
|
289
|
+
"",
|
|
290
|
+
E
|
|
291
|
+
].join("\n"), O = [
|
|
292
|
+
"Create nav-user.svelte with a Teams entry:",
|
|
293
|
+
"",
|
|
294
|
+
E
|
|
295
|
+
].join("\n");
|
|
296
|
+
function k(e, t, n, r, i) {
|
|
297
|
+
let a = new s(e), o = !1, c = (e) => {
|
|
298
|
+
o || e((e) => {
|
|
299
|
+
let a = u(e, t, n, r, i);
|
|
300
|
+
return a.wasAdded && (o = !0), a.source;
|
|
224
301
|
});
|
|
225
302
|
};
|
|
226
|
-
return c((e) => a.modifyModuleScript(e)),
|
|
303
|
+
return c((e) => a.modifyModuleScript(e)), o || c((e) => a.modifyScript(e)), {
|
|
227
304
|
newNavUserSnippet: a.toString(),
|
|
228
|
-
wasAdded:
|
|
305
|
+
wasAdded: o
|
|
229
306
|
};
|
|
230
307
|
}
|
|
231
|
-
function
|
|
232
|
-
if (!
|
|
233
|
-
|
|
234
|
-
|
|
308
|
+
function A(e) {
|
|
309
|
+
if (!f.existsSync(e)) return {
|
|
310
|
+
status: "not-found",
|
|
311
|
+
message: O
|
|
312
|
+
};
|
|
313
|
+
let t = f.readFileSync(e, "utf8");
|
|
314
|
+
if (t.includes("/teams")) return {
|
|
315
|
+
status: "success",
|
|
316
|
+
changed: !1
|
|
317
|
+
};
|
|
318
|
+
let { newNavUserSnippet: n, wasAdded: r } = k(t, "Teams", "/teams", "UsersIcon", "@lucide/svelte/icons/users");
|
|
319
|
+
return r ? (f.writeFileSync(e, n, "utf8"), {
|
|
320
|
+
status: "success",
|
|
321
|
+
changed: !0
|
|
322
|
+
}) : {
|
|
323
|
+
status: "failed",
|
|
324
|
+
message: D
|
|
325
|
+
};
|
|
235
326
|
}
|
|
236
327
|
//#endregion
|
|
237
328
|
//#region src/patterns/enable/teams/generate.runtime.ts
|
|
238
|
-
async function
|
|
329
|
+
async function j(e, n, i) {
|
|
239
330
|
await r();
|
|
240
331
|
let o = a(n, "created", i);
|
|
241
332
|
o && e.push({
|
|
242
333
|
path: o,
|
|
243
334
|
language: t(o),
|
|
244
|
-
content:
|
|
335
|
+
content: f.readFileSync(o, "utf8"),
|
|
336
|
+
status: "success"
|
|
245
337
|
});
|
|
246
338
|
}
|
|
247
|
-
async function
|
|
339
|
+
async function M(e) {
|
|
248
340
|
let t = [];
|
|
249
341
|
await i(e.root, async (r) => {
|
|
250
342
|
let i = await r.collections.getOne("users"), a = await r.collections.create({
|
|
@@ -289,7 +381,7 @@ async function C(e) {
|
|
|
289
381
|
}
|
|
290
382
|
]
|
|
291
383
|
});
|
|
292
|
-
await
|
|
384
|
+
await j(t, "teams", e);
|
|
293
385
|
let o = await r.collections.create({
|
|
294
386
|
name: "team_memberships",
|
|
295
387
|
type: "base",
|
|
@@ -347,7 +439,7 @@ async function C(e) {
|
|
|
347
439
|
}
|
|
348
440
|
]
|
|
349
441
|
});
|
|
350
|
-
await
|
|
442
|
+
await j(t, "team_memberships", e), await r.collections.create({
|
|
351
443
|
name: "team_users",
|
|
352
444
|
type: "view",
|
|
353
445
|
fields: [
|
|
@@ -402,7 +494,7 @@ async function C(e) {
|
|
|
402
494
|
}
|
|
403
495
|
],
|
|
404
496
|
viewQuery: "select users.id, users.email, users.name, team_memberships.id as membership_id, team_memberships.team, team_memberships.role from users join team_memberships on team_memberships.user = users.id;"
|
|
405
|
-
}), await
|
|
497
|
+
}), await j(t, "team_users", e), await r.collections.create({
|
|
406
498
|
name: "team_invites",
|
|
407
499
|
type: "base",
|
|
408
500
|
fields: [
|
|
@@ -443,7 +535,7 @@ async function C(e) {
|
|
|
443
535
|
type: "autodate"
|
|
444
536
|
}
|
|
445
537
|
]
|
|
446
|
-
}), await
|
|
538
|
+
}), await j(t, "team_invites", e), await r.collections.create({
|
|
447
539
|
name: "team_invite_links",
|
|
448
540
|
type: "base",
|
|
449
541
|
fields: [
|
|
@@ -480,34 +572,20 @@ async function C(e) {
|
|
|
480
572
|
}
|
|
481
573
|
],
|
|
482
574
|
indexes: ["CREATE UNIQUE INDEX `idx_9y3Oz1KVzz` ON `team_invite_links` (`team`)"]
|
|
483
|
-
}), await
|
|
484
|
-
let s = await
|
|
575
|
+
}), await j(t, "team_invite_links", e);
|
|
576
|
+
let s = await d(r, n, e);
|
|
485
577
|
t.push(...s);
|
|
486
578
|
});
|
|
487
|
-
let r = [], a =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
let
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
content: d.readFileSync(o, "utf8")
|
|
498
|
-
});
|
|
499
|
-
let s = f.join(e.root, "src", "lib", "components", "app-sidebar.svelte");
|
|
500
|
-
d.existsSync(s) && v(s) && r.push({
|
|
501
|
-
path: s,
|
|
502
|
-
language: "svelte",
|
|
503
|
-
content: d.readFileSync(s, "utf8")
|
|
504
|
-
});
|
|
505
|
-
let c = f.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
506
|
-
return x(c) && r.push({
|
|
507
|
-
path: c,
|
|
508
|
-
language: "svelte",
|
|
509
|
-
content: d.readFileSync(c, "utf8")
|
|
510
|
-
}), {
|
|
579
|
+
let r = [], a = (e) => {
|
|
580
|
+
e && r.push(e);
|
|
581
|
+
}, s = p.join(e.root, "src", "routes", "(app)", "+layout.server.ts");
|
|
582
|
+
a(o(s, T(s)));
|
|
583
|
+
let c = p.join(e.root, "src", "routes", "(app)", "+layout.svelte");
|
|
584
|
+
a(o(c, v(c)));
|
|
585
|
+
let l = p.join(e.root, "src", "lib", "components", "app-sidebar.svelte");
|
|
586
|
+
a(o(l, w(l)));
|
|
587
|
+
let u = p.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
588
|
+
return a(o(u, A(u))), {
|
|
511
589
|
creates: t,
|
|
512
590
|
modifies: r,
|
|
513
591
|
deletes: [],
|
|
@@ -517,6 +595,6 @@ async function C(e) {
|
|
|
517
595
|
};
|
|
518
596
|
}
|
|
519
597
|
//#endregion
|
|
520
|
-
export {
|
|
598
|
+
export { M as generate };
|
|
521
599
|
|
|
522
|
-
//# sourceMappingURL=generate.runtime-
|
|
600
|
+
//# sourceMappingURL=generate.runtime-B0EfMNMf.js.map
|