@velastack/patterns 0.2.3 → 0.2.5
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 +13 -1
- package/dist/chunks/{collections-1Z0NCLM-.js → collections-B-yQ1qt6.js} +2 -2
- package/dist/chunks/{collections-1Z0NCLM-.js.map → collections-B-yQ1qt6.js.map} +1 -1
- package/dist/chunks/{generate-mchSz-tm.js → generate-BCBS08AS.js} +2 -2
- package/dist/chunks/{generate-mchSz-tm.js.map → generate-BCBS08AS.js.map} +1 -1
- package/dist/chunks/generate-BoEG6Rb-.js +111 -0
- package/dist/chunks/generate-BoEG6Rb-.js.map +1 -0
- package/dist/chunks/{generate.runtime-C52G7ZnV.js → generate.runtime-ArKscTs9.js} +2 -2
- package/dist/chunks/{generate.runtime-C52G7ZnV.js.map → generate.runtime-ArKscTs9.js.map} +1 -1
- package/dist/chunks/{generate.runtime-Cdep21LK.js → generate.runtime-BBOWWrZv.js} +2 -2
- package/dist/chunks/{generate.runtime-Cdep21LK.js.map → generate.runtime-BBOWWrZv.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DJJTAUe-.js → generate.runtime-Biy8wuHU.js} +13 -13
- package/dist/chunks/{generate.runtime-DJJTAUe-.js.map → generate.runtime-Biy8wuHU.js.map} +1 -1
- package/dist/chunks/{generate.runtime-qsPylve5.js → generate.runtime-BpvwX9CL.js} +3 -3
- package/dist/chunks/{generate.runtime-qsPylve5.js.map → generate.runtime-BpvwX9CL.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BB-U8d52.js → generate.runtime-BtL9FPuW.js} +3 -3
- package/dist/chunks/{generate.runtime-BB-U8d52.js.map → generate.runtime-BtL9FPuW.js.map} +1 -1
- package/dist/chunks/{generate.runtime-De1TeiUr.js → generate.runtime-ByASCDoo.js} +2 -2
- package/dist/chunks/{generate.runtime-De1TeiUr.js.map → generate.runtime-ByASCDoo.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CL-fRmd9.js → generate.runtime-C6RhVu5K.js} +3 -3
- package/dist/chunks/{generate.runtime-CL-fRmd9.js.map → generate.runtime-C6RhVu5K.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CpKaHLG6.js → generate.runtime-C6qZUlN-.js} +2 -2
- package/dist/chunks/{generate.runtime-CpKaHLG6.js.map → generate.runtime-C6qZUlN-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-O_XZsZZ0.js → generate.runtime-CIuSkWtY.js} +2 -2
- package/dist/chunks/{generate.runtime-O_XZsZZ0.js.map → generate.runtime-CIuSkWtY.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C5TE2jyc.js → generate.runtime-CRgw-aja.js} +2 -2
- package/dist/chunks/{generate.runtime-C5TE2jyc.js.map → generate.runtime-CRgw-aja.js.map} +1 -1
- package/dist/chunks/{generate.runtime-BgW9zLGZ.js → generate.runtime-CUtOhlNA.js} +3 -3
- package/dist/chunks/{generate.runtime-BgW9zLGZ.js.map → generate.runtime-CUtOhlNA.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DZR09ORc.js → generate.runtime-CghBFVEf.js} +2 -2
- package/dist/chunks/{generate.runtime-DZR09ORc.js.map → generate.runtime-CghBFVEf.js.map} +1 -1
- package/dist/chunks/{generate.runtime-DEPMu4l8.js → generate.runtime-CrrAzNZS.js} +15 -15
- package/dist/chunks/{generate.runtime-DEPMu4l8.js.map → generate.runtime-CrrAzNZS.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CRcQrxEJ.js → generate.runtime-CwaPHcYP.js} +3 -3
- package/dist/chunks/{generate.runtime-CRcQrxEJ.js.map → generate.runtime-CwaPHcYP.js.map} +1 -1
- package/dist/chunks/{generate.runtime-QL0UvDUK.js → generate.runtime-DercL_qN.js} +2 -2
- package/dist/chunks/{generate.runtime-QL0UvDUK.js.map → generate.runtime-DercL_qN.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CfclK4xT.js → generate.runtime-Dlokr7A0.js} +2 -2
- package/dist/chunks/{generate.runtime-CfclK4xT.js.map → generate.runtime-Dlokr7A0.js.map} +1 -1
- package/dist/chunks/{generate.runtime-mFZIMpFZ.js → generate.runtime-JWURZXj-.js} +15 -15
- package/dist/chunks/{generate.runtime-mFZIMpFZ.js.map → generate.runtime-JWURZXj-.js.map} +1 -1
- package/dist/chunks/{generate.runtime-CmBcOojv.js → generate.runtime-PjMBpjkG.js} +2 -2
- package/dist/chunks/{generate.runtime-CmBcOojv.js.map → generate.runtime-PjMBpjkG.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C8Y2mS0B.js → generate.runtime-UIN_TkYo.js} +3 -3
- package/dist/chunks/{generate.runtime-C8Y2mS0B.js.map → generate.runtime-UIN_TkYo.js.map} +1 -1
- package/dist/chunks/{generate.runtime-C7Shwovm.js → generate.runtime-WwZt9Mu5.js} +3 -3
- package/dist/chunks/{generate.runtime-C7Shwovm.js.map → generate.runtime-WwZt9Mu5.js.map} +1 -1
- package/dist/chunks/{generate.runtime-pwEIGBEe.js → generate.runtime-XpQGIrOx.js} +3 -3
- package/dist/chunks/{generate.runtime-pwEIGBEe.js.map → generate.runtime-XpQGIrOx.js.map} +1 -1
- package/dist/chunks/generate.runtime-_VsM0zBS.js +87 -0
- package/dist/chunks/generate.runtime-_VsM0zBS.js.map +1 -0
- package/dist/chunks/{generate.runtime-CDSkTWtx.js → generate.runtime-nyMB57Tf.js} +2 -2
- package/dist/chunks/{generate.runtime-CDSkTWtx.js.map → generate.runtime-nyMB57Tf.js.map} +1 -1
- package/dist/chunks/{modify-file-PVKmDJHk.js → modify-file-Dgd_PzRG.js} +2 -2
- package/dist/chunks/{modify-file-PVKmDJHk.js.map → modify-file-Dgd_PzRG.js.map} +1 -1
- package/dist/chunks/{shared-CaHmNkZE.js → shared-cFKFtcgw.js} +3 -3
- package/dist/chunks/{shared-CaHmNkZE.js.map → shared-cFKFtcgw.js.map} +1 -1
- package/dist/chunks/{test-setup-BGhcb0Qm.js → test-setup-BBb4kcoO.js} +42 -38
- package/dist/chunks/test-setup-BBb4kcoO.js.map +1 -0
- package/dist/chunks/{ui-DAtVMiVs.js → ui-X12f0xKA.js} +2 -2
- package/dist/chunks/{ui-DAtVMiVs.js.map → ui-X12f0xKA.js.map} +1 -1
- package/dist/chunks/{util-Bk7aQQJR.js → util-Bq_Mh6IQ.js} +11 -11
- package/dist/chunks/util-Bq_Mh6IQ.js.map +1 -0
- package/dist/chunks/{write-result-BHCOxcsA.js → write-result-DgFUKxhP.js} +2 -2
- package/dist/chunks/{write-result-BHCOxcsA.js.map → write-result-DgFUKxhP.js.map} +1 -1
- package/dist/index.d.ts +200 -54
- package/dist/index.js +2137 -2043
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/chunks/test-setup-BGhcb0Qm.js.map +0 -1
- package/dist/chunks/util-Bk7aQQJR.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { o as e, r as t, t as n } from "./generate-BoEG6Rb-.js";
|
|
2
|
+
import { t as r } from "./dedent-Gq6Krl4n.js";
|
|
3
|
+
import { n as i } from "./logger-CQONztPm.js";
|
|
4
|
+
import { modifyOutcomeToFile as a } from "./modify-file-Dgd_PzRG.js";
|
|
5
|
+
import { a as o, n as s, o as c } from "./ts-morph-helpers-7qF9S2k7.js";
|
|
6
|
+
import { t as l } from "./env-BPfk1VAw.js";
|
|
7
|
+
import u from "node:path";
|
|
8
|
+
import d from "node:fs";
|
|
9
|
+
//#region src/patterns/enable/analytics/modifies/layout.svelte.ts
|
|
10
|
+
var f = "$lib/components/analytics/analytics.svelte", p = r`
|
|
11
|
+
import Analytics from '${f}';
|
|
12
|
+
`, m = "\n<Analytics />\n", h = [
|
|
13
|
+
"Create the root src/routes/+layout.svelte and mount <Analytics /> inside it.",
|
|
14
|
+
"",
|
|
15
|
+
"Import for the <script> tag:",
|
|
16
|
+
"",
|
|
17
|
+
p,
|
|
18
|
+
"",
|
|
19
|
+
"Markup to add at the top level of the layout, above {@render children()}:",
|
|
20
|
+
m.trim()
|
|
21
|
+
].join("\n"), g = [
|
|
22
|
+
"Mount <Analytics /> in the root src/routes/+layout.svelte.",
|
|
23
|
+
"",
|
|
24
|
+
"Import for a <script lang=\"ts\"> tag:",
|
|
25
|
+
"",
|
|
26
|
+
p,
|
|
27
|
+
"",
|
|
28
|
+
"Markup to add at the top level of the layout, above {@render children()}:",
|
|
29
|
+
m.trim()
|
|
30
|
+
].join("\n");
|
|
31
|
+
function _(e) {
|
|
32
|
+
if (!d.existsSync(e)) return {
|
|
33
|
+
status: "not-found",
|
|
34
|
+
message: h
|
|
35
|
+
};
|
|
36
|
+
let t = c.fromPath(e);
|
|
37
|
+
return t.hasElement("Analytics") ? {
|
|
38
|
+
status: "success",
|
|
39
|
+
changed: !1
|
|
40
|
+
} : t.getScript() ? (t.modifyScript((e) => {
|
|
41
|
+
let { source: t } = o(e, (e) => {
|
|
42
|
+
s(e, [{
|
|
43
|
+
defaultImport: "Analytics",
|
|
44
|
+
moduleSpecifier: f
|
|
45
|
+
}]);
|
|
46
|
+
});
|
|
47
|
+
return t;
|
|
48
|
+
}), t.insertBeforeChildren(m) || t.appendMarkup(m), t.writeTo(e), {
|
|
49
|
+
status: "success",
|
|
50
|
+
changed: t.hasChanged()
|
|
51
|
+
}) : {
|
|
52
|
+
status: "failed",
|
|
53
|
+
message: g
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/patterns/enable/analytics/generate.runtime.ts
|
|
58
|
+
function v(e) {
|
|
59
|
+
let t = e.input.providerEnv;
|
|
60
|
+
if (!t || typeof t != "object") return {};
|
|
61
|
+
let n = {};
|
|
62
|
+
for (let [e, r] of Object.entries(t)) typeof r == "string" && (n[e] = r);
|
|
63
|
+
return n;
|
|
64
|
+
}
|
|
65
|
+
async function y(r) {
|
|
66
|
+
let o = i(r), s = e(n, r), c = [], d = (e) => {
|
|
67
|
+
e && c.push(e);
|
|
68
|
+
};
|
|
69
|
+
o.info("Modifying src/routes/+layout.svelte");
|
|
70
|
+
let f = u.join(r.root, "src", "routes", "+layout.svelte");
|
|
71
|
+
d(a(f, _(f))), o.info("Updating .env");
|
|
72
|
+
let p = u.join(r.root, ".env");
|
|
73
|
+
return d(a(p, l(p, t(s, v(r))))), {
|
|
74
|
+
creates: [],
|
|
75
|
+
modifies: c,
|
|
76
|
+
deletes: [],
|
|
77
|
+
components: [],
|
|
78
|
+
packages: [],
|
|
79
|
+
collections: [],
|
|
80
|
+
collectionPatches: [],
|
|
81
|
+
collectionDrops: []
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { y as generate };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=generate.runtime-_VsM0zBS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-_VsM0zBS.js","names":[],"sources":["../../src/patterns/enable/analytics/modifies/layout.svelte.ts","../../src/patterns/enable/analytics/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst MODULE_SPECIFIER = \"$lib/components/analytics/analytics.svelte\";\n\nconst IMPORT_SNIPPET = dedent`\n import Analytics from '${MODULE_SPECIFIER}';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<Analytics />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <Analytics /> inside it.\",\n \"\",\n \"Import for the <script> tag:\",\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <Analytics /> in the root src/routes/+layout.svelte.\",\n \"\",\n 'Import for a <script lang=\"ts\"> tag:',\n \"\",\n IMPORT_SNIPPET,\n \"\",\n \"Markup to add at the top level of the layout, above {@render children()}:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/**\n * Mounts `<Analytics />` at the top level of the root layout, ahead of\n * `{@render children()}`. The component is the same path for every provider,\n * so this modifier is provider-agnostic and a re-run with another provider\n * leaves the layout alone.\n */\nexport function modifyLayoutSvelte(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(\"Analytics\")) {\n return { status: \"success\", changed: false };\n }\n if (!file.getScript()) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { defaultImport: \"Analytics\", moduleSpecifier: MODULE_SPECIFIER },\n ]);\n });\n return out;\n });\n\n if (!file.insertBeforeChildren(MARKUP_SNIPPET)) {\n file.appendMarkup(MARKUP_SNIPPET);\n }\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { resolveProvider } from \"../../../core/providers\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { envEditsFor, META } from \"./generate\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\nfunction suppliedEnv(options: Options): Record<string, string> {\n const raw = options.input.providerEnv;\n if (!raw || typeof raw !== \"object\") return {};\n const values: Record<string, string> = {};\n for (const [key, value] of Object.entries(raw)) {\n if (typeof value === \"string\") values[key] = value;\n }\n return values;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutPath = path.join(options.root, \"src\", \"routes\", \"+layout.svelte\");\n pushResult(modifyOutcomeToFile(layoutPath, modifyLayoutSvelte(layoutPath)));\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n pushResult(\n modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedEnv(options))),\n ),\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;AASA,IAAM,IAAmB,8CAEnB,IAAiB,CAAM;2BACF,EAAiB;GAGtC,IAAiB,qBAEjB,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA,EAAe,KAAK;AACtB,CAAC,CAAC,KAAK,IAAI,GAEL,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA,EAAe,KAAK;AACtB,CAAC,CAAC,KAAK,IAAI;AAQX,SAAgB,EAAmB,GAAmC;CACpE,IAAI,CAAC,EAAG,WAAW,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAGxD,IAAM,IAAO,EAAW,SAAS,CAAU;CAqB3C,OApBI,EAAK,WAAW,WAAW,IACtB;EAAE,QAAQ;EAAW,SAAS;CAAM,IAExC,EAAK,UAAU,KAIpB,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQ,MAAQ,EAAmB,IAAS,MAAO;GACzD,EAAc,GAAI,CAChB;IAAE,eAAe;IAAa,iBAAiB;GAAiB,CAClE,CAAC;EACH,CAAC;EACD,OAAO;CACT,CAAC,GAEI,EAAK,qBAAqB,CAAc,KAC3C,EAAK,aAAa,CAAc,GAElC,EAAK,QAAQ,CAAU,GAChB;EAAE,QAAQ;EAAW,SAAS,EAAK,WAAW;CAAE,KAhB9C;EAAE,QAAQ;EAAU,SAAS;CAAa;AAiBrD;;;AC/DA,SAAS,EAAY,GAA0C;CAC7D,IAAM,IAAM,EAAQ,MAAM;CAC1B,IAAI,CAAC,KAAO,OAAO,KAAQ,UAAU,OAAO,CAAC;CAC7C,IAAM,IAAiC,CAAC;CACxC,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAG,GAC3C,AAAI,OAAO,KAAU,aAAU,EAAO,KAAO;CAE/C,OAAO;AACT;AAEA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAW,EAAgB,GAAM,CAAO,GACxC,IAAmB,CAAC,GAEpB,KAAc,MAAsB;EACxC,AAAI,KAAM,EAAS,KAAK,CAAI;CAC9B;CAEA,EAAO,KAAK,qCAAqC;CACjD,IAAM,IAAa,EAAK,KAAK,EAAQ,MAAM,OAAO,UAAU,gBAAgB;CAG5E,AAFA,EAAW,EAAoB,GAAY,EAAmB,CAAU,CAAC,CAAC,GAE1E,EAAO,KAAK,eAAe;CAC3B,IAAM,IAAU,EAAK,KAAK,EAAQ,MAAM,MAAM;CAQ9C,OAPA,EACE,EACE,GACA,EAAU,GAAS,EAAY,GAAU,EAAY,CAAO,CAAC,CAAC,CAChE,CACF,GAEO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e } from "./logger-CQONztPm.js";
|
|
2
|
-
import { modifyOutcomeToFile as t } from "./modify-file-
|
|
2
|
+
import { modifyOutcomeToFile as t } from "./modify-file-Dgd_PzRG.js";
|
|
3
3
|
import n from "node:path";
|
|
4
4
|
import r from "node:fs";
|
|
5
5
|
import { Project as i, SyntaxKind as a } from "ts-morph";
|
|
@@ -53,4 +53,4 @@ async function s(r) {
|
|
|
53
53
|
//#endregion
|
|
54
54
|
export { s as generate };
|
|
55
55
|
|
|
56
|
-
//# sourceMappingURL=generate.runtime-
|
|
56
|
+
//# sourceMappingURL=generate.runtime-nyMB57Tf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.runtime-
|
|
1
|
+
{"version":3,"file":"generate.runtime-nyMB57Tf.js","names":[],"sources":["../../src/patterns/disable/api/modifies/hooks.server.ts","../../src/patterns/disable/api/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport function unmodifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"success\", changed: false };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"success\", changed: false };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n return { status: \"success\", changed: false };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n return { status: \"success\", changed: false };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n return { status: \"success\", changed: false };\n }\n\n apiProp.remove();\n\n if (optionsObj.getProperties().length === 0) {\n callExpr.removeArgument(0);\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { unmodifyHooksServer } from \"./modifies/hooks.server\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Reverting hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n const file = modifyOutcomeToFile(\n hooksServerPath,\n unmodifyHooksServer(hooksServerPath),\n );\n if (file) modifies.push(file);\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;;;AAIA,SAAgB,EAAoB,GAAwC;CAC1E,IAAI,CAAC,EAAG,WAAW,CAAe,GAChC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAiB,EAAG,aAAa,GAAiB,MAAM,GAExD,IAAa,IADC,EACD,CAAA,CAAQ,oBAAoB,CAAe,GAExD,IAAW,EACd,qBAAqB,EAAW,cAAc,CAAC,CAC/C,MAAM,MAAO,EAAG,cAAc,CAAC,CAAC,QAAQ,MAAM,kBAAkB;CAEnE,IAAI,CAAC,GACH,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAO,EAAS,aAAa;CACnC,IAAI,EAAK,WAAW,GAClB,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAW,EAAK;CACtB,IAAI,EAAS,QAAQ,MAAM,EAAW,yBACpC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,IAAa,EAAS,cAAc,EAAW,uBAAuB,GACtE,IAAU,EAAW,YAAY,KAAK;CAc5C,OAbK,KAIL,EAAQ,OAAO,GAEX,EAAW,cAAc,CAAC,CAAC,WAAW,KACxC,EAAS,eAAe,CAAC,GAG3B,EAAW,WAAW,GACtB,EAAW,SAAS,GAEb;EACL,QAAQ;EACR,SAAS,EAAW,YAAY,MAAM;CACxC,KAfS;EAAE,QAAQ;EAAW,SAAS;CAAM;AAgB/C;;;AC5CA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAS,EAAU,CAAO,GAC1B,IAAmB,CAAC;CAE1B,EAAO,KAAK,2BAA2B;CACvC,IAAM,IAAkB,EAAK,KAAK,EAAQ,MAAM,OAAO,iBAAiB,GAClE,IAAO,EACX,GACA,EAAoB,CAAe,CACrC;CAGA,OAFI,KAAM,EAAS,KAAK,CAAI,GAErB;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as e } from "./util-Bq_Mh6IQ.js";
|
|
2
2
|
import t from "node:fs";
|
|
3
3
|
//#region src/runtime/modify-file.ts
|
|
4
4
|
function n(n, r) {
|
|
@@ -19,4 +19,4 @@ function n(n, r) {
|
|
|
19
19
|
//#endregion
|
|
20
20
|
export { n as modifyOutcomeToFile };
|
|
21
21
|
|
|
22
|
-
//# sourceMappingURL=modify-file-
|
|
22
|
+
//# sourceMappingURL=modify-file-Dgd_PzRG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modify-file-
|
|
1
|
+
{"version":3,"file":"modify-file-Dgd_PzRG.js","names":[],"sources":["../../src/runtime/modify-file.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport type { File, ModifyOutcome } from \"../core/types\";\nimport { languageFromPath } from \"../core/util\";\n\nexport function modifyOutcomeToFile(\n filePath: string,\n outcome: ModifyOutcome,\n): File | null {\n const language = languageFromPath(filePath);\n\n if (outcome.status === \"success\") {\n if (!outcome.changed) return null;\n return {\n path: filePath,\n language,\n content: fs.readFileSync(filePath, \"utf8\"),\n status: \"success\",\n };\n }\n\n const content =\n outcome.status === \"failed\" && fs.existsSync(filePath)\n ? fs.readFileSync(filePath, \"utf8\")\n : \"\";\n\n return {\n path: filePath,\n language,\n content,\n status: outcome.status,\n message: outcome.message,\n };\n}\n"],"mappings":";;;AAIA,SAAgB,EACd,GACA,GACa;CACb,IAAM,IAAW,EAAiB,CAAQ;CAiB1C,OAfI,EAAQ,WAAW,YAChB,EAAQ,UACN;EACL,MAAM;EACN;EACA,SAAS,EAAG,aAAa,GAAU,MAAM;EACzC,QAAQ;CACV,IAN6B,OAcxB;EACL,MAAM;EACN;EACA,SAPA,EAAQ,WAAW,YAAY,EAAG,WAAW,CAAQ,IACjD,EAAG,aAAa,GAAU,MAAM,IAChC;EAMJ,QAAQ,EAAQ;EAChB,SAAS,EAAQ;CACnB;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as e } from "./util-Bq_Mh6IQ.js";
|
|
2
2
|
//#region src/patterns/destroy/shared.ts
|
|
3
3
|
function t(t) {
|
|
4
4
|
return {
|
|
@@ -15,7 +15,7 @@ async function n(e, t) {
|
|
|
15
15
|
exists: !0,
|
|
16
16
|
rowCount: 0
|
|
17
17
|
}));
|
|
18
|
-
let { withPocketbase: n } = await import("./pocketbase-059B1oot.js"), { planCollectionDrops: r } = await import("./collections-
|
|
18
|
+
let { withPocketbase: n } = await import("./pocketbase-059B1oot.js"), { planCollectionDrops: r } = await import("./collections-B-yQ1qt6.js"), i = [];
|
|
19
19
|
return await n(t.root, async (t) => {
|
|
20
20
|
let n = await r(t, e);
|
|
21
21
|
i.push(...n);
|
|
@@ -24,4 +24,4 @@ async function n(e, t) {
|
|
|
24
24
|
//#endregion
|
|
25
25
|
export { t as n, n as t };
|
|
26
26
|
|
|
27
|
-
//# sourceMappingURL=shared-
|
|
27
|
+
//# sourceMappingURL=shared-cFKFtcgw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-
|
|
1
|
+
{"version":3,"file":"shared-cFKFtcgw.js","names":[],"sources":["../../src/patterns/destroy/shared.ts"],"sourcesContent":["import type { CollectionDropSpec, File, Options } from \"../../core/types\";\nimport { languageFromPath } from \"../../core/util\";\n\nexport function toDeleteEntry(path: string): File {\n return {\n path,\n language: languageFromPath(path),\n content: \"\",\n status: \"success\",\n };\n}\n\n/**\n * Build `CollectionDropSpec` entries for each collection name, with live row\n * counts from PocketBase when `env === \"runtime\"`. In preview mode, returns\n * `{ exists: true, rowCount: 0 }` placeholders.\n */\nexport async function planDropsForCollections(\n collectionNames: string[],\n options: Options,\n): Promise<CollectionDropSpec[]> {\n if (collectionNames.length === 0) return [];\n\n if (options.env !== \"runtime\") {\n return collectionNames.map((name) => ({\n name,\n exists: true,\n rowCount: 0,\n }));\n }\n\n const { withPocketbase } = await import(\"../../runtime/pocketbase\");\n const { planCollectionDrops } = await import(\"../../runtime/collections\");\n const drops: CollectionDropSpec[] = [];\n await withPocketbase(options.root, async (pb) => {\n const plans = await planCollectionDrops(pb, collectionNames);\n drops.push(...plans);\n });\n return drops;\n}\n"],"mappings":";;AAGA,SAAgB,EAAc,GAAoB;CAChD,OAAO;EACL;EACA,UAAU,EAAiB,CAAI;EAC/B,SAAS;EACT,QAAQ;CACV;AACF;AAOA,eAAsB,EACpB,GACA,GAC+B;CAC/B,IAAI,EAAgB,WAAW,GAAG,OAAO,CAAC;CAE1C,IAAI,EAAQ,QAAQ,WAClB,OAAO,EAAgB,KAAK,OAAU;EACpC;EACA,QAAQ;EACR,UAAU;CACZ,EAAE;CAGJ,IAAM,EAAE,sBAAmB,MAAM,OAAO,6BAClC,EAAE,2BAAwB,MAAM,OAAO,8BACvC,IAA8B,CAAC;CAKrC,OAJA,MAAM,EAAe,EAAQ,MAAM,OAAO,MAAO;EAC/C,IAAM,IAAQ,MAAM,EAAoB,GAAI,CAAe;EAC3D,EAAM,KAAK,GAAG,CAAK;CACrB,CAAC,GACM;AACT"}
|
|
@@ -3,26 +3,30 @@ import { o as t, s as n } from "./config-target-DOi8kI_f.js";
|
|
|
3
3
|
import r from "node:fs";
|
|
4
4
|
import { SyntaxKind as i } from "ts-morph";
|
|
5
5
|
//#region src/patterns/enable/backend/modifies/svelte-config.ts
|
|
6
|
-
var a = e`
|
|
7
|
-
Switch the SvelteKit adapter to
|
|
6
|
+
var a = "@sveltejs/adapter-node", o = "@sveltejs/adapter-static", s = "@sveltejs/adapter-auto", c = e`
|
|
7
|
+
Switch the SvelteKit adapter to ${a}:
|
|
8
8
|
|
|
9
|
-
import adapter from '
|
|
9
|
+
import adapter from '${a}';
|
|
10
10
|
|
|
11
11
|
// ...
|
|
12
12
|
adapter: adapter()
|
|
13
|
-
`,
|
|
14
|
-
Configure
|
|
13
|
+
`, l = e`
|
|
14
|
+
Configure ${a} via the sveltekit() plugin in vite.config.ts.
|
|
15
15
|
`;
|
|
16
|
-
function
|
|
17
|
-
return e.getImportDeclarations().find((e) =>
|
|
16
|
+
function u(e) {
|
|
17
|
+
return e.getImportDeclarations().find((e) => [
|
|
18
|
+
o,
|
|
19
|
+
s,
|
|
20
|
+
a
|
|
21
|
+
].includes(e.getModuleSpecifierValue()));
|
|
18
22
|
}
|
|
19
|
-
function
|
|
23
|
+
function d(e) {
|
|
20
24
|
return e.getDescendantsOfKind(i.CallExpression).filter((e) => e.getExpression().getText() === "adapter");
|
|
21
25
|
}
|
|
22
|
-
function
|
|
26
|
+
function f(e) {
|
|
23
27
|
let r = t(e, {
|
|
24
|
-
notFound:
|
|
25
|
-
failed:
|
|
28
|
+
notFound: l,
|
|
29
|
+
failed: c
|
|
26
30
|
});
|
|
27
31
|
if (r.status !== "resolved") return {
|
|
28
32
|
filePath: r.filePath,
|
|
@@ -31,16 +35,16 @@ function l(e) {
|
|
|
31
35
|
message: r.message
|
|
32
36
|
}
|
|
33
37
|
};
|
|
34
|
-
let { target: i } = r,
|
|
35
|
-
if (!
|
|
38
|
+
let { target: i } = r, o = u(i.sourceFile);
|
|
39
|
+
if (!o) return {
|
|
36
40
|
filePath: i.filePath,
|
|
37
41
|
outcome: {
|
|
38
42
|
status: "failed",
|
|
39
|
-
message:
|
|
43
|
+
message: c
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
|
-
|
|
43
|
-
for (let e of
|
|
46
|
+
o.getModuleSpecifierValue() !== a && o.setModuleSpecifier(a);
|
|
47
|
+
for (let e of d(i.sourceFile)) {
|
|
44
48
|
let t = e.getArguments();
|
|
45
49
|
for (let n = t.length - 1; n >= 0; n--) e.removeArgument(n);
|
|
46
50
|
}
|
|
@@ -49,10 +53,10 @@ function l(e) {
|
|
|
49
53
|
outcome: n(i)
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
|
-
function
|
|
56
|
+
function p(e) {
|
|
53
57
|
let r = t(e, {
|
|
54
|
-
notFound:
|
|
55
|
-
failed:
|
|
58
|
+
notFound: l,
|
|
59
|
+
failed: c
|
|
56
60
|
});
|
|
57
61
|
if (r.status !== "resolved") return {
|
|
58
62
|
filePath: r.filePath,
|
|
@@ -61,16 +65,16 @@ function u(e) {
|
|
|
61
65
|
changed: !1
|
|
62
66
|
}
|
|
63
67
|
};
|
|
64
|
-
let { target: i } = r,
|
|
65
|
-
if (!
|
|
68
|
+
let { target: i } = r, a = u(i.sourceFile);
|
|
69
|
+
if (!a) return {
|
|
66
70
|
filePath: i.filePath,
|
|
67
71
|
outcome: {
|
|
68
72
|
status: "success",
|
|
69
73
|
changed: !1
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
|
-
|
|
73
|
-
for (let e of
|
|
76
|
+
a.getModuleSpecifierValue() !== o && a.setModuleSpecifier(o);
|
|
77
|
+
for (let e of d(i.sourceFile)) e.getArguments().length === 0 && e.addArgument("{ fallback: '200.html' }");
|
|
74
78
|
return {
|
|
75
79
|
filePath: i.filePath,
|
|
76
80
|
outcome: n(i)
|
|
@@ -78,7 +82,7 @@ function u(e) {
|
|
|
78
82
|
}
|
|
79
83
|
//#endregion
|
|
80
84
|
//#region src/patterns/enable/backend/modifies/gitignore.ts
|
|
81
|
-
var
|
|
85
|
+
var m = "# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n", h = e`
|
|
82
86
|
Create a .gitignore at the project root with the PocketBase block:
|
|
83
87
|
|
|
84
88
|
# PocketBase
|
|
@@ -87,23 +91,23 @@ var d = "# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n",
|
|
|
87
91
|
!/data/seeds
|
|
88
92
|
!/data/hooks
|
|
89
93
|
`;
|
|
90
|
-
function
|
|
94
|
+
function g(e) {
|
|
91
95
|
if (!r.existsSync(e)) return {
|
|
92
96
|
status: "not-found",
|
|
93
|
-
message:
|
|
97
|
+
message: h
|
|
94
98
|
};
|
|
95
99
|
let t = r.readFileSync(e, "utf8");
|
|
96
100
|
if (t.includes("# PocketBase") && t.includes("/data/*")) return {
|
|
97
101
|
status: "success",
|
|
98
102
|
changed: !1
|
|
99
103
|
};
|
|
100
|
-
let n = t + (t.endsWith("\n") ? "\n" : "\n\n") +
|
|
104
|
+
let n = t + (t.endsWith("\n") ? "\n" : "\n\n") + m;
|
|
101
105
|
return r.writeFileSync(e, n, "utf8"), {
|
|
102
106
|
status: "success",
|
|
103
107
|
changed: !0
|
|
104
108
|
};
|
|
105
109
|
}
|
|
106
|
-
function
|
|
110
|
+
function _(e) {
|
|
107
111
|
if (!r.existsSync(e)) return {
|
|
108
112
|
status: "success",
|
|
109
113
|
changed: !1
|
|
@@ -124,7 +128,7 @@ function m(e) {
|
|
|
124
128
|
}
|
|
125
129
|
//#endregion
|
|
126
130
|
//#region src/patterns/enable/backend/modifies/test-setup.ts
|
|
127
|
-
var
|
|
131
|
+
var v = "import { beforeEach, afterEach, beforeAll } from 'vitest';\nimport supertest, { type Agent } from 'supertest';\nimport PocketBase from 'pocketbase-sveltekit';\nimport type { TestContext } from '@velastack/pocketbase/testing';\n\nconst admin = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['admin'];\nconst pb = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['pb'];\n\nconst testUserPassword = 'password';\n\nasync function authenticateUser(agent: Agent, user: { email: string }) {\n await agent.post('/login').type('form').send({\n type: 'password',\n email: user.email,\n password: testUserPassword\n });\n}\n\nbeforeAll(async () => {\n await admin\n // @ts-ignore\n .collection('_superusers')\n .authWithPassword(\n process.env.POCKETBASE_SUPERUSER_EMAIL!,\n process.env.POCKETBASE_SUPERUSER_PASSWORD!\n );\n});\n\nbeforeEach(async (context: TestContext) => {\n context.request = supertest(process.env.VITE_TEST_URL!);\n context.agent = supertest.agent(process.env.VITE_TEST_URL!) as TestContext['agent'];\n context.admin = admin;\n context.pb = pb;\n context.user = await context.admin.collection('users').create({\n email: `test-${Math.random().toString(36).slice(2)}@example.com`,\n password: testUserPassword,\n passwordConfirm: testUserPassword\n });\n context.agent.authenticateUser = () => authenticateUser(context.agent, context.user);\n await context.pb.collection('users').authWithPassword(context.user.email, testUserPassword);\n});\n\nafterEach(async (context: TestContext) => {\n await context.pb.authStore.clear();\n await context.admin.collection('users').delete(context.user.id);\n});\n", y = "import { beforeEach } from 'vitest';\nimport supertest from 'supertest';\n\nbeforeEach(async (context: any) => {\n context.request = supertest(process.env.VITE_TEST_URL!);\n context.agent = supertest.agent(process.env.VITE_TEST_URL!);\n});\n", b = e`
|
|
128
132
|
Create test/setup.ts. The default minimal-template setup wires supertest:
|
|
129
133
|
|
|
130
134
|
import { beforeEach } from 'vitest';
|
|
@@ -135,28 +139,28 @@ var h = "import { beforeEach, afterEach, beforeAll } from 'vitest';\nimport supe
|
|
|
135
139
|
context.agent = supertest.agent(process.env.VITE_TEST_URL!);
|
|
136
140
|
});
|
|
137
141
|
`;
|
|
138
|
-
function
|
|
139
|
-
return r.existsSync(e) ? r.readFileSync(e, "utf8") ===
|
|
142
|
+
function x(e) {
|
|
143
|
+
return r.existsSync(e) ? r.readFileSync(e, "utf8") === v ? {
|
|
140
144
|
status: "success",
|
|
141
145
|
changed: !1
|
|
142
|
-
} : (r.writeFileSync(e,
|
|
146
|
+
} : (r.writeFileSync(e, v, "utf8"), {
|
|
143
147
|
status: "success",
|
|
144
148
|
changed: !0
|
|
145
149
|
}) : {
|
|
146
150
|
status: "not-found",
|
|
147
|
-
message:
|
|
151
|
+
message: b
|
|
148
152
|
};
|
|
149
153
|
}
|
|
150
|
-
function
|
|
151
|
-
return !r.existsSync(e) || r.readFileSync(e, "utf8") ===
|
|
154
|
+
function S(e) {
|
|
155
|
+
return !r.existsSync(e) || r.readFileSync(e, "utf8") === y ? {
|
|
152
156
|
status: "success",
|
|
153
157
|
changed: !1
|
|
154
|
-
} : (r.writeFileSync(e,
|
|
158
|
+
} : (r.writeFileSync(e, y, "utf8"), {
|
|
155
159
|
status: "success",
|
|
156
160
|
changed: !0
|
|
157
161
|
});
|
|
158
162
|
}
|
|
159
163
|
//#endregion
|
|
160
|
-
export {
|
|
164
|
+
export { f as a, _ as i, S as n, p as o, g as r, x as t };
|
|
161
165
|
|
|
162
|
-
//# sourceMappingURL=test-setup-
|
|
166
|
+
//# sourceMappingURL=test-setup-BBb4kcoO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-setup-BBb4kcoO.js","names":[],"sources":["../../src/patterns/enable/backend/modifies/svelte-config.ts","../../src/patterns/enable/backend/modifies/gitignore.ts","../../src/patterns/enable/backend/modifies/test-setup.ts"],"sourcesContent":["import dedent from \"dedent\";\nimport { SyntaxKind } from \"ts-morph\";\nimport {\n resolveConfigTarget,\n saveTarget,\n type ConfigModifyResult,\n type ConfigTarget,\n} from \"../../../../runtime/config-target\";\n\nconst ADAPTER_NODE = \"@sveltejs/adapter-node\";\nconst ADAPTER_STATIC = \"@sveltejs/adapter-static\";\nconst ADAPTER_AUTO = \"@sveltejs/adapter-auto\";\n\nconst FAILURE_HINT = dedent`\n Switch the SvelteKit adapter to ${ADAPTER_NODE}:\n\n import adapter from '${ADAPTER_NODE}';\n\n // ...\n adapter: adapter()\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Configure ${ADAPTER_NODE} via the sveltekit() plugin in vite.config.ts.\n`;\n\n/**\n * The adapters this pattern moves between. adapter-auto is included because\n * that is what `sv create` ships, and a project that never chose is one the\n * backend is free to decide for.\n */\nfunction findAdapterImport(sourceFile: ConfigTarget[\"sourceFile\"]) {\n return sourceFile\n .getImportDeclarations()\n .find((decl) =>\n [ADAPTER_STATIC, ADAPTER_AUTO, ADAPTER_NODE].includes(\n decl.getModuleSpecifierValue(),\n ),\n );\n}\n\nfunction adapterCalls(sourceFile: ConfigTarget[\"sourceFile\"]) {\n return sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((ce) => ce.getExpression().getText() === \"adapter\");\n}\n\n/**\n * Switch the adapter to `@sveltejs/adapter-node` and drop its arguments, in\n * whichever file holds the adapter import + `adapter()` call (vite.config when\n * the project uses inline config, else svelte.config). A project with a\n * backend is served from a Node process, which is what `vela deploy` runs.\n * Operates on the import and call expression directly, so it never needs the\n * config object.\n */\nexport function modifySvelteConfig(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, {\n notFound: NOT_FOUND_HINT,\n failed: FAILURE_HINT,\n });\n if (res.status !== \"resolved\") {\n return {\n filePath: res.filePath,\n outcome: { status: res.status, message: res.message },\n };\n }\n const { target } = res;\n const adapterImport = findAdapterImport(target.sourceFile);\n if (!adapterImport) {\n return {\n filePath: target.filePath,\n outcome: { status: \"failed\", message: FAILURE_HINT },\n };\n }\n\n if (adapterImport.getModuleSpecifierValue() !== ADAPTER_NODE) {\n adapterImport.setModuleSpecifier(ADAPTER_NODE);\n }\n\n for (const call of adapterCalls(target.sourceFile)) {\n const args = call.getArguments();\n for (let i = args.length - 1; i >= 0; i--) {\n call.removeArgument(i);\n }\n }\n\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n\n/**\n * Reverse of {@link modifySvelteConfig}: switch back to\n * `@sveltejs/adapter-static` and restore the `{ fallback: '200.html' }` arg.\n * Lenient — if no config or no adapter import is found, it's a no-op success.\n */\nexport function unmodifySvelteConfig(root: string): ConfigModifyResult {\n const res = resolveConfigTarget(root, {\n notFound: NOT_FOUND_HINT,\n failed: FAILURE_HINT,\n });\n if (res.status !== \"resolved\") {\n // Nothing to revert — treat missing/unparseable config as a no-op.\n return {\n filePath: res.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n const { target } = res;\n const adapterImport = findAdapterImport(target.sourceFile);\n if (!adapterImport) {\n return {\n filePath: target.filePath,\n outcome: { status: \"success\", changed: false },\n };\n }\n\n if (adapterImport.getModuleSpecifierValue() !== ADAPTER_STATIC) {\n adapterImport.setModuleSpecifier(ADAPTER_STATIC);\n }\n\n for (const call of adapterCalls(target.sourceFile)) {\n if (call.getArguments().length === 0) {\n call.addArgument(\"{ fallback: '200.html' }\");\n }\n }\n\n return { filePath: target.filePath, outcome: saveTarget(target) };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst POCKETBASE_BLOCK = `# PocketBase\n/data/*\n!/data/fixtures\n!/data/seeds\n!/data/hooks\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create a .gitignore at the project root with the PocketBase block:\n\n # PocketBase\n /data/*\n !/data/fixtures\n !/data/seeds\n !/data/hooks\n`;\n\nexport function modifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n\n if (original.includes(\"# PocketBase\") && original.includes(\"/data/*\")) {\n return { status: \"success\", changed: false };\n }\n\n const separator = original.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n const next = original + separator + POCKETBASE_BLOCK;\n fs.writeFileSync(gitignorePath, next, \"utf8\");\n\n return { status: \"success\", changed: true };\n}\n\nexport function unmodifyGitignore(gitignorePath: string): ModifyOutcome {\n if (!fs.existsSync(gitignorePath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(gitignorePath, \"utf8\");\n\n if (!original.includes(\"# PocketBase\")) {\n return { status: \"success\", changed: false };\n }\n\n const withBlockRemoved = original.replace(\n /\\n*# PocketBase\\n\\/data\\/\\*\\n!\\/data\\/fixtures\\n!\\/data\\/seeds\\n!\\/data\\/hooks\\n?/,\n \"\\n\",\n );\n\n const cleaned = withBlockRemoved.replace(/\\n{3,}$/, \"\\n\");\n\n if (cleaned === original) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(gitignorePath, cleaned, \"utf8\");\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\n// Source of truth: velastack-cli/templates/minimal/test/setup.ts\nconst WITH_BACKEND = `import { beforeEach, afterEach, beforeAll } from 'vitest';\nimport supertest, { type Agent } from 'supertest';\nimport PocketBase from 'pocketbase-sveltekit';\nimport type { TestContext } from '@velastack/pocketbase/testing';\n\nconst admin = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['admin'];\nconst pb = new PocketBase(process.env.POCKETBASE_URL!) as App.Locals['pb'];\n\nconst testUserPassword = 'password';\n\nasync function authenticateUser(agent: Agent, user: { email: string }) {\n\\tawait agent.post('/login').type('form').send({\n\\t\\ttype: 'password',\n\\t\\temail: user.email,\n\\t\\tpassword: testUserPassword\n\\t});\n}\n\nbeforeAll(async () => {\n\\tawait admin\n\\t\\t// @ts-ignore\n\\t\\t.collection('_superusers')\n\\t\\t.authWithPassword(\n\\t\\t\\tprocess.env.POCKETBASE_SUPERUSER_EMAIL!,\n\\t\\t\\tprocess.env.POCKETBASE_SUPERUSER_PASSWORD!\n\\t\\t);\n});\n\nbeforeEach(async (context: TestContext) => {\n\\tcontext.request = supertest(process.env.VITE_TEST_URL!);\n\\tcontext.agent = supertest.agent(process.env.VITE_TEST_URL!) as TestContext['agent'];\n\\tcontext.admin = admin;\n\\tcontext.pb = pb;\n\\tcontext.user = await context.admin.collection('users').create({\n\\t\\temail: \\`test-\\${Math.random().toString(36).slice(2)}@example.com\\`,\n\\t\\tpassword: testUserPassword,\n\\t\\tpasswordConfirm: testUserPassword\n\\t});\n\\tcontext.agent.authenticateUser = () => authenticateUser(context.agent, context.user);\n\\tawait context.pb.collection('users').authWithPassword(context.user.email, testUserPassword);\n});\n\nafterEach(async (context: TestContext) => {\n\\tawait context.pb.authStore.clear();\n\\tawait context.admin.collection('users').delete(context.user.id);\n});\n`;\n\n// Source of truth: velastack-cli/templates/static/test/setup.ts\nconst WITHOUT_BACKEND = `import { beforeEach } from 'vitest';\nimport supertest from 'supertest';\n\nbeforeEach(async (context: any) => {\n\\tcontext.request = supertest(process.env.VITE_TEST_URL!);\n\\tcontext.agent = supertest.agent(process.env.VITE_TEST_URL!);\n});\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create test/setup.ts. The default minimal-template setup wires supertest:\n\n import { beforeEach } from 'vitest';\n import supertest from 'supertest';\n\n beforeEach(async (context: any) => {\n context.request = supertest(process.env.VITE_TEST_URL!);\n context.agent = supertest.agent(process.env.VITE_TEST_URL!);\n });\n`;\n\nexport function modifyTestSetup(testSetupPath: string): ModifyOutcome {\n if (!fs.existsSync(testSetupPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const original = fs.readFileSync(testSetupPath, \"utf8\");\n if (original === WITH_BACKEND) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(testSetupPath, WITH_BACKEND, \"utf8\");\n return { status: \"success\", changed: true };\n}\n\nexport function unmodifyTestSetup(testSetupPath: string): ModifyOutcome {\n if (!fs.existsSync(testSetupPath)) {\n return { status: \"success\", changed: false };\n }\n\n const original = fs.readFileSync(testSetupPath, \"utf8\");\n if (original === WITHOUT_BACKEND) {\n return { status: \"success\", changed: false };\n }\n\n fs.writeFileSync(testSetupPath, WITHOUT_BACKEND, \"utf8\");\n return { status: \"success\", changed: true };\n}\n"],"mappings":";;;;;AASA,IAAM,IAAe,0BACf,IAAiB,4BACjB,IAAe,0BAEf,IAAe,CAAM;oCACS,EAAa;;yBAExB,EAAa;;;;GAMhC,IAAiB,CAAM;cACf,EAAa;;AAQ3B,SAAS,EAAkB,GAAwC;CACjE,OAAO,EACJ,sBAAsB,CAAC,C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B,GAAsC;CAWpE,OAVK,EAAG,WAAW,CAAa,IAIf,EAAG,aAAa,GAAe,MAC5C,MAAa,IACR;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7C,EAAG,cAAc,GAAe,GAAc,MAAM,GAC7C;EAAE,QAAQ;EAAW,SAAS;CAAK,KATjC;EAAE,QAAQ;EAAa,SAAS;CAAe;AAU1D;AAEA,SAAgB,EAAkB,GAAsC;CAWtE,OAVI,CAAC,EAAG,WAAW,CAAa,KAIf,EAAG,aAAa,GAAe,MAC5C,MAAa,IACR;EAAE,QAAQ;EAAW,SAAS;CAAM,KAG7C,EAAG,cAAc,GAAe,GAAiB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK;AAC5C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as e, t } from "./errors-D6gyegUK.js";
|
|
2
2
|
import { n } from "./logger-CQONztPm.js";
|
|
3
|
-
import { executeCommand as r, formatPaths as i, getAllCustomComponents as a, installComponents as o, installedComponents as s, installedPackagesFromProject as c, isCustomComponent as l, n as u, t as d } from "./write-result-
|
|
3
|
+
import { executeCommand as r, formatPaths as i, getAllCustomComponents as a, installComponents as o, installedComponents as s, installedPackagesFromProject as c, isCustomComponent as l, n as u, t as d } from "./write-result-DgFUKxhP.js";
|
|
4
4
|
import f from "node:path";
|
|
5
5
|
import { existsSync as p, readFileSync as m, writeFileSync as h } from "node:fs";
|
|
6
6
|
import { createRequire as g } from "node:module";
|
|
@@ -170,4 +170,4 @@ async function N(e, t) {
|
|
|
170
170
|
//#endregion
|
|
171
171
|
export { M as applyBaseColor, N as applyTheme, C as listComponents, D as switchStyle };
|
|
172
172
|
|
|
173
|
-
//# sourceMappingURL=ui-
|
|
173
|
+
//# sourceMappingURL=ui-X12f0xKA.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-DAtVMiVs.js","names":[],"sources":["../../src/runtime/shadcn-preset.ts","../../src/runtime/ui.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { WriteResultRuntime } from \"../core/types\";\nimport { readComponentsConfig } from \"./registry\";\nimport { executeCommand, formatPaths } from \"./write-result\";\n\n/**\n * What a shadcn-svelte preset code carries. Mirrors `PresetConfig` from\n * `shadcn-svelte/preset` as plain strings, so this package's types do not\n * depend on a package its consumers may not have installed.\n */\nexport interface PresetConfig {\n style: string;\n baseColor: string;\n theme: string;\n chartColor?: string;\n iconLibrary: string;\n font: string;\n fontHeading: string;\n radius: string;\n menuAccent: string;\n menuColor: string;\n}\n\n/** The part of `shadcn-svelte/preset` this package uses. */\nexport interface ShadcnPreset {\n PRESET_STYLES: readonly string[];\n PRESET_BASE_COLOR_KEYS: readonly string[];\n PRESET_THEME_KEYS: readonly string[];\n PRESET_FONTS: readonly string[];\n PRESET_ICON_LIBRARIES: readonly string[];\n encodePreset(config: Partial<PresetConfig>): string;\n decodePreset(code: string): PresetConfig | null;\n}\n\nexport type PresetPart = \"theme\" | \"font\";\n\n/**\n * The encoder from the *project's* shadcn-svelte, so every preset code is\n * produced by the same version that consumes it and the value lists can\n * never drift from what `apply` accepts.\n */\nexport async function loadPreset(root: string): Promise<ShadcnPreset> {\n let resolved: string;\n try {\n resolved = createRequire(path.join(root, \"package.json\")).resolve(\n \"shadcn-svelte/preset\",\n );\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Could not load shadcn-svelte/preset from ${root}: ${reason}\\n` +\n \"Install the project's dependencies (shadcn-svelte >= 1.6) and try again.\",\n );\n }\n const module: unknown = await import(\n /* @vite-ignore */ pathToFileURL(resolved).href\n );\n return module as ShadcnPreset;\n}\n\n/**\n * The font each style is designed with. shadcn-svelte keeps this table inside\n * its bundle (the `create` presets) without exporting it, so it is vendored\n * here; `shadcn-preset.test.ts` checks it still covers every style the\n * installed shadcn-svelte knows.\n */\nexport const STYLE_FONTS: Record<\n string,\n { font: string; fontHeading?: string }\n> = {\n nova: { font: \"geist\" },\n vega: { font: \"inter\" },\n maia: { font: \"figtree\" },\n lyra: { font: \"jetbrains-mono\" },\n mira: { font: \"inter\" },\n luma: { font: \"inter\" },\n sera: { font: \"noto-sans\", fontHeading: \"playfair-display\" },\n rhea: { font: \"inter\" },\n};\n\n/**\n * A preset code for the project as it is, with `overrides` on top: the style,\n * base color, icon library and menu settings come from `components.json` so\n * an `apply --only theme` keeps everything it does not mean to change.\n * Values shadcn-svelte does not know (a `slate` from an older template) fall\n * back to its defaults inside `encodePreset`.\n */\nexport async function presetFor(\n root: string,\n overrides: Partial<PresetConfig>,\n preset?: ShadcnPreset,\n): Promise<string> {\n const { encodePreset } = preset ?? (await loadPreset(root));\n const config = readComponentsConfig(root);\n const current: Partial<PresetConfig> = { style: config.style };\n if (config.baseColor) current.baseColor = config.baseColor;\n if (config.iconLibrary) current.iconLibrary = config.iconLibrary;\n if (config.menuColor) current.menuColor = config.menuColor;\n if (config.menuAccent) current.menuAccent = config.menuAccent;\n return encodePreset({ ...current, ...overrides });\n}\n\n/**\n * `shadcn-svelte apply --preset <code> --only <parts> --yes` through the\n * project's package manager. `theme` rewrites the token values in `:root` /\n * `.dark` and records the base color in `components.json`; `font` adds the\n * fontsource import, dependency and `--font-sans`. Both leave the rest of the\n * stylesheet alone but write it in the registry's formatting, so the file is\n * run through the project's prettier afterwards.\n */\nexport async function applyPreset(\n root: string,\n code: string,\n only: PresetPart[],\n runtime?: WriteResultRuntime,\n): Promise<void> {\n await executeCommand(\n root,\n \"execute\",\n [\"shadcn-svelte\", \"apply\", \"--preset\", code, \"--only\", ...only, \"--yes\"],\n runtime,\n );\n await formatPaths(root, [readComponentsConfig(root).cssPath]);\n}\n","import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n ApplyBaseColorOptions,\n ApplyColorsResult,\n ApplyThemeOptions,\n Component,\n ListComponentsOptions,\n ListComponentsResult,\n RegistryItem,\n SwitchStyleOptions,\n SwitchStyleResult,\n WriteResultRuntime,\n} from \"../core/types\";\nimport { InvalidArgumentError, RegistryUnavailableError } from \"../core/errors\";\nimport { getLogger } from \"../core/logger\";\nimport { fetchRegistryIndex, readComponentsConfig } from \"./registry\";\nimport {\n applyPreset,\n loadPreset,\n presetFor,\n STYLE_FONTS,\n type ShadcnPreset,\n} from \"./shadcn-preset\";\nimport {\n getAllCustomComponents,\n installComponents,\n installedComponents,\n installedPackagesFromProject,\n isCustomComponent,\n} from \"./write-result\";\n\nconst COMPONENTS_JSON = \"components.json\";\n\n/**\n * What a project has and what it could add: the ui directory, this package's\n * bundled components, and the registry index of the configured style. A\n * registry that cannot be read leaves the first two intact and says why.\n */\nexport async function listComponents(\n options: ListComponentsOptions,\n runtime?: WriteResultRuntime,\n): Promise<ListComponentsResult> {\n const { root } = options;\n const { style } = readComponentsConfig(root);\n const result: ListComponentsResult = {\n style,\n installed: installedComponents(root),\n custom: getAllCustomComponents(),\n registry: [],\n };\n try {\n result.registry = await fetchRegistryIndex(root, { runtime });\n } catch (error) {\n if (!(error instanceof RegistryUnavailableError)) throw error;\n result.registryUnavailable = error.message;\n }\n return result;\n}\n\nfunction assertOneOf(\n kind: string,\n value: string,\n choices: readonly string[],\n): void {\n if (choices.includes(value)) return;\n throw new InvalidArgumentError(\n `Unknown ${kind} \"${value}\". Choose one of: ${choices.join(\", \")}.`,\n );\n}\n\n/**\n * Rewrites `style` in `components.json` and nothing else, keeping the file's\n * indentation so the change reads as the one-line diff it is.\n */\nfunction writeStyle(root: string, style: string): void {\n const configPath = path.join(root, COMPONENTS_JSON);\n if (!existsSync(configPath)) {\n throw new Error(\n `${COMPONENTS_JSON} not found in ${root}; this does not look like a shadcn-svelte project.`,\n );\n }\n const text = readFileSync(configPath, \"utf8\");\n const config = JSON.parse(text) as Record<string, unknown>;\n config.style = style;\n const indent = text.includes(\"\\n\\t\") ? \"\\t\" : 2;\n writeFileSync(\n configPath,\n `${JSON.stringify(config, null, indent)}\\n`,\n \"utf8\",\n );\n}\n\nfunction registryUiNames(index: RegistryItem[]): Set<string> {\n return new Set(\n index\n .filter((item) => item.type === \"registry:ui\")\n .map((item) => item.name),\n );\n}\n\n/**\n * Moves a project to another shadcn-svelte style. Every installed component\n * the new style's registry also offers is re-added from there (their local\n * edits are lost, which is what `confirm` is for); this package's own\n * components and anything the registry does not know are left alone. The\n * style's preset font follows unless `font` is false.\n */\nexport async function switchStyle(\n options: SwitchStyleOptions,\n runtime?: WriteResultRuntime,\n): Promise<SwitchStyleResult> {\n const { root, style, font = true } = options;\n const logger = getLogger(options);\n const preset = await loadPreset(root);\n assertOneOf(\"style\", style, preset.PRESET_STYLES);\n\n const unchanged: SwitchStyleResult = {\n status: \"unchanged\",\n style,\n reinstalled: [],\n filesModified: [],\n packages: [],\n hints: [],\n };\n if (readComponentsConfig(root).style === style) {\n return unchanged;\n }\n\n const index = await fetchRegistryIndex(root, { style, runtime });\n const offered = registryUiNames(index);\n const reinstall = installedComponents(root).filter(\n (component) => offered.has(component) && !isCustomComponent(component),\n );\n\n if (options.confirm && !(await options.confirm(reinstall))) {\n return { ...unchanged, status: \"cancelled\" };\n }\n\n const packagesBefore = installedPackagesFromProject(root);\n writeStyle(root, style);\n const filesModified = [COMPONENTS_JSON];\n\n let reinstalled: Component[] = [];\n if (reinstall.length > 0) {\n const outcome = await installComponents(\n { root, components: reinstall, overwrite: true, logger },\n runtime,\n );\n reinstalled = outcome.installed;\n }\n\n const hints: string[] = [];\n if (font) {\n await applyStyleFont(\n root,\n style,\n preset,\n runtime,\n filesModified,\n hints,\n logger,\n );\n }\n\n const packages = [...installedPackagesFromProject(root)]\n .filter((name) => !packagesBefore.has(name))\n .sort();\n\n return {\n status: \"switched\",\n style,\n reinstalled,\n filesModified,\n packages,\n hints,\n };\n}\n\nconst FONTSOURCE_IMPORT =\n /@import\\s+[\"']@fontsource(?:-variable)?\\/([^\"']+)[\"']/g;\n\n/** The fontsource families a stylesheet imports, in order. */\nfunction fontsourceImports(css: string): string[] {\n return [...css.matchAll(FONTSOURCE_IMPORT)].map((match) => match[1]!);\n}\n\nasync function applyStyleFont(\n root: string,\n style: string,\n preset: ShadcnPreset,\n runtime: WriteResultRuntime | undefined,\n filesModified: string[],\n hints: string[],\n logger: ReturnType<typeof getLogger>,\n): Promise<void> {\n const fonts = STYLE_FONTS[style];\n if (!fonts) {\n logger.info(\n `No preset font is known for the ${style} style; leaving fonts unchanged.`,\n );\n return;\n }\n logger.info(`Applying the ${style} font (${fonts.font})`);\n const code = await presetFor(root, { style, ...fonts }, preset);\n await applyPreset(root, code, [\"font\"], runtime);\n\n const cssPath = readComponentsConfig(root).cssPath;\n filesModified.push(cssPath, \"package.json\");\n\n // `apply --only font` adds the new font beside whatever was imported before\n // and leaves it to the project to drop the old one; a font nobody uses\n // still ships to every visitor.\n const cssFile = path.join(root, cssPath);\n if (existsSync(cssFile)) {\n const wanted = new Set([fonts.font, fonts.fontHeading].filter(Boolean));\n const stale = fontsourceImports(readFileSync(cssFile, \"utf8\")).filter(\n (family) => !wanted.has(family),\n );\n if (stale.length > 0) {\n hints.push(\n `${cssPath} still imports ${stale.map((f) => `@fontsource-variable/${f}`).join(\", \")} from the previous style; remove the import and the package if nothing else uses them.`,\n );\n }\n }\n}\n\nasync function applyColors(\n root: string,\n overrides: { baseColor?: string; theme: string },\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n const preset = await loadPreset(root);\n if (overrides.baseColor) {\n assertOneOf(\n \"base color\",\n overrides.baseColor,\n preset.PRESET_BASE_COLOR_KEYS,\n );\n }\n assertOneOf(\"theme\", overrides.theme, preset.PRESET_THEME_KEYS);\n\n // Charts follow the accent, as shadcn-svelte's own presets do.\n const code = await presetFor(\n root,\n { ...overrides, chartColor: overrides.theme },\n preset,\n );\n await applyPreset(root, code, [\"theme\"], runtime);\n\n const config = readComponentsConfig(root);\n return {\n baseColor: config.baseColor ?? overrides.baseColor ?? \"\",\n theme: overrides.theme,\n filesModified: [config.cssPath, COMPONENTS_JSON],\n };\n}\n\n/**\n * Sets the base (gray) palette. The accent is reset to the base color as\n * well, since `components.json` records only the base color; `applyTheme`\n * puts an accent back on top.\n */\nexport async function applyBaseColor(\n options: ApplyBaseColorOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(\n options.root,\n { baseColor: options.color, theme: options.color },\n runtime,\n );\n}\n\n/** Sets the accent (primary, ring, charts) and keeps the base palette. */\nexport async function applyTheme(\n options: ApplyThemeOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(options.root, { theme: options.theme }, runtime);\n}\n"],"mappings":";;;;;;;;AA2CA,eAAsB,EAAW,GAAqC;CACpE,IAAI;CACJ,IAAI;EACF,IAAW,EAAc,EAAK,KAAK,GAAM,cAAc,CAAC,CAAC,CAAC,QACxD,sBACF;CACF,SAAS,GAAO;EACd,IAAM,IAAS,aAAiB,QAAQ,EAAM,UAAU,OAAO,CAAK;EACpE,MAAU,MACR,4CAA4C,EAAK,IAAI,EAAO,2EAE9D;CACF;CAIA,OAAO,MAHuB;;EACT,EAAc,CAAQ,CAAC,CAAC;;AAG/C;AAQA,IAAa,IAGT;CACF,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,EAAE,MAAM,iBAAiB;CAC/B,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM,EAAE,MAAM,QAAQ;CACtB,MAAM;EAAE,MAAM;EAAa,aAAa;CAAmB;CAC3D,MAAM,EAAE,MAAM,QAAQ;AACxB;AASA,eAAsB,EACpB,GACA,GACA,GACiB;CACjB,IAAM,EAAE,oBAAiB,KAAW,MAAM,EAAW,CAAI,GACnD,IAAS,EAAqB,CAAI,GAClC,IAAiC,EAAE,OAAO,EAAO,MAAM;CAK7D,OAJI,EAAO,cAAW,EAAQ,YAAY,EAAO,YAC7C,EAAO,gBAAa,EAAQ,cAAc,EAAO,cACjD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EhD,IAAM,IAAS,EAAqB,CAAI;CACxC,OAAO;EACL,WAAW,EAAO,aAAa,EAAU,aAAa;EACtD,OAAO,EAAU;EACjB,eAAe,CAAC,EAAO,SAAS,CAAe;CACjD;AACF;AAOA,eAAsB,EACpB,GACA,GAC4B;CAC5B,OAAO,EACL,EAAQ,MACR;EAAE,WAAW,EAAQ;EAAO,OAAO,EAAQ;CAAM,GACjD,CACF;AACF;AAGA,eAAsB,EACpB,GACA,GAC4B;CAC5B,OAAO,EAAY,EAAQ,MAAM,EAAE,OAAO,EAAQ,MAAM,GAAG,CAAO;AACpE"}
|
|
1
|
+
{"version":3,"file":"ui-X12f0xKA.js","names":[],"sources":["../../src/runtime/shadcn-preset.ts","../../src/runtime/ui.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { WriteResultRuntime } from \"../core/types\";\nimport { readComponentsConfig } from \"./registry\";\nimport { executeCommand, formatPaths } from \"./write-result\";\n\n/**\n * What a shadcn-svelte preset code carries. Mirrors `PresetConfig` from\n * `shadcn-svelte/preset` as plain strings, so this package's types do not\n * depend on a package its consumers may not have installed.\n */\nexport interface PresetConfig {\n style: string;\n baseColor: string;\n theme: string;\n chartColor?: string;\n iconLibrary: string;\n font: string;\n fontHeading: string;\n radius: string;\n menuAccent: string;\n menuColor: string;\n}\n\n/** The part of `shadcn-svelte/preset` this package uses. */\nexport interface ShadcnPreset {\n PRESET_STYLES: readonly string[];\n PRESET_BASE_COLOR_KEYS: readonly string[];\n PRESET_THEME_KEYS: readonly string[];\n PRESET_FONTS: readonly string[];\n PRESET_ICON_LIBRARIES: readonly string[];\n encodePreset(config: Partial<PresetConfig>): string;\n decodePreset(code: string): PresetConfig | null;\n}\n\nexport type PresetPart = \"theme\" | \"font\";\n\n/**\n * The encoder from the *project's* shadcn-svelte, so every preset code is\n * produced by the same version that consumes it and the value lists can\n * never drift from what `apply` accepts.\n */\nexport async function loadPreset(root: string): Promise<ShadcnPreset> {\n let resolved: string;\n try {\n resolved = createRequire(path.join(root, \"package.json\")).resolve(\n \"shadcn-svelte/preset\",\n );\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new Error(\n `Could not load shadcn-svelte/preset from ${root}: ${reason}\\n` +\n \"Install the project's dependencies (shadcn-svelte >= 1.6) and try again.\",\n );\n }\n const module: unknown = await import(\n /* @vite-ignore */ pathToFileURL(resolved).href\n );\n return module as ShadcnPreset;\n}\n\n/**\n * The font each style is designed with. shadcn-svelte keeps this table inside\n * its bundle (the `create` presets) without exporting it, so it is vendored\n * here; `shadcn-preset.test.ts` checks it still covers every style the\n * installed shadcn-svelte knows.\n */\nexport const STYLE_FONTS: Record<\n string,\n { font: string; fontHeading?: string }\n> = {\n nova: { font: \"geist\" },\n vega: { font: \"inter\" },\n maia: { font: \"figtree\" },\n lyra: { font: \"jetbrains-mono\" },\n mira: { font: \"inter\" },\n luma: { font: \"inter\" },\n sera: { font: \"noto-sans\", fontHeading: \"playfair-display\" },\n rhea: { font: \"inter\" },\n};\n\n/**\n * A preset code for the project as it is, with `overrides` on top: the style,\n * base color, icon library and menu settings come from `components.json` so\n * an `apply --only theme` keeps everything it does not mean to change.\n * Values shadcn-svelte does not know (a `slate` from an older template) fall\n * back to its defaults inside `encodePreset`.\n */\nexport async function presetFor(\n root: string,\n overrides: Partial<PresetConfig>,\n preset?: ShadcnPreset,\n): Promise<string> {\n const { encodePreset } = preset ?? (await loadPreset(root));\n const config = readComponentsConfig(root);\n const current: Partial<PresetConfig> = { style: config.style };\n if (config.baseColor) current.baseColor = config.baseColor;\n if (config.iconLibrary) current.iconLibrary = config.iconLibrary;\n if (config.menuColor) current.menuColor = config.menuColor;\n if (config.menuAccent) current.menuAccent = config.menuAccent;\n return encodePreset({ ...current, ...overrides });\n}\n\n/**\n * `shadcn-svelte apply --preset <code> --only <parts> --yes` through the\n * project's package manager. `theme` rewrites the token values in `:root` /\n * `.dark` and records the base color in `components.json`; `font` adds the\n * fontsource import, dependency and `--font-sans`. Both leave the rest of the\n * stylesheet alone but write it in the registry's formatting, so the file is\n * run through the project's prettier afterwards.\n */\nexport async function applyPreset(\n root: string,\n code: string,\n only: PresetPart[],\n runtime?: WriteResultRuntime,\n): Promise<void> {\n await executeCommand(\n root,\n \"execute\",\n [\"shadcn-svelte\", \"apply\", \"--preset\", code, \"--only\", ...only, \"--yes\"],\n runtime,\n );\n await formatPaths(root, [readComponentsConfig(root).cssPath]);\n}\n","import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n ApplyBaseColorOptions,\n ApplyColorsResult,\n ApplyThemeOptions,\n Component,\n ListComponentsOptions,\n ListComponentsResult,\n RegistryItem,\n SwitchStyleOptions,\n SwitchStyleResult,\n WriteResultRuntime,\n} from \"../core/types\";\nimport { InvalidArgumentError, RegistryUnavailableError } from \"../core/errors\";\nimport { getLogger } from \"../core/logger\";\nimport { fetchRegistryIndex, readComponentsConfig } from \"./registry\";\nimport {\n applyPreset,\n loadPreset,\n presetFor,\n STYLE_FONTS,\n type ShadcnPreset,\n} from \"./shadcn-preset\";\nimport {\n getAllCustomComponents,\n installComponents,\n installedComponents,\n installedPackagesFromProject,\n isCustomComponent,\n} from \"./write-result\";\n\nconst COMPONENTS_JSON = \"components.json\";\n\n/**\n * What a project has and what it could add: the ui directory, this package's\n * bundled components, and the registry index of the configured style. A\n * registry that cannot be read leaves the first two intact and says why.\n */\nexport async function listComponents(\n options: ListComponentsOptions,\n runtime?: WriteResultRuntime,\n): Promise<ListComponentsResult> {\n const { root } = options;\n const { style } = readComponentsConfig(root);\n const result: ListComponentsResult = {\n style,\n installed: installedComponents(root),\n custom: getAllCustomComponents(),\n registry: [],\n };\n try {\n result.registry = await fetchRegistryIndex(root, { runtime });\n } catch (error) {\n if (!(error instanceof RegistryUnavailableError)) throw error;\n result.registryUnavailable = error.message;\n }\n return result;\n}\n\nfunction assertOneOf(\n kind: string,\n value: string,\n choices: readonly string[],\n): void {\n if (choices.includes(value)) return;\n throw new InvalidArgumentError(\n `Unknown ${kind} \"${value}\". Choose one of: ${choices.join(\", \")}.`,\n );\n}\n\n/**\n * Rewrites `style` in `components.json` and nothing else, keeping the file's\n * indentation so the change reads as the one-line diff it is.\n */\nfunction writeStyle(root: string, style: string): void {\n const configPath = path.join(root, COMPONENTS_JSON);\n if (!existsSync(configPath)) {\n throw new Error(\n `${COMPONENTS_JSON} not found in ${root}; this does not look like a shadcn-svelte project.`,\n );\n }\n const text = readFileSync(configPath, \"utf8\");\n const config = JSON.parse(text) as Record<string, unknown>;\n config.style = style;\n const indent = text.includes(\"\\n\\t\") ? \"\\t\" : 2;\n writeFileSync(\n configPath,\n `${JSON.stringify(config, null, indent)}\\n`,\n \"utf8\",\n );\n}\n\nfunction registryUiNames(index: RegistryItem[]): Set<string> {\n return new Set(\n index\n .filter((item) => item.type === \"registry:ui\")\n .map((item) => item.name),\n );\n}\n\n/**\n * Moves a project to another shadcn-svelte style. Every installed component\n * the new style's registry also offers is re-added from there (their local\n * edits are lost, which is what `confirm` is for); this package's own\n * components and anything the registry does not know are left alone. The\n * style's preset font follows unless `font` is false.\n */\nexport async function switchStyle(\n options: SwitchStyleOptions,\n runtime?: WriteResultRuntime,\n): Promise<SwitchStyleResult> {\n const { root, style, font = true } = options;\n const logger = getLogger(options);\n const preset = await loadPreset(root);\n assertOneOf(\"style\", style, preset.PRESET_STYLES);\n\n const unchanged: SwitchStyleResult = {\n status: \"unchanged\",\n style,\n reinstalled: [],\n filesModified: [],\n packages: [],\n hints: [],\n };\n if (readComponentsConfig(root).style === style) {\n return unchanged;\n }\n\n const index = await fetchRegistryIndex(root, { style, runtime });\n const offered = registryUiNames(index);\n const reinstall = installedComponents(root).filter(\n (component) => offered.has(component) && !isCustomComponent(component),\n );\n\n if (options.confirm && !(await options.confirm(reinstall))) {\n return { ...unchanged, status: \"cancelled\" };\n }\n\n const packagesBefore = installedPackagesFromProject(root);\n writeStyle(root, style);\n const filesModified = [COMPONENTS_JSON];\n\n let reinstalled: Component[] = [];\n if (reinstall.length > 0) {\n const outcome = await installComponents(\n { root, components: reinstall, overwrite: true, logger },\n runtime,\n );\n reinstalled = outcome.installed;\n }\n\n const hints: string[] = [];\n if (font) {\n await applyStyleFont(\n root,\n style,\n preset,\n runtime,\n filesModified,\n hints,\n logger,\n );\n }\n\n const packages = [...installedPackagesFromProject(root)]\n .filter((name) => !packagesBefore.has(name))\n .sort();\n\n return {\n status: \"switched\",\n style,\n reinstalled,\n filesModified,\n packages,\n hints,\n };\n}\n\nconst FONTSOURCE_IMPORT =\n /@import\\s+[\"']@fontsource(?:-variable)?\\/([^\"']+)[\"']/g;\n\n/** The fontsource families a stylesheet imports, in order. */\nfunction fontsourceImports(css: string): string[] {\n return [...css.matchAll(FONTSOURCE_IMPORT)].map((match) => match[1]!);\n}\n\nasync function applyStyleFont(\n root: string,\n style: string,\n preset: ShadcnPreset,\n runtime: WriteResultRuntime | undefined,\n filesModified: string[],\n hints: string[],\n logger: ReturnType<typeof getLogger>,\n): Promise<void> {\n const fonts = STYLE_FONTS[style];\n if (!fonts) {\n logger.info(\n `No preset font is known for the ${style} style; leaving fonts unchanged.`,\n );\n return;\n }\n logger.info(`Applying the ${style} font (${fonts.font})`);\n const code = await presetFor(root, { style, ...fonts }, preset);\n await applyPreset(root, code, [\"font\"], runtime);\n\n const cssPath = readComponentsConfig(root).cssPath;\n filesModified.push(cssPath, \"package.json\");\n\n // `apply --only font` adds the new font beside whatever was imported before\n // and leaves it to the project to drop the old one; a font nobody uses\n // still ships to every visitor.\n const cssFile = path.join(root, cssPath);\n if (existsSync(cssFile)) {\n const wanted = new Set([fonts.font, fonts.fontHeading].filter(Boolean));\n const stale = fontsourceImports(readFileSync(cssFile, \"utf8\")).filter(\n (family) => !wanted.has(family),\n );\n if (stale.length > 0) {\n hints.push(\n `${cssPath} still imports ${stale.map((f) => `@fontsource-variable/${f}`).join(\", \")} from the previous style; remove the import and the package if nothing else uses them.`,\n );\n }\n }\n}\n\nasync function applyColors(\n root: string,\n overrides: { baseColor?: string; theme: string },\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n const preset = await loadPreset(root);\n if (overrides.baseColor) {\n assertOneOf(\n \"base color\",\n overrides.baseColor,\n preset.PRESET_BASE_COLOR_KEYS,\n );\n }\n assertOneOf(\"theme\", overrides.theme, preset.PRESET_THEME_KEYS);\n\n // Charts follow the accent, as shadcn-svelte's own presets do.\n const code = await presetFor(\n root,\n { ...overrides, chartColor: overrides.theme },\n preset,\n );\n await applyPreset(root, code, [\"theme\"], runtime);\n\n const config = readComponentsConfig(root);\n return {\n baseColor: config.baseColor ?? overrides.baseColor ?? \"\",\n theme: overrides.theme,\n filesModified: [config.cssPath, COMPONENTS_JSON],\n };\n}\n\n/**\n * Sets the base (gray) palette. The accent is reset to the base color as\n * well, since `components.json` records only the base color; `applyTheme`\n * puts an accent back on top.\n */\nexport async function applyBaseColor(\n options: ApplyBaseColorOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(\n options.root,\n { baseColor: options.color, theme: options.color },\n runtime,\n );\n}\n\n/** Sets the accent (primary, ring, charts) and keeps the base palette. */\nexport async function applyTheme(\n options: ApplyThemeOptions,\n runtime?: WriteResultRuntime,\n): Promise<ApplyColorsResult> {\n return applyColors(options.root, { theme: options.theme }, runtime);\n}\n"],"mappings":";;;;;;;;AA2CA,eAAsB,EAAW,GAAqC;CACpE,IAAI;CACJ,IAAI;EACF,IAAW,EAAc,EAAK,KAAK,GAAM,cAAc,CAAC,CAAC,CAAC,QACxD,sBACF;CACF,SAAS,GAAO;EACd,IAAM,IAAS,aAAiB,QAAQ,EAAM,UAAU,OAAO,CAAK;EACpE,MAAU,MACR,4CAA4C,EAAK,IAAI,EAAO,2EAE9D;CACF;CAIA,OAAO,MAHuB;;EACT,EAAc,CAAQ,CAAC,CAAC;;AAG/C;AAQA,IAAa,IAGT;CACF,MAAM,EAAE,MAAM,QAAQ;C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,CAAC,EAAO,IAAI,CAAM,CAChC;EACA,AAAI,EAAM,SAAS,KACjB,EAAM,KACJ,GAAG,EAAQ,iBAAiB,EAAM,KAAK,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,uFACvF;CAEJ;AACF;AAEA,eAAe,EACb,GACA,GACA,GAC4B;CAC5B,IAAM,IAAS,MAAM,EAAW,CAAI;CAgBpC,AAfI,EAAU,aACZ,EACE,cACA,EAAU,WACV,EAAO,sBACT,GAEF,EAAY,SAAS,EAAU,OAAO,EAAO,iBAAiB,GAQ9D,MAAM,EAAY,GAAM,MALL,EACjB,GACA;EAAE,GAAG;EAAW,YAAY,EAAU;CAAM,GAC5C,CACF,GAC8B,CAAC,OAAO,GAAG,CAAO;CAEhD,IAAM,IAAS,EAAqB,CAAI;CACxC,OAAO;EACL,WAAW,EAAO,aAAa,EAAU,aAAa;EACtD,OAAO,EAAU;EACjB,eAAe,CAAC,EAAO,SAAS,CAAe;CACjD;AACF;AAOA,eAAsB,EACpB,GACA,GAC4B;CAC5B,OAAO,EACL,EAAQ,MACR;EAAE,WAAW,EAAQ;EAAO,OAAO,EAAQ;CAAM,GACjD,CACF;AACF;AAGA,eAAsB,EACpB,GACA,GAC4B;CAC5B,OAAO,EAAY,EAAQ,MAAM,EAAE,OAAO,EAAQ,MAAM,GAAG,CAAO;AACpE"}
|
|
@@ -18,16 +18,16 @@ function n(n, r) {
|
|
|
18
18
|
}
|
|
19
19
|
return i;
|
|
20
20
|
}
|
|
21
|
-
function r(e, t
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return Object.
|
|
21
|
+
function r(e, t) {
|
|
22
|
+
let r = {};
|
|
23
|
+
for (let [n, i] of Object.entries(e)) n.startsWith(t) && (r[n] = i);
|
|
24
|
+
return n(r, t);
|
|
25
|
+
}
|
|
26
|
+
function i(e, t, i, a) {
|
|
27
|
+
let o = n(e, t);
|
|
28
|
+
return i && typeof a == "string" && a.length > 0 && Object.assign(o, r(i, `./variants/${a}/`)), Object.values(o).sort((e, t) => e.path.localeCompare(t.path));
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function a(e) {
|
|
31
31
|
return e.reduce((e, t) => (e.creates.push(...t.creates), e.modifies.push(...t.modifies), e.deletes.push(...t.deletes), e.components.push(...t.components), e.packages.push(...t.packages), e.collections.push(...t.collections), e.collectionPatches.push(...t.collectionPatches), e.collectionDrops.push(...t.collectionDrops), e), {
|
|
32
32
|
creates: [],
|
|
33
33
|
modifies: [],
|
|
@@ -40,6 +40,6 @@ function i(e) {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
//#endregion
|
|
43
|
-
export {
|
|
43
|
+
export { t as a, r as i, i as n, a as o, n as r, e as t };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=util-
|
|
45
|
+
//# sourceMappingURL=util-Bq_Mh6IQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util-Bq_Mh6IQ.js","names":[],"sources":["../../src/core/util.ts"],"sourcesContent":["import type { File, Result } from \"./types\";\n\nexport function appRelativePath(globKey: string, prefix: string): string {\n if (globKey.startsWith(prefix)) {\n return globKey.slice(prefix.length);\n }\n return globKey.replace(/^\\.\\//, \"\");\n}\n\nexport function languageFromPath(path: string): string {\n if (path.endsWith(\".svelte\")) return \"svelte\";\n if (path.endsWith(\".tsx\")) return \"ts\";\n if (path.endsWith(\".ts\")) return \"ts\";\n if (path.endsWith(\".jsx\")) return \"js\";\n if (path.endsWith(\".js\")) return \"js\";\n return \"text\";\n}\n\nexport function filesFromGlob(\n raw: Record<string, string>,\n prefix: string,\n): Record<string, File> {\n const files: Record<string, File> = {};\n for (const [key, content] of Object.entries(raw)) {\n const path = appRelativePath(key, prefix);\n files[path] = {\n path,\n language: languageFromPath(path),\n content,\n status: \"success\",\n };\n }\n return files;\n}\n\n/**\n * The subset of a glob map under `prefix`, keyed by app-relative path. Lets a\n * single `import.meta.glob(\"./variants/**\")` (or `./providers/**`) serve every\n * named subdirectory.\n */\nexport function filesUnderPrefix(\n raw: Record<string, string>,\n prefix: string,\n): Record<string, File> {\n const filtered: Record<string, string> = {};\n for (const [key, content] of Object.entries(raw)) {\n if (key.startsWith(prefix)) filtered[key] = content;\n }\n return filesFromGlob(filtered, prefix);\n}\n\n/**\n * Compose `creates/` files with an optional variant overlay from `variants/<variant>/`.\n * Files in the variant directory override files in creates at the same relative path.\n * Unknown or empty `variant` → no overlay applied.\n */\nexport function composeCreates(\n createsRaw: Record<string, string>,\n createsPrefix: string,\n variantsRaw?: Record<string, string>,\n variant?: string,\n): File[] {\n const files = filesFromGlob(createsRaw, createsPrefix);\n if (variantsRaw && typeof variant === \"string\" && variant.length > 0) {\n Object.assign(\n files,\n filesUnderPrefix(variantsRaw, `./variants/${variant}/`),\n );\n }\n return Object.values(files).sort((a, b) => a.path.localeCompare(b.path));\n}\n\nexport function mergeResults(results: Result[]) {\n return results.reduce(\n (acc, result) => {\n acc.creates.push(...result.creates);\n acc.modifies.push(...result.modifies);\n acc.deletes.push(...result.deletes);\n acc.components.push(...result.components);\n acc.packages.push(...result.packages);\n acc.collections.push(...result.collections);\n acc.collectionPatches.push(...result.collectionPatches);\n acc.collectionDrops.push(...result.collectionDrops);\n return acc;\n },\n {\n creates: [],\n modifies: [],\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result,\n );\n}\n"],"mappings":";AAEA,SAAgB,EAAgB,GAAiB,GAAwB;CAIvE,OAHI,EAAQ,WAAW,CAAM,IACpB,EAAQ,MAAM,EAAO,MAAM,IAE7B,EAAQ,QAAQ,SAAS,EAAE;AACpC;AAEA,SAAgB,EAAiB,GAAsB;CAMrD,OALI,EAAK,SAAS,SAAS,IAAU,WACjC,EAAK,SAAS,MAAM,KACpB,EAAK,SAAS,KAAK,IAAU,OAC7B,EAAK,SAAS,MAAM,K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AAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB,CACF;AACF"}
|
|
@@ -375,7 +375,7 @@ async function nt(e, t, n) {
|
|
|
375
375
|
collectionDrops: []
|
|
376
376
|
}, o = [];
|
|
377
377
|
if (e.collectionDrops.length > 0) {
|
|
378
|
-
let { dropCollections: n } = await import("./collections-
|
|
378
|
+
let { dropCollections: n } = await import("./collections-B-yQ1qt6.js");
|
|
379
379
|
o = await n(e.collectionDrops, t);
|
|
380
380
|
}
|
|
381
381
|
let s = await Y(t.root, e.packages, n, r), l = await $({
|
|
@@ -442,4 +442,4 @@ async function nt(e, t, n) {
|
|
|
442
442
|
//#endregion
|
|
443
443
|
export { q as executeCommand, Z as formatPaths, H as getAllCustomComponents, $ as installComponents, $e as installedComponents, J as installedPackagesFromProject, X as isCustomComponent, b as n, C as t, nt as writeResult };
|
|
444
444
|
|
|
445
|
-
//# sourceMappingURL=write-result-
|
|
445
|
+
//# sourceMappingURL=write-result-DgFUKxhP.js.map
|