@velastack/patterns 0.0.61 → 0.1.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/dist/chunks/_server-BSm1eAiY.js +6 -0
- package/dist/chunks/_server-BSm1eAiY.js.map +1 -0
- package/dist/chunks/{collections-DZOoJLVj.js → collections-DgZjDXef.js} +2 -2
- package/dist/chunks/{collections-DZOoJLVj.js.map → collections-DgZjDXef.js.map} +1 -1
- package/dist/chunks/{config-target-Co-ij8p3.js → config-target-DOi8kI_f.js} +9 -9
- package/dist/chunks/{config-target-Co-ij8p3.js.map → config-target-DOi8kI_f.js.map} +1 -1
- package/dist/chunks/{generate.runtime-6qpoLA04.js → generate.runtime--0bYEUP_.js} +19 -19
- package/dist/chunks/{generate.runtime-6qpoLA04.js.map → generate.runtime--0bYEUP_.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DBG6kEKb.js → generate.runtime-677mL0-8.js} +17 -17
- package/dist/chunks/{generate.runtime-DBG6kEKb.js.map → generate.runtime-677mL0-8.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CtzHFod-.js → generate.runtime-BOLZHcGN.js} +24 -24
- package/dist/chunks/{generate.runtime-CtzHFod-.js.map → generate.runtime-BOLZHcGN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DfqzMG8Z.js → generate.runtime-BgW9zLGZ.js} +2 -2
- package/dist/chunks/{generate.runtime-DfqzMG8Z.js.map → generate.runtime-BgW9zLGZ.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CYmjlSQp.js → generate.runtime-C52G7ZnV.js} +15 -15
- package/dist/chunks/{generate.runtime-CYmjlSQp.js.map → generate.runtime-C52G7ZnV.js.map} +1 -1
- package/dist/chunks/{generate.runtime-a5PXS1Kd.js → generate.runtime-CDSkTWtx.js} +10 -10
- package/dist/chunks/{generate.runtime-a5PXS1Kd.js.map → generate.runtime-CDSkTWtx.js.map} +1 -1
- package/dist/chunks/{generate.runtime-AmiNbSR3.js → generate.runtime-CFKrhkAA.js} +12 -12
- package/dist/chunks/{generate.runtime-AmiNbSR3.js.map → generate.runtime-CFKrhkAA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BnnsaLsg.js → generate.runtime-CFwzS666.js} +12 -12
- package/dist/chunks/{generate.runtime-BnnsaLsg.js.map → generate.runtime-CFwzS666.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CRS9C9xX.js → generate.runtime-CG0gMypH.js} +14 -14
- package/dist/chunks/{generate.runtime-CRS9C9xX.js.map → generate.runtime-CG0gMypH.js.map} +1 -1
- package/dist/chunks/{generate.runtime-rfNiROHo.js → generate.runtime-CNwy0UB2.js} +30 -30
- package/dist/chunks/{generate.runtime-rfNiROHo.js.map → generate.runtime-CNwy0UB2.js.map} +1 -1
- package/dist/chunks/{generate.runtime-D9t6eaQd.js → generate.runtime-Cc1SG-nN.js} +20 -20
- package/dist/chunks/{generate.runtime-D9t6eaQd.js.map → generate.runtime-Cc1SG-nN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Di0p-J8l.js → generate.runtime-CfclK4xT.js} +12 -12
- package/dist/chunks/{generate.runtime-Di0p-J8l.js.map → generate.runtime-CfclK4xT.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CtS6qa_1.js → generate.runtime-Coi_Y6nm.js} +22 -22
- package/dist/chunks/generate.runtime-Coi_Y6nm.js.map +1 -0
- package/dist/chunks/{generate.runtime-EokncTLy.js → generate.runtime-Dad9oAKS.js} +27 -27
- package/dist/chunks/{generate.runtime-EokncTLy.js.map → generate.runtime-Dad9oAKS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CNxgU9v1.js → generate.runtime-Dbhctzy1.js} +17 -17
- package/dist/chunks/{generate.runtime-CNxgU9v1.js.map → generate.runtime-Dbhctzy1.js.map} +1 -1
- package/dist/chunks/{generate.runtime-P8IVwJLB.js → generate.runtime-DpV_oOT7.js} +23 -23
- package/dist/chunks/{generate.runtime-P8IVwJLB.js.map → generate.runtime-DpV_oOT7.js.map} +1 -1
- package/dist/chunks/{generate.runtime-6TJoTPg9.js → generate.runtime-DrDZe6gu.js} +25 -20
- package/dist/chunks/generate.runtime-DrDZe6gu.js.map +1 -0
- package/dist/chunks/{generate.runtime-CINxHRnJ.js → generate.runtime-PtDQdWNY.js} +11 -11
- package/dist/chunks/{generate.runtime-CINxHRnJ.js.map → generate.runtime-PtDQdWNY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-qZhYdFI1.js → generate.runtime-WaqVbEPP.js} +19 -19
- package/dist/chunks/{generate.runtime-qZhYdFI1.js.map → generate.runtime-WaqVbEPP.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DsLlDfIo.js → generate.runtime-lvraqNgB.js} +25 -25
- package/dist/chunks/{generate.runtime-DsLlDfIo.js.map → generate.runtime-lvraqNgB.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CGtKTfYU.js → generate.runtime-qsPylve5.js} +2 -2
- package/dist/chunks/{generate.runtime-CGtKTfYU.js.map → generate.runtime-qsPylve5.js.map} +1 -1
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js → modify-svelte-config-remote-D3eBzcZc.js} +2 -2
- package/dist/chunks/{modify-svelte-config-remote-CDKs_Qi0.js.map → modify-svelte-config-remote-D3eBzcZc.js.map} +1 -1
- package/dist/chunks/{pocketbase-BbFvZ4HI.js → pocketbase-BPwW3TWr.js} +15 -15
- package/dist/chunks/{pocketbase-BbFvZ4HI.js.map → pocketbase-BPwW3TWr.js.map} +1 -1
- package/dist/chunks/{shared-C4-NNykV.js → shared-BGvy1V-z.js} +2 -2
- package/dist/chunks/{shared-C4-NNykV.js.map → shared-BGvy1V-z.js.map} +1 -1
- package/dist/chunks/{test-setup-CcD8wSRD.js → test-setup-BGhcb0Qm.js} +3 -3
- package/dist/chunks/{test-setup-CcD8wSRD.js.map → test-setup-BGhcb0Qm.js.map} +1 -1
- package/dist/chunks/{write-result-DtTqt0Cs.js → write-result-BhULcFGo.js} +45 -45
- package/dist/chunks/{write-result-DtTqt0Cs.js.map → write-result-BhULcFGo.js.map} +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.js +80 -70
- package/dist/index.js.map +1 -1
- package/package.json +13 -3
- package/dist/chunks/_server-Cie287JZ.js +0 -6
- package/dist/chunks/_server-Cie287JZ.js.map +0 -1
- package/dist/chunks/env.runtime-BVage9Kk.js +0 -31
- package/dist/chunks/env.runtime-BVage9Kk.js.map +0 -1
- package/dist/chunks/generate.runtime-6TJoTPg9.js.map +0 -1
- package/dist/chunks/generate.runtime-CtS6qa_1.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as e, t } from "./logger-CQONztPm.js";
|
|
2
|
-
import
|
|
3
|
-
import s from "node:
|
|
2
|
+
import n from "node:path";
|
|
3
|
+
import { existsSync as r, mkdirSync as i, readFileSync as a, rmSync as o, writeFileSync as s } from "node:fs";
|
|
4
4
|
import { detect as c } from "package-manager-detector";
|
|
5
5
|
import { resolveCommand as l } from "package-manager-detector/commands";
|
|
6
6
|
import u from "cross-spawn";
|
|
@@ -103,16 +103,16 @@ function be(e) {
|
|
|
103
103
|
return t.slice(n + 2).join("/");
|
|
104
104
|
}
|
|
105
105
|
function J(e, t) {
|
|
106
|
-
return
|
|
106
|
+
return n.isAbsolute(t) ? t : n.join(e, t);
|
|
107
107
|
}
|
|
108
108
|
function Y(e, t) {
|
|
109
|
-
return
|
|
109
|
+
return n.isAbsolute(t) ? n.relative(e, t) : t;
|
|
110
110
|
}
|
|
111
111
|
function X(e, t) {
|
|
112
|
-
|
|
112
|
+
i(n.dirname(e), { recursive: !0 }), s(e, t, "utf8");
|
|
113
113
|
}
|
|
114
114
|
function xe(e) {
|
|
115
|
-
|
|
115
|
+
r(e) && o(e, {
|
|
116
116
|
force: !0,
|
|
117
117
|
recursive: !0
|
|
118
118
|
});
|
|
@@ -143,14 +143,14 @@ async function Z(e, t, n, r) {
|
|
|
143
143
|
await Se(e, t, n);
|
|
144
144
|
}
|
|
145
145
|
function Ce(e) {
|
|
146
|
-
let t =
|
|
147
|
-
if (!
|
|
148
|
-
let
|
|
146
|
+
let t = n.join(e, "package.json");
|
|
147
|
+
if (!r(t)) return /* @__PURE__ */ new Set();
|
|
148
|
+
let i = JSON.parse(a(t, "utf8"));
|
|
149
149
|
return /* @__PURE__ */ new Set([
|
|
150
|
-
...Object.keys(
|
|
151
|
-
...Object.keys(
|
|
152
|
-
...Object.keys(
|
|
153
|
-
...Object.keys(
|
|
150
|
+
...Object.keys(i.dependencies ?? {}),
|
|
151
|
+
...Object.keys(i.devDependencies ?? {}),
|
|
152
|
+
...Object.keys(i.optionalDependencies ?? {}),
|
|
153
|
+
...Object.keys(i.peerDependencies ?? {})
|
|
154
154
|
]);
|
|
155
155
|
}
|
|
156
156
|
async function Q(e, n, r, i = t) {
|
|
@@ -165,47 +165,47 @@ function we(e) {
|
|
|
165
165
|
return [...new Set(e.flatMap((e) => ve[e] ?? []))];
|
|
166
166
|
}
|
|
167
167
|
function Te(e, t) {
|
|
168
|
-
let
|
|
169
|
-
r
|
|
170
|
-
for (let [t,
|
|
168
|
+
let r = n.join(t, e);
|
|
169
|
+
i(r, { recursive: !0 });
|
|
170
|
+
for (let [t, a] of Object.entries(K)) {
|
|
171
171
|
if (q(t) !== e) continue;
|
|
172
|
-
let
|
|
173
|
-
if (!
|
|
174
|
-
let c =
|
|
175
|
-
|
|
172
|
+
let o = be(t);
|
|
173
|
+
if (!o) continue;
|
|
174
|
+
let c = n.join(r, o);
|
|
175
|
+
i(n.dirname(c), { recursive: !0 }), s(c, a, "utf8");
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
async function Ee(e,
|
|
179
|
-
if (
|
|
178
|
+
async function Ee(e, a, o, s = t) {
|
|
179
|
+
if (a.length === 0) return {
|
|
180
180
|
components: [],
|
|
181
181
|
packages: []
|
|
182
182
|
};
|
|
183
|
-
let c =
|
|
184
|
-
|
|
185
|
-
let l = [...new Set(
|
|
183
|
+
let c = n.join(e, "src", "lib", "components", "ui");
|
|
184
|
+
i(c, { recursive: !0 });
|
|
185
|
+
let l = [...new Set(a)].filter((e) => !r(n.join(c, e)));
|
|
186
186
|
if (l.length === 0) return {
|
|
187
187
|
components: [],
|
|
188
188
|
packages: []
|
|
189
189
|
};
|
|
190
190
|
let u = new Set(l.filter($)), d = new Set(l.filter((e) => !$(e)));
|
|
191
|
-
for (let e of [...u]) for (let t of _e[e] ?? []) n
|
|
191
|
+
for (let e of [...u]) for (let t of _e[e] ?? []) r(n.join(c, t)) || ($(t) ? u.add(t) : d.add(t));
|
|
192
192
|
let f = [], p = [...u].sort();
|
|
193
|
-
p.length > 0 &&
|
|
193
|
+
p.length > 0 && s.info(`Installing custom components: ${p.join(", ")}`);
|
|
194
194
|
for (let e of p) Te(e, c), f.push(e), d.delete(e);
|
|
195
|
-
let m = await Q(e, we([...u]),
|
|
196
|
-
return h.length > 0 && (
|
|
195
|
+
let m = await Q(e, we([...u]), o, s), h = [...d].sort();
|
|
196
|
+
return h.length > 0 && (s.info(`Installing shadcn-svelte components: ${h.join(", ")}`), await Z(e, "execute", [
|
|
197
197
|
"shadcn-svelte",
|
|
198
198
|
"add",
|
|
199
199
|
"--yes",
|
|
200
200
|
"--overwrite",
|
|
201
201
|
...h
|
|
202
|
-
],
|
|
202
|
+
], o), f.push(...h)), {
|
|
203
203
|
components: [...new Set(f)],
|
|
204
204
|
packages: m
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
-
async function De(t,
|
|
208
|
-
let o = e(
|
|
207
|
+
async function De(t, n, i) {
|
|
208
|
+
let o = e(n), s = {
|
|
209
209
|
creates: [],
|
|
210
210
|
modifies: [],
|
|
211
211
|
deletes: [],
|
|
@@ -216,32 +216,32 @@ async function De(t, r, a) {
|
|
|
216
216
|
collectionDrops: []
|
|
217
217
|
}, c = [];
|
|
218
218
|
if (t.collectionDrops.length > 0) {
|
|
219
|
-
let { dropCollections: e } = await import("./collections-
|
|
220
|
-
c = await e(t.collectionDrops,
|
|
219
|
+
let { dropCollections: e } = await import("./collections-DgZjDXef.js");
|
|
220
|
+
c = await e(t.collectionDrops, n);
|
|
221
221
|
}
|
|
222
|
-
let l = await Q(
|
|
222
|
+
let l = await Q(n.root, t.packages, i, o), u = await Ee(n.root, t.components, i, o);
|
|
223
223
|
for (let e of [...t.creates, ...c]) {
|
|
224
224
|
if (e.status !== "success") continue;
|
|
225
|
-
let t = J(
|
|
226
|
-
if (!
|
|
225
|
+
let t = J(n.root, e.path);
|
|
226
|
+
if (!r(t)) {
|
|
227
227
|
X(t, e.content), s.creates.push({
|
|
228
228
|
...e,
|
|
229
|
-
path: Y(
|
|
229
|
+
path: Y(n.root, e.path)
|
|
230
230
|
});
|
|
231
231
|
continue;
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
a(t, "utf8") !== e.content && (X(t, e.content), s.modifies.push({
|
|
234
234
|
...e,
|
|
235
|
-
path: Y(
|
|
235
|
+
path: Y(n.root, e.path)
|
|
236
236
|
}));
|
|
237
237
|
}
|
|
238
|
-
for (let e of t.modifies) e.status === "success" && (X(J(
|
|
238
|
+
for (let e of t.modifies) e.status === "success" && (X(J(n.root, e.path), e.content), s.modifies.push({
|
|
239
239
|
...e,
|
|
240
|
-
path: Y(
|
|
240
|
+
path: Y(n.root, e.path)
|
|
241
241
|
}));
|
|
242
|
-
for (let e of t.deletes) e.status === "success" &&
|
|
242
|
+
for (let e of t.deletes) e.status === "success" && r(J(n.root, e.path)) && (xe(J(n.root, e.path)), s.deletes.push({
|
|
243
243
|
...e,
|
|
244
|
-
path: Y(
|
|
244
|
+
path: Y(n.root, e.path)
|
|
245
245
|
}));
|
|
246
246
|
return {
|
|
247
247
|
...t,
|
|
@@ -255,4 +255,4 @@ async function De(t, r, a) {
|
|
|
255
255
|
//#endregion
|
|
256
256
|
export { De as writeResult };
|
|
257
257
|
|
|
258
|
-
//# sourceMappingURL=write-result-
|
|
258
|
+
//# sourceMappingURL=write-result-BhULcFGo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-result-DtTqt0Cs.js","names":[],"sources":["../../src/runtime/write-result.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport path from \"node:path\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport type { Options, Result } from \"../core/types\";\nimport { getLogger, NOOP_LOGGER, type Logger } from \"../core/logger\";\n\ntype PackageManagerOperation = \"execute\" | \"install\";\ntype ExecuteCommand = (\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n) => Promise<void>;\n\ninterface WriteResultRuntime {\n executeCommand?: ExecuteCommand;\n}\n\ntype CustomNpmPackages = Record<string, string[]>;\n\nconst customDependencies: Record<string, string[]> = {\n \"file-form\": [\"input\", \"form\"],\n multiselect: [\"command\", \"popover\", \"button\", \"badge\"],\n geopoint: [\"button\", \"leaflet\"],\n cells: [],\n \"column-header\": [\"dropdown-menu\", \"button\"],\n \"faceted-filter\": [\"command\", \"popover\", \"button\", \"separator\", \"badge\"],\n pagination: [\"button\", \"select\"],\n \"row-actions\": [\"dropdown-menu\", \"button\"],\n leaflet: [],\n \"auth-menu\": [\"dropdown-menu\", \"button\"],\n};\n\nconst customNpmPackages: CustomNpmPackages = {\n \"file-form\": [],\n multiselect: [],\n geopoint: [],\n cells: [],\n \"column-header\": [\"@tanstack/table-core\"],\n \"faceted-filter\": [\"@tanstack/table-core\"],\n pagination: [\"@tanstack/table-core\"],\n \"row-actions\": [],\n leaflet: [\"leaflet\", \"@types/leaflet\"],\n};\n\nconst customComponentAssets = import.meta.glob<string>(\"../ui/components/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nfunction getAllCustomComponents() {\n return [\n ...new Set(\n Object.keys(customComponentAssets).map(componentNameFromAssetPath),\n ),\n ]\n .filter(Boolean)\n .sort();\n}\n\nfunction componentNameFromAssetPath(assetPath: string): string {\n const parts = assetPath.split(\"/\");\n const index = parts.indexOf(\"components\");\n return parts[index + 1] ?? \"\";\n}\n\nfunction componentRelativeAssetPath(assetPath: string): string {\n const parts = assetPath.split(\"/\");\n const index = parts.indexOf(\"components\");\n return parts.slice(index + 2).join(\"/\");\n}\n\nfunction toTargetPath(root: string, filePath: string): string {\n if (path.isAbsolute(filePath)) {\n return filePath;\n }\n return path.join(root, filePath);\n}\n\nfunction toRelativePath(root: string, filePath: string): string {\n if (path.isAbsolute(filePath)) {\n return path.relative(root, filePath);\n }\n return filePath;\n}\n\nfunction writeFile(filePath: string, content: string): void {\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content, \"utf8\");\n}\n\nfunction removeFile(filePath: string): void {\n if (!existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath, { force: true, recursive: true });\n}\n\nasync function executeWithDetectedPackageManager(\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n): Promise<void> {\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const resolved = resolveCommand(packageManager, operation, args);\n if (!resolved) {\n throw new Error(\n `Unable to resolve ${operation} command for ${packageManager}`,\n );\n }\n\n const commandArgs = [...resolved.args];\n if (packageManager === \"npm\") {\n commandArgs.unshift(\"--yes\");\n }\n\n await new Promise<void>((resolve, reject) => {\n const child = spawn(resolved.command, commandArgs, {\n cwd,\n stdio: \"inherit\",\n });\n child.on(\"error\", reject);\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n return;\n }\n reject(\n new Error(`${resolved.command} exited with code ${code ?? \"unknown\"}`),\n );\n });\n });\n}\n\nasync function executeCommand(\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n runtime?: WriteResultRuntime,\n): Promise<void> {\n if (runtime?.executeCommand) {\n await runtime.executeCommand(cwd, operation, args);\n return;\n }\n\n await executeWithDetectedPackageManager(cwd, operation, args);\n}\n\nfunction installedPackagesFromProject(root: string): Set<string> {\n const packageJsonPath = path.join(root, \"package.json\");\n if (!existsSync(packageJsonPath)) {\n return new Set();\n }\n\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n };\n\n return new Set([\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.devDependencies ?? {}),\n ...Object.keys(packageJson.optionalDependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ]);\n}\n\nasync function installPackages(\n root: string,\n packages: string[],\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<string[]> {\n if (packages.length === 0) {\n return [];\n }\n\n const installed = installedPackagesFromProject(root);\n const toInstall = [...new Set(packages)].filter((pkg) => !installed.has(pkg));\n if (toInstall.length === 0) {\n return [];\n }\n\n logger.info(`Installing packages: ${toInstall.join(\", \")}`);\n await executeCommand(root, \"install\", toInstall, runtime);\n return toInstall;\n}\n\nfunction isCustomComponent(component: string): boolean {\n return getAllCustomComponents().includes(component);\n}\n\nfunction customNpmPackagesFor(components: string[]): string[] {\n return [\n ...new Set(\n components.flatMap((component) => customNpmPackages[component] ?? []),\n ),\n ];\n}\n\nfunction copyCustomComponent(\n component: string,\n targetComponentsDir: string,\n): void {\n const targetDir = path.join(targetComponentsDir, component);\n mkdirSync(targetDir, { recursive: true });\n\n for (const [assetPath, content] of Object.entries(customComponentAssets)) {\n if (componentNameFromAssetPath(assetPath) !== component) {\n continue;\n }\n const relativePath = componentRelativeAssetPath(assetPath);\n if (!relativePath) {\n continue;\n }\n\n const outputPath = path.join(targetDir, relativePath);\n mkdirSync(path.dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, content, \"utf8\");\n }\n}\n\nasync function installComponents(\n root: string,\n components: string[],\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<{ components: string[]; packages: string[] }> {\n if (components.length === 0) {\n return { components: [], packages: [] };\n }\n\n const componentsDir = path.join(root, \"src\", \"lib\", \"components\", \"ui\");\n mkdirSync(componentsDir, { recursive: true });\n\n const requested = [...new Set(components)];\n const missing = requested.filter(\n (component) => !existsSync(path.join(componentsDir, component)),\n );\n\n if (missing.length === 0) {\n return { components: [], packages: [] };\n }\n\n const customToInstall = new Set(missing.filter(isCustomComponent));\n const publicToInstall = new Set(\n missing.filter((component) => !isCustomComponent(component)),\n );\n\n for (const component of [...customToInstall]) {\n for (const dependency of customDependencies[component] ?? []) {\n if (existsSync(path.join(componentsDir, dependency))) {\n continue;\n }\n if (isCustomComponent(dependency)) {\n customToInstall.add(dependency);\n } else {\n publicToInstall.add(dependency);\n }\n }\n }\n\n const installedComponents: string[] = [];\n const customList = [...customToInstall].sort();\n if (customList.length > 0) {\n logger.info(`Installing custom components: ${customList.join(\", \")}`);\n }\n for (const component of customList) {\n copyCustomComponent(component, componentsDir);\n installedComponents.push(component);\n publicToInstall.delete(component);\n }\n\n const customPackages = await installPackages(\n root,\n customNpmPackagesFor([...customToInstall]),\n runtime,\n logger,\n );\n\n const publicList = [...publicToInstall].sort();\n if (publicList.length > 0) {\n logger.info(\n `Installing shadcn-svelte components: ${publicList.join(\", \")}`,\n );\n await executeCommand(\n root,\n \"execute\",\n [\"shadcn-svelte\", \"add\", \"--yes\", \"--overwrite\", ...publicList],\n runtime,\n );\n installedComponents.push(...publicList);\n }\n\n return {\n components: [...new Set(installedComponents)],\n packages: customPackages,\n };\n}\n\nexport async function writeResult(\n result: Result,\n options: Options,\n runtime?: WriteResultRuntime,\n): Promise<Result> {\n const logger = getLogger(options);\n\n const writtenResult: Result = {\n creates: [],\n modifies: [],\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n };\n\n let dropMigrationCreates: Result[\"creates\"] = [];\n if (result.collectionDrops.length > 0) {\n const { dropCollections } = await import(\"./collections\");\n dropMigrationCreates = await dropCollections(\n result.collectionDrops,\n options,\n );\n }\n\n const packageInstalls = await installPackages(\n options.root,\n result.packages,\n runtime,\n logger,\n );\n\n const componentInstalls = await installComponents(\n options.root,\n result.components,\n runtime,\n logger,\n );\n\n for (const file of [...result.creates, ...dropMigrationCreates]) {\n if (file.status !== \"success\") continue;\n const target = toTargetPath(options.root, file.path);\n if (!existsSync(target)) {\n writeFile(target, file.content);\n writtenResult.creates.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n if (readFileSync(target, \"utf8\") !== file.content) {\n writeFile(target, file.content);\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n }\n\n for (const file of result.modifies) {\n if (file.status !== \"success\") continue;\n writeFile(toTargetPath(options.root, file.path), file.content);\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n\n for (const file of result.deletes) {\n if (file.status !== \"success\") continue;\n if (existsSync(toTargetPath(options.root, file.path))) {\n removeFile(toTargetPath(options.root, file.path));\n writtenResult.deletes.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n }\n\n return {\n ...result,\n creates: writtenResult.creates,\n modifies: writtenResult.modifies,\n deletes: writtenResult.deletes,\n components: componentInstalls.components,\n packages: [...new Set([...packageInstalls, ...componentInstalls.packages])],\n };\n}\n"],"mappings":";;;;;;;wv2CA2BM,KAA+C;CACnD,aAAa,CAAC,SAAS,MAAM;CAC7B,aAAa;EAAC;EAAW;EAAW;EAAU;CAAO;CACrD,UAAU,CAAC,UAAU,SAAS;CAC9B,OAAO,CAAC;CACR,iBAAiB,CAAC,iBAAiB,QAAQ;CAC3C,kBAAkB;EAAC;EAAW;EAAW;EAAU;EAAa;CAAO;CACvE,YAAY,CAAC,UAAU,QAAQ;CAC/B,eAAe,CAAC,iBAAiB,QAAQ;CACzC,SAAS,CAAC;CACV,aAAa,CAAC,iBAAiB,QAAQ;AACzC,GAEM,KAAuC;CAC3C,aAAa,CAAC;CACd,aAAa,CAAC;CACd,UAAU,CAAC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Ae,EAAQ,MAAM,EAAK,IAAI;GAC9C,CAAC;GACD;EACF;EACA,AAAI,EAAa,GAAQ,MAAM,MAAM,EAAK,YACxC,EAAU,GAAQ,EAAK,OAAO,GAC9B,EAAc,SAAS,KAAK;GAC1B,GAAG;GACH,MAAM,EAAe,EAAQ,MAAM,EAAK,IAAI;EAC9C,CAAC;CAEL;CAEA,KAAK,IAAM,KAAQ,EAAO,UACpB,EAAK,WAAW,cACpB,EAAU,EAAa,EAAQ,MAAM,EAAK,IAAI,GAAG,EAAK,OAAO,GAC7D,EAAc,SAAS,KAAK;EAC1B,GAAG;EACH,MAAM,EAAe,EAAQ,MAAM,EAAK,IAAI;CAC9C,CAAC;CAGH,KAAK,IAAM,KAAQ,EAAO,SACpB,EAAK,WAAW,aAChB,EAAW,EAAa,EAAQ,MAAM,EAAK,IAAI,CAAC,MAClD,GAAW,EAAa,EAAQ,MAAM,EAAK,IAAI,CAAC,GAChD,EAAc,QAAQ,KAAK;EACzB,GAAG;EACH,MAAM,EAAe,EAAQ,MAAM,EAAK,IAAI;CAC9C,CAAC;CAIL,OAAO;EACL,GAAG;EACH,SAAS,EAAc;EACvB,UAAU,EAAc;EACxB,SAAS,EAAc;EACvB,YAAY,EAAkB;EAC9B,UAAU,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,GAAiB,GAAG,EAAkB,QAAQ,CAAC,CAAC;CAC5E;AACF"}
|
|
1
|
+
{"version":3,"file":"write-result-BhULcFGo.js","names":[],"sources":["../../src/runtime/write-result.ts"],"sourcesContent":["import {\n existsSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport path from \"node:path\";\nimport { detect } from \"package-manager-detector\";\nimport { resolveCommand } from \"package-manager-detector/commands\";\nimport spawn from \"cross-spawn\";\nimport type { Options, Result } from \"../core/types\";\nimport { getLogger, NOOP_LOGGER, type Logger } from \"../core/logger\";\n\ntype PackageManagerOperation = \"execute\" | \"install\";\ntype ExecuteCommand = (\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n) => Promise<void>;\n\ninterface WriteResultRuntime {\n executeCommand?: ExecuteCommand;\n}\n\ntype CustomNpmPackages = Record<string, string[]>;\n\nconst customDependencies: Record<string, string[]> = {\n \"file-form\": [\"input\", \"form\"],\n multiselect: [\"command\", \"popover\", \"button\", \"badge\"],\n geopoint: [\"button\", \"leaflet\"],\n cells: [],\n \"column-header\": [\"dropdown-menu\", \"button\"],\n \"faceted-filter\": [\"command\", \"popover\", \"button\", \"separator\", \"badge\"],\n pagination: [\"button\", \"select\"],\n \"row-actions\": [\"dropdown-menu\", \"button\"],\n leaflet: [],\n \"auth-menu\": [\"dropdown-menu\", \"button\"],\n};\n\nconst customNpmPackages: CustomNpmPackages = {\n \"file-form\": [],\n multiselect: [],\n geopoint: [],\n cells: [],\n \"column-header\": [\"@tanstack/table-core\"],\n \"faceted-filter\": [\"@tanstack/table-core\"],\n pagination: [\"@tanstack/table-core\"],\n \"row-actions\": [],\n leaflet: [\"leaflet\", \"@types/leaflet\"],\n};\n\nconst customComponentAssets = import.meta.glob<string>(\"../ui/components/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nfunction getAllCustomComponents() {\n return [\n ...new Set(\n Object.keys(customComponentAssets).map(componentNameFromAssetPath),\n ),\n ]\n .filter(Boolean)\n .sort();\n}\n\nfunction componentNameFromAssetPath(assetPath: string): string {\n const parts = assetPath.split(\"/\");\n const index = parts.indexOf(\"components\");\n return parts[index + 1] ?? \"\";\n}\n\nfunction componentRelativeAssetPath(assetPath: string): string {\n const parts = assetPath.split(\"/\");\n const index = parts.indexOf(\"components\");\n return parts.slice(index + 2).join(\"/\");\n}\n\nfunction toTargetPath(root: string, filePath: string): string {\n if (path.isAbsolute(filePath)) {\n return filePath;\n }\n return path.join(root, filePath);\n}\n\nfunction toRelativePath(root: string, filePath: string): string {\n if (path.isAbsolute(filePath)) {\n return path.relative(root, filePath);\n }\n return filePath;\n}\n\nfunction writeFile(filePath: string, content: string): void {\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content, \"utf8\");\n}\n\nfunction removeFile(filePath: string): void {\n if (!existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath, { force: true, recursive: true });\n}\n\nasync function executeWithDetectedPackageManager(\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n): Promise<void> {\n const packageManager = (await detect({ cwd }))?.name ?? \"npm\";\n const resolved = resolveCommand(packageManager, operation, args);\n if (!resolved) {\n throw new Error(\n `Unable to resolve ${operation} command for ${packageManager}`,\n );\n }\n\n const commandArgs = [...resolved.args];\n if (packageManager === \"npm\") {\n commandArgs.unshift(\"--yes\");\n }\n\n await new Promise<void>((resolve, reject) => {\n const child = spawn(resolved.command, commandArgs, {\n cwd,\n stdio: \"inherit\",\n });\n child.on(\"error\", reject);\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n return;\n }\n reject(\n new Error(`${resolved.command} exited with code ${code ?? \"unknown\"}`),\n );\n });\n });\n}\n\nasync function executeCommand(\n cwd: string,\n operation: PackageManagerOperation,\n args: string[],\n runtime?: WriteResultRuntime,\n): Promise<void> {\n if (runtime?.executeCommand) {\n await runtime.executeCommand(cwd, operation, args);\n return;\n }\n\n await executeWithDetectedPackageManager(cwd, operation, args);\n}\n\nfunction installedPackagesFromProject(root: string): Set<string> {\n const packageJsonPath = path.join(root, \"package.json\");\n if (!existsSync(packageJsonPath)) {\n return new Set();\n }\n\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf8\")) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n optionalDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n };\n\n return new Set([\n ...Object.keys(packageJson.dependencies ?? {}),\n ...Object.keys(packageJson.devDependencies ?? {}),\n ...Object.keys(packageJson.optionalDependencies ?? {}),\n ...Object.keys(packageJson.peerDependencies ?? {}),\n ]);\n}\n\nasync function installPackages(\n root: string,\n packages: string[],\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<string[]> {\n if (packages.length === 0) {\n return [];\n }\n\n const installed = installedPackagesFromProject(root);\n const toInstall = [...new Set(packages)].filter((pkg) => !installed.has(pkg));\n if (toInstall.length === 0) {\n return [];\n }\n\n logger.info(`Installing packages: ${toInstall.join(\", \")}`);\n await executeCommand(root, \"install\", toInstall, runtime);\n return toInstall;\n}\n\nfunction isCustomComponent(component: string): boolean {\n return getAllCustomComponents().includes(component);\n}\n\nfunction customNpmPackagesFor(components: string[]): string[] {\n return [\n ...new Set(\n components.flatMap((component) => customNpmPackages[component] ?? []),\n ),\n ];\n}\n\nfunction copyCustomComponent(\n component: string,\n targetComponentsDir: string,\n): void {\n const targetDir = path.join(targetComponentsDir, component);\n mkdirSync(targetDir, { recursive: true });\n\n for (const [assetPath, content] of Object.entries(customComponentAssets)) {\n if (componentNameFromAssetPath(assetPath) !== component) {\n continue;\n }\n const relativePath = componentRelativeAssetPath(assetPath);\n if (!relativePath) {\n continue;\n }\n\n const outputPath = path.join(targetDir, relativePath);\n mkdirSync(path.dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, content, \"utf8\");\n }\n}\n\nasync function installComponents(\n root: string,\n components: string[],\n runtime?: WriteResultRuntime,\n logger: Logger = NOOP_LOGGER,\n): Promise<{ components: string[]; packages: string[] }> {\n if (components.length === 0) {\n return { components: [], packages: [] };\n }\n\n const componentsDir = path.join(root, \"src\", \"lib\", \"components\", \"ui\");\n mkdirSync(componentsDir, { recursive: true });\n\n const requested = [...new Set(components)];\n const missing = requested.filter(\n (component) => !existsSync(path.join(componentsDir, component)),\n );\n\n if (missing.length === 0) {\n return { components: [], packages: [] };\n }\n\n const customToInstall = new Set(missing.filter(isCustomComponent));\n const publicToInstall = new Set(\n missing.filter((component) => !isCustomComponent(component)),\n );\n\n for (const component of [...customToInstall]) {\n for (const dependency of customDependencies[component] ?? []) {\n if (existsSync(path.join(componentsDir, dependency))) {\n continue;\n }\n if (isCustomComponent(dependency)) {\n customToInstall.add(dependency);\n } else {\n publicToInstall.add(dependency);\n }\n }\n }\n\n const installedComponents: string[] = [];\n const customList = [...customToInstall].sort();\n if (customList.length > 0) {\n logger.info(`Installing custom components: ${customList.join(\", \")}`);\n }\n for (const component of customList) {\n copyCustomComponent(component, componentsDir);\n installedComponents.push(component);\n publicToInstall.delete(component);\n }\n\n const customPackages = await installPackages(\n root,\n customNpmPackagesFor([...customToInstall]),\n runtime,\n logger,\n );\n\n const publicList = [...publicToInstall].sort();\n if (publicList.length > 0) {\n logger.info(\n `Installing shadcn-svelte components: ${publicList.join(\", \")}`,\n );\n await executeCommand(\n root,\n \"execute\",\n [\"shadcn-svelte\", \"add\", \"--yes\", \"--overwrite\", ...publicList],\n runtime,\n );\n installedComponents.push(...publicList);\n }\n\n return {\n components: [...new Set(installedComponents)],\n packages: customPackages,\n };\n}\n\nexport async function writeResult(\n result: Result,\n options: Options,\n runtime?: WriteResultRuntime,\n): Promise<Result> {\n const logger = getLogger(options);\n\n const writtenResult: Result = {\n creates: [],\n modifies: [],\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n };\n\n let dropMigrationCreates: Result[\"creates\"] = [];\n if (result.collectionDrops.length > 0) {\n const { dropCollections } = await import(\"./collections\");\n dropMigrationCreates = await dropCollections(\n result.collectionDrops,\n options,\n );\n }\n\n const packageInstalls = await installPackages(\n options.root,\n result.packages,\n runtime,\n logger,\n );\n\n const componentInstalls = await installComponents(\n options.root,\n result.components,\n runtime,\n logger,\n );\n\n for (const file of [...result.creates, ...dropMigrationCreates]) {\n if (file.status !== \"success\") continue;\n const target = toTargetPath(options.root, file.path);\n if (!existsSync(target)) {\n writeFile(target, file.content);\n writtenResult.creates.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n continue;\n }\n if (readFileSync(target, \"utf8\") !== file.content) {\n writeFile(target, file.content);\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n }\n\n for (const file of result.modifies) {\n if (file.status !== \"success\") continue;\n writeFile(toTargetPath(options.root, file.path), file.content);\n writtenResult.modifies.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n\n for (const file of result.deletes) {\n if (file.status !== \"success\") continue;\n if (existsSync(toTargetPath(options.root, file.path))) {\n removeFile(toTargetPath(options.root, file.path));\n writtenResult.deletes.push({\n ...file,\n path: toRelativePath(options.root, file.path),\n });\n }\n }\n\n return {\n ...result,\n creates: writtenResult.creates,\n modifies: writtenResult.modifies,\n deletes: writtenResult.deletes,\n components: componentInstalls.components,\n packages: [...new Set([...packageInstalls, ...componentInstalls.packages])],\n };\n}\n"],"mappings":";;;;;;;wv2CA2BM,KAA+C;CACnD,aAAa,CAAC,SAAS,MAAM;CAC7B,aAAa;EAAC;EAAW;EAAW;EAAU;CAAO;CACrD,UAAU,CAAC,UAAU,SAAS;CAC9B,OAAO,CAAC;CACR,iBAAiB,CAAC,iBAAiB,QAAQ;CAC3C,kBAAkB;EAAC;EAAW;EAAW;EAAU;EAAa;CAAO;CACvE,YAAY,CAAC,UAAU,QAAQ;CAC/B,eAAe,CAAC,iBAAiB,QAAQ;CACzC,SAAS,CAAC;CACV,aAAa,CAAC,iBAAiB,QAAQ;AACzC,GAEM,KAAuC;CAC3C,aAAa,CAAC;CACd,aAAa,CAAC;CACd,UAAU,CAAC;CACX,OAAO,CAAC;CACR,iBAAiB,CAAC,sBAAsB;CACxC,kBAAkB,CAAC,sBAAsB;CACzC,YAAY,CAAC,sBAAsB;CACnC,eAAe,CAAC;CAChB,SAAS,CAAC,WAAW,gBAAgB;AACvC,GAEM,IAAwB,uBAAA,OAAA;CAAA,uDAAA;CAAA,qDAAA;CAAA,oDAAA;CAAA,qDAAA;CAAA,yDAAA;CAAA,uDAAA;CAAA,+CAAA;CAAA,yCAAA;CAAA,uCAAA;CAAA,0CAAA;CAAA,sCAAA;CAAA,sCAAA;CAAA,wCAAA;CAAA,uCAAA;CAAA,sCAAA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AM,EAAe,EAAQ,MAAM,EAAK,IAAI;CAC9C,CAAC;CAGH,KAAK,IAAM,KAAQ,EAAO,SACpB,EAAK,WAAW,aAChB,EAAW,EAAa,EAAQ,MAAM,EAAK,IAAI,CAAC,MAClD,GAAW,EAAa,EAAQ,MAAM,EAAK,IAAI,CAAC,GAChD,EAAc,QAAQ,KAAK;EACzB,GAAG;EACH,MAAM,EAAe,EAAQ,MAAM,EAAK,IAAI;CAC9C,CAAC;CAIL,OAAO;EACL,GAAG;EACH,SAAS,EAAc;EACvB,UAAU,EAAc;EACxB,SAAS,EAAc;EACvB,YAAY,EAAkB;EAC9B,UAAU,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,GAAiB,GAAG,EAAkB,QAAQ,CAAC,CAAC;CAC5E;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -998,12 +998,26 @@ export declare const bySlug: Record<Slug, PatternEntry>;
|
|
|
998
998
|
|
|
999
999
|
export declare type Category = PatternEntry["category"];
|
|
1000
1000
|
|
|
1001
|
+
declare interface Collection {
|
|
1002
|
+
id: string;
|
|
1003
|
+
name: string;
|
|
1004
|
+
type: "base" | "auth" | "view";
|
|
1005
|
+
fields: CollectionField[];
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1001
1008
|
declare interface CollectionDropSpec {
|
|
1002
1009
|
name: string;
|
|
1003
1010
|
exists: boolean;
|
|
1004
1011
|
rowCount: number;
|
|
1005
1012
|
}
|
|
1006
1013
|
|
|
1014
|
+
declare interface CollectionField {
|
|
1015
|
+
name: string;
|
|
1016
|
+
type: string;
|
|
1017
|
+
collectionId?: string;
|
|
1018
|
+
maxSelect?: number;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1007
1021
|
declare interface CollectionFieldsPatch {
|
|
1008
1022
|
collectionName: string;
|
|
1009
1023
|
changes: FieldChange[];
|
|
@@ -1157,6 +1171,14 @@ declare interface Options {
|
|
|
1157
1171
|
env: "runtime" | "preview";
|
|
1158
1172
|
root: string;
|
|
1159
1173
|
features: Features;
|
|
1174
|
+
/**
|
|
1175
|
+
* Reads the live collection schema. Required when `env` is `"runtime"`.
|
|
1176
|
+
*
|
|
1177
|
+
* Injected by the caller (`vela`) rather than resolved here, because reading
|
|
1178
|
+
* the schema may mean spawning a throwaway PocketBase, and only the CLI owns
|
|
1179
|
+
* that. Keeps this package free of process-spawning dependencies.
|
|
1180
|
+
*/
|
|
1181
|
+
getCollections?: () => Promise<Collection[]>;
|
|
1160
1182
|
/**
|
|
1161
1183
|
* Pattern-specific named inputs (separate from positional argv).
|
|
1162
1184
|
*
|