@velastack/patterns 0.1.5 → 0.1.7
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/generate-3QOmCHGZ.js +90 -0
- package/dist/chunks/generate-3QOmCHGZ.js.map +1 -0
- package/dist/chunks/generate.runtime-B3IKmGyV.js +402 -0
- package/dist/chunks/generate.runtime-B3IKmGyV.js.map +1 -0
- package/dist/index.d.ts +173 -38
- package/dist/index.js +1535 -1420
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { t as e } from "./errors-D3Zy3wCg.js";
|
|
2
|
+
import { r as t } from "./util-Bk7aQQJR.js";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/patterns/enable/cms/generate.ts
|
|
5
|
+
var n = /* #__PURE__ */ Object.assign({
|
|
6
|
+
"./creates-backend/src/lib/server/cms.ts": "import { dataPath } from '@velastack/kit/server';\nimport { createCmsBackend } from '@velastack/cms/backend';\n\n/**\n * The CMS HTTP backend, mounted single-tenant at `/api/cms` by\n * `src/routes/api/cms/[...path]/+server.ts`.\n *\n * Same origin as the site, so there is no CORS to configure and the session\n * cookie is first-party. Editors sign in against the backend's own\n * `cms_editors` table — add one with `vela cms editor add <email>`.\n *\n * `dataPath` reads `VELA_DATA_DIR`, which `vela` sets wherever it runs the\n * app, so the database and uploads live in the data directory that outlives\n * a release rather than inside the build.\n */\nexport const cms = createCmsBackend({\n dbPath: dataPath('cms.sqlite'),\n uploadDir: dataPath('uploads')\n});\n",
|
|
7
|
+
"./creates-backend/src/routes/api/cms/[...path]/+server.ts": "import { cms } from '$lib/server/cms';\n\n// `fallback` catches every method, including OPTIONS. The backend does its own\n// sub-routing off `params.path`, so a new endpoint never touches this file.\nexport const prerender = false;\nexport const fallback = cms.handler;\n",
|
|
8
|
+
"./creates-backend/src/routes/uploads/[filename]/+server.ts": "import { cms } from '$lib/server/cms';\n\n// Uploads land in the data directory after the build, so no static handler\n// would find them. Media URLs written into content are root-relative\n// `/uploads/<file>`, which is what this route serves.\nexport const prerender = false;\nexport const GET = cms.serveUpload;\n"
|
|
9
|
+
}), r = "./creates-backend/", i = "/api/cms", a = "https://velastack.dev/v1/projects/<project>/cms";
|
|
10
|
+
function o(e) {
|
|
11
|
+
for (let t = 0; t < e.length; t++) {
|
|
12
|
+
let n = e[t];
|
|
13
|
+
if (n === "--endpoint") return e[t + 1];
|
|
14
|
+
if (n.startsWith("--endpoint=")) return n.slice(11);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function s(t) {
|
|
18
|
+
let n = (typeof t.input.endpoint == "string" ? t.input.endpoint : o(t.argv))?.trim().replace(/\/+$/, "");
|
|
19
|
+
if (n) {
|
|
20
|
+
if (!/^https?:\/\/\S+$/.test(n)) throw new e(`--endpoint must be the absolute URL of a hosted CMS, like ${a}; got ${n}`);
|
|
21
|
+
return {
|
|
22
|
+
endpoint: n,
|
|
23
|
+
local: !1
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (!t.features.backend) throw new e(`This site has no server to host the CMS backend. Point it at a hosted CMS instead: vela enable cms --endpoint ${a}`);
|
|
27
|
+
return {
|
|
28
|
+
endpoint: i,
|
|
29
|
+
local: !0
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function c(e, t) {
|
|
33
|
+
let n = ["import { apiAdapter, createCms } from '@velastack/cms/server';"];
|
|
34
|
+
t && n.push("import { locales } from '$locales/data';");
|
|
35
|
+
let r = e.local ? [
|
|
36
|
+
" * `/api/cms` is where `src/routes/api/cms/[...path]/+server.ts` mounts the",
|
|
37
|
+
" * backend. It is also the admin bar's default, so the endpoint is named here",
|
|
38
|
+
" * and nowhere else."
|
|
39
|
+
] : [
|
|
40
|
+
" * The CMS is hosted at this endpoint: the app reads published content from",
|
|
41
|
+
" * it and the admin bar signs in there. The same URL is given to the `cms()`",
|
|
42
|
+
" * plugin in vite.config.ts, which downloads media into the build."
|
|
43
|
+
], i = t ? [
|
|
44
|
+
" * The locales are the site's own, from wuchale, so the CMS supports exactly",
|
|
45
|
+
" * the languages the UI does; the first is the default that a missing",
|
|
46
|
+
" * translation falls back to."
|
|
47
|
+
] : [" * `locales` lists every locale the site supports; the first is the default", " * that a missing translation falls back to."];
|
|
48
|
+
return [
|
|
49
|
+
...n,
|
|
50
|
+
"",
|
|
51
|
+
"/**",
|
|
52
|
+
" * The CMS read path, called from the root `+layout.server.ts`.",
|
|
53
|
+
" *",
|
|
54
|
+
...r,
|
|
55
|
+
" *",
|
|
56
|
+
...i,
|
|
57
|
+
" */",
|
|
58
|
+
"export const { load: loadCms, generateEntries } = createCms({",
|
|
59
|
+
`\tadapter: apiAdapter({ endpoint: '${e.endpoint}' }),`,
|
|
60
|
+
`\tlocales: ${t ? "[...locales]" : "['en']"}`,
|
|
61
|
+
"});",
|
|
62
|
+
""
|
|
63
|
+
].join("\n");
|
|
64
|
+
}
|
|
65
|
+
async function l(e) {
|
|
66
|
+
let i = s(e), a = {};
|
|
67
|
+
return i.local && Object.assign(a, t(n, r)), a["src/lib/cms.ts"] = {
|
|
68
|
+
path: "src/lib/cms.ts",
|
|
69
|
+
language: "ts",
|
|
70
|
+
content: c(i, e.features.i18n),
|
|
71
|
+
status: "success"
|
|
72
|
+
}, {
|
|
73
|
+
creates: Object.values(a).sort((e, t) => e.path.localeCompare(t.path)),
|
|
74
|
+
modifies: [],
|
|
75
|
+
deletes: [],
|
|
76
|
+
components: [],
|
|
77
|
+
packages: i.local ? [
|
|
78
|
+
"@velastack/cms@^0.2.2",
|
|
79
|
+
"better-sqlite3",
|
|
80
|
+
"marked"
|
|
81
|
+
] : ["@velastack/cms@^0.2.2", "marked"],
|
|
82
|
+
collections: [],
|
|
83
|
+
collectionPatches: [],
|
|
84
|
+
collectionDrops: []
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { s as n, l as t };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=generate-3QOmCHGZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-3QOmCHGZ.js","names":[],"sources":["../../src/patterns/enable/cms/generate.ts"],"sourcesContent":["import type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { filesFromGlob } from \"../../../core/util\";\n\n// The backend, for an app that hosts the CMS itself: the SQLite-backed HTTP\n// API and the two routes that mount it and serve uploads.\nconst backendRaw = import.meta.glob<string>(\"./creates-backend/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\nconst BACKEND_PREFIX = \"./creates-backend/\";\n\n/** Where an app that hosts the backend itself mounts it. Also the admin bar's default. */\nexport const LOCAL_ENDPOINT = \"/api/cms\";\n\nexport const ENDPOINT_EXAMPLE =\n \"https://velastack.dev/v1/projects/<project>/cms\";\n\nexport interface CmsMode {\n /** What the read path and the admin bar talk to. */\n endpoint: string;\n /** Whether this app hosts the backend at `endpoint` itself. */\n local: boolean;\n}\n\n/** `--endpoint <url>` or `--endpoint=<url>`, for callers that hand flags through in argv. */\nfunction endpointFromArgv(argv: string[]): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n if (arg === \"--endpoint\") return argv[i + 1];\n if (arg.startsWith(\"--endpoint=\")) return arg.slice(\"--endpoint=\".length);\n }\n return undefined;\n}\n\n/**\n * Which of the two shapes to produce.\n *\n * An explicit `--endpoint` means a hosted CMS: the app only reads from it and\n * the admin bar signs in there, so no backend is installed. Without one, an\n * app with a server hosts the backend itself at `/api/cms`. A static site has\n * no server to host it, so there the endpoint is required.\n */\nexport function resolveMode(options: Options): CmsMode {\n const raw =\n typeof options.input.endpoint === \"string\"\n ? options.input.endpoint\n : endpointFromArgv(options.argv);\n const endpoint = raw?.trim().replace(/\\/+$/, \"\");\n\n if (endpoint) {\n if (!/^https?:\\/\\/\\S+$/.test(endpoint)) {\n throw new InvalidArgumentError(\n `--endpoint must be the absolute URL of a hosted CMS, like ${ENDPOINT_EXAMPLE}; got ${endpoint}`,\n );\n }\n return { endpoint, local: false };\n }\n\n if (!options.features.backend) {\n throw new InvalidArgumentError(\n \"This site has no server to host the CMS backend. \" +\n `Point it at a hosted CMS instead: vela enable cms --endpoint ${ENDPOINT_EXAMPLE}`,\n );\n }\n\n return { endpoint: LOCAL_ENDPOINT, local: true };\n}\n\n/** `$lib/cms.ts`: the read path, with the endpoint and locales bound. */\nfunction cmsLibSource(mode: CmsMode, i18n: boolean): string {\n const imports = [\n \"import { apiAdapter, createCms } from '@velastack/cms/server';\",\n ];\n if (i18n) imports.push(\"import { locales } from '$locales/data';\");\n\n const where = mode.local\n ? [\n \" * `/api/cms` is where `src/routes/api/cms/[...path]/+server.ts` mounts the\",\n \" * backend. It is also the admin bar's default, so the endpoint is named here\",\n \" * and nowhere else.\",\n ]\n : [\n \" * The CMS is hosted at this endpoint: the app reads published content from\",\n \" * it and the admin bar signs in there. The same URL is given to the `cms()`\",\n \" * plugin in vite.config.ts, which downloads media into the build.\",\n ];\n\n const which = i18n\n ? [\n \" * The locales are the site's own, from wuchale, so the CMS supports exactly\",\n \" * the languages the UI does; the first is the default that a missing\",\n \" * translation falls back to.\",\n ]\n : [\n \" * `locales` lists every locale the site supports; the first is the default\",\n \" * that a missing translation falls back to.\",\n ];\n\n return [\n ...imports,\n \"\",\n \"/**\",\n \" * The CMS read path, called from the root `+layout.server.ts`.\",\n \" *\",\n ...where,\n \" *\",\n ...which,\n \" */\",\n \"export const { load: loadCms, generateEntries } = createCms({\",\n `\\tadapter: apiAdapter({ endpoint: '${mode.endpoint}' }),`,\n `\\tlocales: ${i18n ? \"[...locales]\" : \"['en']\"}`,\n \"});\",\n \"\",\n ].join(\"\\n\");\n}\n\nexport async function generate(options: Options) {\n const mode = resolveMode(options);\n const creates: Record<string, File> = {};\n\n if (mode.local) {\n Object.assign(creates, filesFromGlob(backendRaw, BACKEND_PREFIX));\n }\n\n creates[\"src/lib/cms.ts\"] = {\n path: \"src/lib/cms.ts\",\n language: \"ts\",\n content: cmsLibSource(mode, options.features.i18n),\n status: \"success\",\n };\n\n const sortedCreates = Object.values(creates).sort((a, b) =>\n a.path.localeCompare(b.path),\n );\n\n // better-sqlite3 and marked are the package's optional peers, which npm\n // skips on install precisely because they are optional — so they have to be\n // named here. The backend needs the first; the root entry imports the\n // second statically, so <AdminBar /> cannot render without it.\n // 0.2.2 is the first release whose Vite plugin imports from the package\n // name rather than its own source tree; 0.2.1 breaks every consumer route.\n const packages = mode.local\n ? [\"@velastack/cms@^0.2.2\", \"better-sqlite3\", \"marked\"]\n : [\"@velastack/cms@^0.2.2\", \"marked\"];\n\n return {\n creates: sortedCreates,\n modifies: [],\n deletes: [],\n components: [],\n packages,\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n"],"mappings":";;;;AAMA,IAAM,IAAa,uBAAA,OAAA;CAAA,2CAAA;CAAA,6DAAA;CAAA,8DAAA;AAIlB,CAAA,GAEK,IAAiB,sBAGV,IAAiB,YAEjB,IACX;AAUF,SAAS,EAAiB,GAAoC;CAC5D,KAAK,IAAI,IAAI,GAAG,IAAI,EAAK,QAAQ,KAAK;EACpC,IAAM,IAAM,EAAK;EACjB,IAAI,MAAQ,cAAc,OAAO,EAAK,IAAI;EAC1C,IAAI,EAAI,WAAW,aAAa,GAAG,OAAO,EAAI,MAAM,EAAoB;CAC1E;AAEF;AAUA,SAAgB,EAAY,GAA2B;CAKrD,IAAM,KAHJ,OAAO,EAAQ,MAAM,YAAa,WAC9B,EAAQ,MAAM,WACd,EAAiB,EAAQ,IAAI,EAAA,EACb,KAAK,CAAC,CAAC,QAAQ,QAAQ,EAAE;CAE/C,IAAI,GAAU;EACZ,IAAI,CAAC,mBAAmB,KAAK,CAAQ,GACnC,MAAM,IAAI,EACR,6DAA6D,EAAiB,QAAQ,GACxF;EAEF,OAAO;GAAE;GAAU,OAAO;EAAM;CAClC;CAEA,IAAI,CAAC,EAAQ,SAAS,SACpB,MAAM,IAAI,EACR,iHACkE,GACpE;CAGF,OAAO;EAAE,UAAU;EAAgB,OAAO;CAAK;AACjD;AAGA,SAAS,EAAa,GAAe,GAAuB;CAC1D,IAAM,IAAU,CACd,gEACF;CACA,AAAI,KAAM,EAAQ,KAAK,0CAA0C;CAEjE,IAAM,IAAQ,EAAK,QACf;EACE;EACA;EACA;CACF,IACA;EACE;EACA;EACA;CACF,GAEE,IAAQ,IACV;EACE;EACA;EACA;CACF,IACA,CACE,+EACA,8CACF;CAEJ,OAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACA,GAAG;EACH;EACA,GAAG;EACH;EACA;EACA,sCAAsC,EAAK,SAAS;EACpD,cAAc,IAAO,iBAAiB;EACtC;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,eAAsB,EAAS,GAAkB;CAC/C,IAAM,IAAO,EAAY,CAAO,GAC1B,IAAgC,CAAC;CA2BvC,OAzBI,EAAK,SACP,OAAO,OAAO,GAAS,EAAc,GAAY,CAAc,CAAC,GAGlE,EAAQ,oBAAoB;EAC1B,MAAM;EACN,UAAU;EACV,SAAS,EAAa,GAAM,EAAQ,SAAS,IAAI;EACjD,QAAQ;CACV,GAgBO;EACL,SAfoB,OAAO,OAAO,CAAO,CAAC,CAAC,MAAM,GAAG,MACpD,EAAE,KAAK,cAAc,EAAE,IAAI,CAclB;EACT,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UATe,EAAK,QAClB;GAAC;GAAyB;GAAkB;EAAQ,IACpD,CAAC,yBAAyB,QAAQ;EAQpC,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { t as e } from "./dedent-Gq6Krl4n.js";
|
|
2
|
+
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
+
import { n } from "./generate-3QOmCHGZ.js";
|
|
4
|
+
import { modifyOutcomeToFile as r } from "./modify-file-PVKmDJHk.js";
|
|
5
|
+
import { a as i, n as a, o } from "./ts-morph-helpers-Bk82Z2n7.js";
|
|
6
|
+
import { a as s, t as c } from "./config-target-DOi8kI_f.js";
|
|
7
|
+
import l from "node:path";
|
|
8
|
+
import u from "node:fs";
|
|
9
|
+
import { Node as d, Project as f, QuoteKind as p, SyntaxKind as m } from "ts-morph";
|
|
10
|
+
//#region src/patterns/enable/cms/modifies/vite-config.ts
|
|
11
|
+
var h = [
|
|
12
|
+
"Add the CMS plugin to your Vite config, ahead of sveltekit():",
|
|
13
|
+
"",
|
|
14
|
+
"import { cms } from '@velastack/cms/vite';",
|
|
15
|
+
"",
|
|
16
|
+
"export default defineConfig({",
|
|
17
|
+
" plugins: [cms(), sveltekit(), /* ...existing plugins */],",
|
|
18
|
+
"});"
|
|
19
|
+
].join("\n"), g = [
|
|
20
|
+
"Create a Vite config with the CMS plugin ahead of sveltekit():",
|
|
21
|
+
"",
|
|
22
|
+
"import { defineConfig } from 'vite';",
|
|
23
|
+
"import { sveltekit } from '@sveltejs/kit/vite';",
|
|
24
|
+
"import { cms } from '@velastack/cms/vite';",
|
|
25
|
+
"",
|
|
26
|
+
"export default defineConfig({",
|
|
27
|
+
" plugins: [cms(), sveltekit()],",
|
|
28
|
+
"});"
|
|
29
|
+
].join("\n");
|
|
30
|
+
function _(e) {
|
|
31
|
+
return e.replace(/\s/g, "");
|
|
32
|
+
}
|
|
33
|
+
function v(e, t = "") {
|
|
34
|
+
let n = `cms(${t})`;
|
|
35
|
+
if (!u.existsSync(e)) return {
|
|
36
|
+
status: "not-found",
|
|
37
|
+
message: g
|
|
38
|
+
};
|
|
39
|
+
let r = new f({
|
|
40
|
+
compilerOptions: { allowJs: !0 },
|
|
41
|
+
manipulationSettings: { quoteKind: p.Single }
|
|
42
|
+
}).addSourceFileAtPath(e), i = !1, a = !1;
|
|
43
|
+
r.getImportDeclarations().some((e) => e.getModuleSpecifierValue() === "@velastack/cms/vite") || (r.insertImportDeclaration(0, {
|
|
44
|
+
namedImports: ["cms"],
|
|
45
|
+
moduleSpecifier: "@velastack/cms/vite"
|
|
46
|
+
}), i = !0);
|
|
47
|
+
let o = r.getDescendantsOfKind(m.CallExpression).find((e) => e.getExpression().getText() === "defineConfig")?.getArguments()?.[0], s = o?.getKind() === m.ObjectLiteralExpression ? o : null;
|
|
48
|
+
if (!s) a = !0;
|
|
49
|
+
else {
|
|
50
|
+
let e = s.getProperty("plugins");
|
|
51
|
+
if (!e) s.addPropertyAssignment({
|
|
52
|
+
name: "plugins",
|
|
53
|
+
initializer: `[${n}]`
|
|
54
|
+
}), i = !0;
|
|
55
|
+
else if (e.getKind() !== m.PropertyAssignment) a = !0;
|
|
56
|
+
else {
|
|
57
|
+
let t = e.getInitializer();
|
|
58
|
+
if (!t) e.setInitializer(`[${n}]`), i = !0;
|
|
59
|
+
else if (t.getKind() !== m.ArrayLiteralExpression) a = !0;
|
|
60
|
+
else {
|
|
61
|
+
let e = t, r = e.getElements();
|
|
62
|
+
if (!r.some((e) => _(e.getText()).startsWith("cms("))) {
|
|
63
|
+
let t = r.findIndex((e) => _(e.getText()).startsWith("sveltekit("));
|
|
64
|
+
e.insertElement(t === -1 ? 0 : t, n), i = !0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return i && (r.formatText(), r.saveSync()), a ? {
|
|
70
|
+
status: "failed",
|
|
71
|
+
message: h
|
|
72
|
+
} : {
|
|
73
|
+
status: "success",
|
|
74
|
+
changed: i
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/patterns/enable/cms/modifies/load-function.ts
|
|
79
|
+
function y() {
|
|
80
|
+
return new f({
|
|
81
|
+
compilerOptions: { allowJs: !0 },
|
|
82
|
+
manipulationSettings: { quoteKind: p.Single }
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function b(e, t, n) {
|
|
86
|
+
let r = e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t);
|
|
87
|
+
if (!r) {
|
|
88
|
+
e.addImportDeclaration({
|
|
89
|
+
namedImports: n,
|
|
90
|
+
moduleSpecifier: t
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (let e of n) r.getNamedImports().some((t) => t.getName() === e) || r.addNamedImport(e);
|
|
95
|
+
}
|
|
96
|
+
function x(e, t) {
|
|
97
|
+
t.namedImports?.length && b(e, t.moduleSpecifier, t.namedImports), !e.getImportDeclarations().find((e) => e.getModuleSpecifierValue() === t.moduleSpecifier) && e.addImportDeclaration({
|
|
98
|
+
moduleSpecifier: t.moduleSpecifier,
|
|
99
|
+
defaultImport: t.defaultImport,
|
|
100
|
+
namespaceImport: t.namespaceImport
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function S(e) {
|
|
104
|
+
if (d.isArrowFunction(e) || d.isFunctionExpression(e)) return e;
|
|
105
|
+
if (d.isParenthesizedExpression(e) || d.isAsExpression(e) || d.isSatisfiesExpression(e)) return S(e.getExpression());
|
|
106
|
+
if (d.isCallExpression(e)) for (let t of e.getArguments()) {
|
|
107
|
+
let e = S(t);
|
|
108
|
+
if (e) return e;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
function C(e) {
|
|
113
|
+
let t = e.getFunction("load");
|
|
114
|
+
if (t) return t.isExported() ? t : null;
|
|
115
|
+
let n = e.getVariableDeclaration("load");
|
|
116
|
+
if (!n || !n.getVariableStatement()?.isExported()) return null;
|
|
117
|
+
let r = n.getInitializer();
|
|
118
|
+
return r ? S(r) : null;
|
|
119
|
+
}
|
|
120
|
+
function w(e) {
|
|
121
|
+
return d.isArrowFunction(e) || d.isFunctionExpression(e) || d.isFunctionDeclaration(e) || d.isMethodDeclaration(e);
|
|
122
|
+
}
|
|
123
|
+
function T(e, t) {
|
|
124
|
+
let n = t.getStatements(), r = n[n.length - 1];
|
|
125
|
+
return !r || !d.isReturnStatement(r) || t.getDescendantsOfKind(m.ReturnStatement).filter((t) => t.getFirstAncestor(w) === e).length !== 1 ? null : r;
|
|
126
|
+
}
|
|
127
|
+
function E(e) {
|
|
128
|
+
let t = e.getExpression();
|
|
129
|
+
for (; t && d.isParenthesizedExpression(t);) t = t.getExpression();
|
|
130
|
+
return !t || !d.isObjectLiteralExpression(t) ? null : t;
|
|
131
|
+
}
|
|
132
|
+
function D(e, t) {
|
|
133
|
+
return e.getProperties().some((e) => d.isPropertyAssignment(e) || d.isShorthandPropertyAssignment(e) ? e.getName() === t : !1);
|
|
134
|
+
}
|
|
135
|
+
function O(e, t) {
|
|
136
|
+
return e.getProperties().some((e) => d.isSpreadAssignment(e) && e.getExpression().getText() === t);
|
|
137
|
+
}
|
|
138
|
+
function k(e) {
|
|
139
|
+
let t = e.getParameters();
|
|
140
|
+
if (t.length === 0) return { kind: "none" };
|
|
141
|
+
if (t.length > 1) return { kind: "unsupported" };
|
|
142
|
+
let n = t[0];
|
|
143
|
+
if (n.getInitializer() || n.isRestParameter()) return { kind: "unsupported" };
|
|
144
|
+
let r = n.getNameNode();
|
|
145
|
+
return d.isIdentifier(r) ? {
|
|
146
|
+
kind: "identifier",
|
|
147
|
+
name: r.getText(),
|
|
148
|
+
param: n
|
|
149
|
+
} : d.isObjectBindingPattern(r) ? {
|
|
150
|
+
kind: "binding",
|
|
151
|
+
pattern: r,
|
|
152
|
+
param: n
|
|
153
|
+
} : { kind: "unsupported" };
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/patterns/enable/cms/modifies/layout.server.ts
|
|
157
|
+
var A = { expression: () => "'en'" }, j = {
|
|
158
|
+
expression: (e) => `getLocale(${e}.url)`,
|
|
159
|
+
imports: [{
|
|
160
|
+
namedImports: ["getLocale"],
|
|
161
|
+
moduleSpecifier: "$locales/main.url"
|
|
162
|
+
}]
|
|
163
|
+
};
|
|
164
|
+
function M(t, n) {
|
|
165
|
+
return e`
|
|
166
|
+
const { cms, notFound, gone, redirectTo } = await loadCms(${t}, { locale: ${n} });
|
|
167
|
+
if (redirectTo) redirect(308, redirectTo);
|
|
168
|
+
if (gone) error(410, 'Gone');
|
|
169
|
+
if (notFound) error(404, 'Not found');
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
function N(e) {
|
|
173
|
+
let t = [];
|
|
174
|
+
return e.defaultImport && t.push(e.defaultImport), e.namespaceImport && t.push(`* as ${e.namespaceImport}`), e.namedImports?.length && t.push(`{ ${e.namedImports.join(", ")} }`), `import ${t.join(", ")} from '${e.moduleSpecifier}';`;
|
|
175
|
+
}
|
|
176
|
+
function P(t) {
|
|
177
|
+
let n = [
|
|
178
|
+
"import { error, redirect } from '@sveltejs/kit';",
|
|
179
|
+
"import { loadCms } from '$lib/cms';",
|
|
180
|
+
...(t.imports ?? []).map(N),
|
|
181
|
+
"import type { LayoutServerLoad } from './$types';"
|
|
182
|
+
].join("\n"), r = M("event", t.expression("event")).split("\n").join("\n ");
|
|
183
|
+
return e`
|
|
184
|
+
${n}
|
|
185
|
+
|
|
186
|
+
export const load: LayoutServerLoad = async (event) => {
|
|
187
|
+
${r}
|
|
188
|
+
|
|
189
|
+
return { cms };
|
|
190
|
+
};
|
|
191
|
+
`.concat("\n");
|
|
192
|
+
}
|
|
193
|
+
var F = [
|
|
194
|
+
"Call loadCms from the root +layout.server.ts load and return `cms`:",
|
|
195
|
+
"",
|
|
196
|
+
P(A).trimEnd(),
|
|
197
|
+
"",
|
|
198
|
+
"loadCms needs the whole event, so a destructured parameter has to become",
|
|
199
|
+
"`event` with the destructuring moved into the body."
|
|
200
|
+
].join("\n");
|
|
201
|
+
function I(e, t = A) {
|
|
202
|
+
if (!u.existsSync(e)) return u.mkdirSync(l.dirname(e), { recursive: !0 }), u.writeFileSync(e, P(t)), {
|
|
203
|
+
status: "success",
|
|
204
|
+
changed: !0
|
|
205
|
+
};
|
|
206
|
+
if (u.readFileSync(e, "utf8").includes("loadCms(")) return {
|
|
207
|
+
status: "success",
|
|
208
|
+
changed: !1
|
|
209
|
+
};
|
|
210
|
+
let n = y().addSourceFileAtPath(e), r = C(n);
|
|
211
|
+
if (!r) return {
|
|
212
|
+
status: "failed",
|
|
213
|
+
message: F
|
|
214
|
+
};
|
|
215
|
+
let i = r.getBody();
|
|
216
|
+
if (!i || !d.isBlock(i)) return {
|
|
217
|
+
status: "failed",
|
|
218
|
+
message: F
|
|
219
|
+
};
|
|
220
|
+
let a = k(r);
|
|
221
|
+
if (a.kind === "unsupported") return {
|
|
222
|
+
status: "failed",
|
|
223
|
+
message: F
|
|
224
|
+
};
|
|
225
|
+
let o = T(r, i), s = o && E(o);
|
|
226
|
+
if (!o || !s) return {
|
|
227
|
+
status: "failed",
|
|
228
|
+
message: F
|
|
229
|
+
};
|
|
230
|
+
let c = a.kind === "identifier" ? a.name : "event";
|
|
231
|
+
if (!D(s, "cms")) {
|
|
232
|
+
let e = s.getProperties().findIndex((e) => d.isSpreadAssignment(e));
|
|
233
|
+
e === -1 ? s.addShorthandPropertyAssignment({ name: "cms" }) : s.insertShorthandPropertyAssignment(e, { name: "cms" });
|
|
234
|
+
}
|
|
235
|
+
let f = i.getStatements().indexOf(o);
|
|
236
|
+
if (i.insertStatements(f, `\n${M(c, t.expression(c))}\n`), a.kind === "binding") {
|
|
237
|
+
let e = a.pattern.getText();
|
|
238
|
+
i.insertStatements(0, `const ${e} = ${c};`);
|
|
239
|
+
let t = a.param.getTypeNode()?.getText();
|
|
240
|
+
a.param.replaceWithText(t ? `${c}: ${t}` : c);
|
|
241
|
+
} else a.kind === "none" && r.addParameter({ name: c });
|
|
242
|
+
r.isAsync() || r.setIsAsync(!0), b(n, "@sveltejs/kit", ["error", "redirect"]), b(n, "$lib/cms", ["loadCms"]);
|
|
243
|
+
for (let e of t.imports ?? []) x(n, e);
|
|
244
|
+
return n.formatText(), n.saveSync(), {
|
|
245
|
+
status: "success",
|
|
246
|
+
changed: !0
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/patterns/enable/cms/modifies/layout.ts
|
|
251
|
+
var L = e`
|
|
252
|
+
Forward the server load's data through the root +layout.ts, so \`cms\` reaches
|
|
253
|
+
the page:
|
|
254
|
+
|
|
255
|
+
export const load = async ({ url, data }) => {
|
|
256
|
+
// ...existing code...
|
|
257
|
+
return { ...data, /* existing keys */ };
|
|
258
|
+
};
|
|
259
|
+
`;
|
|
260
|
+
function R(e) {
|
|
261
|
+
if (!u.existsSync(e)) return {
|
|
262
|
+
status: "success",
|
|
263
|
+
changed: !1
|
|
264
|
+
};
|
|
265
|
+
let t = y().addSourceFileAtPath(e), n = C(t);
|
|
266
|
+
if (!n) return {
|
|
267
|
+
status: "success",
|
|
268
|
+
changed: !1
|
|
269
|
+
};
|
|
270
|
+
let r = n.getBody();
|
|
271
|
+
if (!r || !d.isBlock(r)) return {
|
|
272
|
+
status: "failed",
|
|
273
|
+
message: L
|
|
274
|
+
};
|
|
275
|
+
let i = k(n);
|
|
276
|
+
if (i.kind === "unsupported") return {
|
|
277
|
+
status: "failed",
|
|
278
|
+
message: L
|
|
279
|
+
};
|
|
280
|
+
let a = T(n, r);
|
|
281
|
+
if (!a) return {
|
|
282
|
+
status: "failed",
|
|
283
|
+
message: L
|
|
284
|
+
};
|
|
285
|
+
let o = i.kind === "identifier" ? `${i.name}.data` : "data", s = a.getExpression();
|
|
286
|
+
if (s && s.getText() === o) return {
|
|
287
|
+
status: "success",
|
|
288
|
+
changed: !1
|
|
289
|
+
};
|
|
290
|
+
let c = E(a);
|
|
291
|
+
if (!c) return {
|
|
292
|
+
status: "failed",
|
|
293
|
+
message: L
|
|
294
|
+
};
|
|
295
|
+
if (O(c, o)) return {
|
|
296
|
+
status: "success",
|
|
297
|
+
changed: !1
|
|
298
|
+
};
|
|
299
|
+
if (c.insertSpreadAssignment(0, { expression: o }), i.kind === "binding") {
|
|
300
|
+
if (!i.pattern.getElements().some((e) => e.getName() === "data")) {
|
|
301
|
+
let e = i.pattern.getText();
|
|
302
|
+
i.pattern.replaceWithText(e.replace(/^\{\s*/, "{ data, "));
|
|
303
|
+
}
|
|
304
|
+
} else i.kind === "none" && n.addParameter({ name: "{ data }" });
|
|
305
|
+
return t.formatText(), t.saveSync(), {
|
|
306
|
+
status: "success",
|
|
307
|
+
changed: !0
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/patterns/enable/cms/modifies/layout.svelte.ts
|
|
312
|
+
var z = e`
|
|
313
|
+
import { AdminBar } from '@velastack/cms';
|
|
314
|
+
`, B = "\n<AdminBar />\n", V = [
|
|
315
|
+
"Create the root src/routes/+layout.svelte and mount <AdminBar /> inside it.",
|
|
316
|
+
"",
|
|
317
|
+
"Import for the <script> tag:",
|
|
318
|
+
"",
|
|
319
|
+
z,
|
|
320
|
+
"",
|
|
321
|
+
"Markup to add at the top level of the layout:",
|
|
322
|
+
B.trim()
|
|
323
|
+
].join("\n"), H = [
|
|
324
|
+
"Mount <AdminBar /> in the root src/routes/+layout.svelte.",
|
|
325
|
+
"",
|
|
326
|
+
"Import for a <script lang=\"ts\"> tag:",
|
|
327
|
+
"",
|
|
328
|
+
z,
|
|
329
|
+
"",
|
|
330
|
+
"Markup to add at the top level of the layout:",
|
|
331
|
+
B.trim()
|
|
332
|
+
].join("\n");
|
|
333
|
+
function U(e) {
|
|
334
|
+
if (!u.existsSync(e)) return {
|
|
335
|
+
status: "not-found",
|
|
336
|
+
message: V
|
|
337
|
+
};
|
|
338
|
+
let t = o.fromPath(e);
|
|
339
|
+
return t.hasElement("AdminBar") ? {
|
|
340
|
+
status: "success",
|
|
341
|
+
changed: !1
|
|
342
|
+
} : t.getScript() ? (t.modifyScript((e) => {
|
|
343
|
+
let { source: t } = i(e, (e) => {
|
|
344
|
+
a(e, [{
|
|
345
|
+
namedImports: ["AdminBar"],
|
|
346
|
+
moduleSpecifier: "@velastack/cms"
|
|
347
|
+
}]);
|
|
348
|
+
});
|
|
349
|
+
return t;
|
|
350
|
+
}), t.appendMarkup(B), t.writeTo(e), {
|
|
351
|
+
status: "success",
|
|
352
|
+
changed: t.hasChanged()
|
|
353
|
+
}) : {
|
|
354
|
+
status: "failed",
|
|
355
|
+
message: H
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/patterns/enable/cms/generate.runtime.ts
|
|
360
|
+
function W(e, t) {
|
|
361
|
+
return e.filter((e) => !u.existsSync(l.join(t, e.path)));
|
|
362
|
+
}
|
|
363
|
+
function G(e) {
|
|
364
|
+
let t = l.join(e, "wuchale.config.js");
|
|
365
|
+
if (!u.existsSync(t)) return null;
|
|
366
|
+
let n = u.readFileSync(t, "utf8").match(/locales:\s*\[([^\]]*)\]/);
|
|
367
|
+
if (!n) return null;
|
|
368
|
+
let r = [...n[1].matchAll(/['"]([^'"]+)['"]/g)].map((e) => e[1]);
|
|
369
|
+
return r.length > 0 ? r : null;
|
|
370
|
+
}
|
|
371
|
+
function K(e, t) {
|
|
372
|
+
if (e.local) return "";
|
|
373
|
+
let n = t.map((e) => `'${e}'`).join(", ");
|
|
374
|
+
return `{ endpoint: '${e.endpoint}', locales: [${n}] }`;
|
|
375
|
+
}
|
|
376
|
+
async function q(e) {
|
|
377
|
+
let i = t(e), a = [], o = n(e), u = e.features.i18n, d = (e) => {
|
|
378
|
+
e && a.push(e);
|
|
379
|
+
};
|
|
380
|
+
i.info("Modifying vite.config");
|
|
381
|
+
let f = s(e.root, c) ?? l.join(e.root, c[0]), p = u && G(e.root) || ["en"];
|
|
382
|
+
d(r(f, v(f, K(o, p)))), i.info("Modifying src/routes/+layout.server.ts");
|
|
383
|
+
let m = l.join(e.root, "src", "routes", "+layout.server.ts");
|
|
384
|
+
d(r(m, I(m, u ? j : A))), i.info("Modifying src/routes/+layout.ts");
|
|
385
|
+
let h = l.join(e.root, "src", "routes", "+layout.ts");
|
|
386
|
+
d(r(h, R(h))), i.info("Modifying src/routes/+layout.svelte");
|
|
387
|
+
let g = l.join(e.root, "src", "routes", "+layout.svelte");
|
|
388
|
+
return d(r(g, U(g))), {
|
|
389
|
+
creates: [],
|
|
390
|
+
modifies: a,
|
|
391
|
+
deletes: [],
|
|
392
|
+
components: [],
|
|
393
|
+
packages: [],
|
|
394
|
+
collections: [],
|
|
395
|
+
collectionPatches: [],
|
|
396
|
+
collectionDrops: []
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
export { q as generate, W as keepMissing };
|
|
401
|
+
|
|
402
|
+
//# sourceMappingURL=generate.runtime-B3IKmGyV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-B3IKmGyV.js","names":[],"sources":["../../src/patterns/enable/cms/modifies/vite-config.ts","../../src/patterns/enable/cms/modifies/load-function.ts","../../src/patterns/enable/cms/modifies/layout.server.ts","../../src/patterns/enable/cms/modifies/layout.ts","../../src/patterns/enable/cms/modifies/layout.svelte.ts","../../src/patterns/enable/cms/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport {\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrayLiteralExpression,\n type ObjectLiteralExpression,\n type PropertyAssignment,\n} from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst FAILURE_HINT = [\n \"Add the CMS plugin to your Vite config, ahead of sveltekit():\",\n \"\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit(), /* ...existing plugins */],\",\n \"});\",\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create a Vite config with the CMS plugin ahead of sveltekit():\",\n \"\",\n \"import { defineConfig } from 'vite';\",\n \"import { sveltekit } from '@sveltejs/kit/vite';\",\n \"import { cms } from '@velastack/cms/vite';\",\n \"\",\n \"export default defineConfig({\",\n \" plugins: [cms(), sveltekit()],\",\n \"});\",\n].join(\"\\n\");\n\nfunction elementName(text: string): string {\n return text.replace(/\\s/g, \"\");\n}\n\n/**\n * Registers `cms(...)` from `@velastack/cms/vite` in the Vite plugin list, just\n * ahead of `sveltekit()`. Only the plugin array is touched, so the inline\n * `sveltekit({ ... })` shape the templates use is left alone.\n */\nexport function modifyViteConfig(\n viteConfigPath: string,\n pluginArgs = \"\",\n): ModifyOutcome {\n const call = `cms(${pluginArgs})`;\n if (!fs.existsSync(viteConfigPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const project = new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n const sourceFile = project.addSourceFileAtPath(viteConfigPath);\n\n let changed = false;\n let failed = false;\n\n const hasImport = sourceFile\n .getImportDeclarations()\n .some((d) => d.getModuleSpecifierValue() === \"@velastack/cms/vite\");\n\n if (!hasImport) {\n sourceFile.insertImportDeclaration(0, {\n namedImports: [\"cms\"],\n moduleSpecifier: \"@velastack/cms/vite\",\n });\n changed = true;\n }\n\n const defineConfigCall = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"defineConfig\");\n\n const configArg = defineConfigCall?.getArguments()?.[0];\n const configObj =\n configArg?.getKind() === SyntaxKind.ObjectLiteralExpression\n ? (configArg as ObjectLiteralExpression)\n : null;\n\n if (!configObj) {\n failed = true;\n } else {\n const pluginsProp = configObj.getProperty(\"plugins\");\n if (!pluginsProp) {\n configObj.addPropertyAssignment({\n name: \"plugins\",\n initializer: `[${call}]`,\n });\n changed = true;\n } else if (pluginsProp.getKind() !== SyntaxKind.PropertyAssignment) {\n failed = true;\n } else {\n const pluginsInit = (pluginsProp as PropertyAssignment).getInitializer();\n\n if (!pluginsInit) {\n (pluginsProp as PropertyAssignment).setInitializer(`[${call}]`);\n changed = true;\n } else if (pluginsInit.getKind() !== SyntaxKind.ArrayLiteralExpression) {\n failed = true;\n } else {\n const arr = pluginsInit as ArrayLiteralExpression;\n const elements = arr.getElements();\n const hasCms = elements.some((el) =>\n elementName(el.getText()).startsWith(\"cms(\"),\n );\n\n if (!hasCms) {\n const sveltekitIndex = elements.findIndex((el) =>\n elementName(el.getText()).startsWith(\"sveltekit(\"),\n );\n arr.insertElement(sveltekitIndex === -1 ? 0 : sveltekitIndex, call);\n changed = true;\n }\n }\n }\n }\n\n if (changed) {\n sourceFile.formatText();\n sourceFile.saveSync();\n }\n\n if (failed) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n return { status: \"success\", changed };\n}\n","import {\n Node,\n Project,\n QuoteKind,\n SyntaxKind,\n type ArrowFunction,\n type Block,\n type FunctionDeclaration,\n type FunctionExpression,\n type ObjectLiteralExpression,\n type ParameterDeclaration,\n type ReturnStatement,\n type SourceFile,\n} from \"ts-morph\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\n\n/**\n * What the two layout modifiers have in common: finding a SvelteKit `load`,\n * working out how it receives its event, and locating the object it returns.\n */\n\nexport type LoadFunction =\n ArrowFunction | FunctionExpression | FunctionDeclaration;\n\nexport function newProject(): Project {\n return new Project({\n compilerOptions: { allowJs: true },\n manipulationSettings: { quoteKind: QuoteKind.Single },\n });\n}\n\nexport function ensureNamedImports(\n sourceFile: SourceFile,\n moduleSpecifier: string,\n names: string[],\n) {\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === moduleSpecifier);\n if (!existing) {\n sourceFile.addImportDeclaration({ namedImports: names, moduleSpecifier });\n return;\n }\n for (const name of names) {\n const has = existing.getNamedImports().some((ni) => ni.getName() === name);\n if (!has) existing.addNamedImport(name);\n }\n}\n\nexport function ensureImportSpec(sourceFile: SourceFile, spec: ImportSpec) {\n if (spec.namedImports?.length) {\n ensureNamedImports(sourceFile, spec.moduleSpecifier, spec.namedImports);\n }\n const existing = sourceFile\n .getImportDeclarations()\n .find((d) => d.getModuleSpecifierValue() === spec.moduleSpecifier);\n if (existing) return;\n sourceFile.addImportDeclaration({\n moduleSpecifier: spec.moduleSpecifier,\n defaultImport: spec.defaultImport,\n namespaceImport: spec.namespaceImport,\n });\n}\n\n/** Peel wrappers (`loadFlash(fn)`, `(fn)`, `fn satisfies X`) down to the function. */\nfunction unwrapFunction(node: Node): ArrowFunction | FunctionExpression | null {\n if (Node.isArrowFunction(node) || Node.isFunctionExpression(node)) {\n return node;\n }\n if (\n Node.isParenthesizedExpression(node) ||\n Node.isAsExpression(node) ||\n Node.isSatisfiesExpression(node)\n ) {\n return unwrapFunction(node.getExpression());\n }\n if (Node.isCallExpression(node)) {\n for (const arg of node.getArguments()) {\n const fn = unwrapFunction(arg);\n if (fn) return fn;\n }\n }\n return null;\n}\n\n/** The exported `load`, whether declared as a function or wrapped in a const. */\nexport function findLoadFunction(sourceFile: SourceFile): LoadFunction | null {\n const declaration = sourceFile.getFunction(\"load\");\n if (declaration) {\n return declaration.isExported() ? declaration : null;\n }\n\n const variable = sourceFile.getVariableDeclaration(\"load\");\n if (!variable) return null;\n if (!variable.getVariableStatement()?.isExported()) return null;\n\n const initializer = variable.getInitializer();\n return initializer ? unwrapFunction(initializer) : null;\n}\n\nfunction isFunctionNode(node: Node): boolean {\n return (\n Node.isArrowFunction(node) ||\n Node.isFunctionExpression(node) ||\n Node.isFunctionDeclaration(node) ||\n Node.isMethodDeclaration(node)\n );\n}\n\n/**\n * The single, final `return <expression>` of the load body, or null when the\n * body has early returns — those would need any insertion hoisted above them,\n * and guessing where is worse than refusing.\n */\nexport function findFinalReturn(\n fn: LoadFunction,\n body: Block,\n): ReturnStatement | null {\n const statements = body.getStatements();\n const last = statements[statements.length - 1];\n if (!last || !Node.isReturnStatement(last)) return null;\n\n const returns = body\n .getDescendantsOfKind(SyntaxKind.ReturnStatement)\n .filter((r) => r.getFirstAncestor(isFunctionNode) === fn);\n if (returns.length !== 1) return null;\n\n return last;\n}\n\n/** The object literal a return statement yields, unwrapping parentheses. */\nexport function returnedObject(\n statement: ReturnStatement,\n): ObjectLiteralExpression | null {\n let expression = statement.getExpression();\n while (expression && Node.isParenthesizedExpression(expression)) {\n expression = expression.getExpression();\n }\n if (!expression || !Node.isObjectLiteralExpression(expression)) return null;\n return expression;\n}\n\nexport function hasProperty(\n object: ObjectLiteralExpression,\n name: string,\n): boolean {\n return object.getProperties().some((property) => {\n if (\n Node.isPropertyAssignment(property) ||\n Node.isShorthandPropertyAssignment(property)\n ) {\n return property.getName() === name;\n }\n return false;\n });\n}\n\nexport function hasSpreadOf(\n object: ObjectLiteralExpression,\n expressionText: string,\n): boolean {\n return object\n .getProperties()\n .some(\n (property) =>\n Node.isSpreadAssignment(property) &&\n property.getExpression().getText() === expressionText,\n );\n}\n\n/** How a load receives its event: not at all, by name, or destructured. */\nexport type EventParameter =\n | { kind: \"none\" }\n | { kind: \"identifier\"; name: string; param: ParameterDeclaration }\n | {\n kind: \"binding\";\n pattern: import(\"ts-morph\").ObjectBindingPattern;\n param: ParameterDeclaration;\n }\n | { kind: \"unsupported\" };\n\nexport function inspectEventParameter(fn: LoadFunction): EventParameter {\n const params = fn.getParameters();\n if (params.length === 0) return { kind: \"none\" };\n if (params.length > 1) return { kind: \"unsupported\" };\n\n const param = params[0];\n if (param.getInitializer() || param.isRestParameter()) {\n return { kind: \"unsupported\" };\n }\n const nameNode = param.getNameNode();\n if (Node.isIdentifier(nameNode)) {\n return { kind: \"identifier\", name: nameNode.getText(), param };\n }\n if (Node.isObjectBindingPattern(nameNode)) {\n return { kind: \"binding\", pattern: nameNode, param };\n }\n return { kind: \"unsupported\" };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport type { ImportSpec } from \"../../../../runtime/ts-morph-helpers\";\nimport {\n ensureImportSpec,\n ensureNamedImports,\n findFinalReturn,\n findLoadFunction,\n hasProperty,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"./load-function\";\n\nexport interface LayoutServerLocale {\n /**\n * Expression passed as `locale` to `loadCms`, given the name of the load's\n * event parameter: `() => \"'en'\"` or `(event) => \\`getLocale(${event}.url)\\``.\n */\n expression: (eventName: string) => string;\n /** Imports the expression depends on. */\n imports?: ImportSpec[];\n}\n\n/** A single-locale site: the literal default locale. */\nexport const DEFAULT_LOCALE: LayoutServerLocale = {\n expression: () => \"'en'\",\n};\n\n/** A wuchale site: the locale enable-i18n's reroute already resolved from the URL. */\nexport const WUCHALE_LOCALE: LayoutServerLocale = {\n expression: (eventName) => `getLocale(${eventName}.url)`,\n imports: [\n { namedImports: [\"getLocale\"], moduleSpecifier: \"$locales/main.url\" },\n ],\n};\n\nfunction cmsSnippet(eventName: string, locale: string): string {\n return dedent`\n const { cms, notFound, gone, redirectTo } = await loadCms(${eventName}, { locale: ${locale} });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n `;\n}\n\nfunction importLine(spec: ImportSpec): string {\n const parts: string[] = [];\n if (spec.defaultImport) parts.push(spec.defaultImport);\n if (spec.namespaceImport) parts.push(`* as ${spec.namespaceImport}`);\n if (spec.namedImports?.length)\n parts.push(`{ ${spec.namedImports.join(\", \")} }`);\n return `import ${parts.join(\", \")} from '${spec.moduleSpecifier}';`;\n}\n\n/**\n * A root `+layout.server.ts` written from scratch, for a project that has\n * none — the static template keeps its layout load universal.\n */\nexport function createdLayoutServer(locale: LayoutServerLocale): string {\n const imports = [\n \"import { error, redirect } from '@sveltejs/kit';\",\n \"import { loadCms } from '$lib/cms';\",\n ...(locale.imports ?? []).map(importLine),\n \"import type { LayoutServerLoad } from './$types';\",\n ].join(\"\\n\");\n const snippet = cmsSnippet(\"event\", locale.expression(\"event\"))\n .split(\"\\n\")\n .join(\"\\n\\t\");\n\n return dedent`\n ${imports}\n\n export const load: LayoutServerLoad = async (event) => {\n \t${snippet}\n\n \treturn { cms };\n };\n `.concat(\"\\n\");\n}\n\nconst FAILURE_HINT = [\n \"Call loadCms from the root +layout.server.ts load and return `cms`:\",\n \"\",\n createdLayoutServer(DEFAULT_LOCALE).trimEnd(),\n \"\",\n \"loadCms needs the whole event, so a destructured parameter has to become\",\n \"`event` with the destructuring moved into the body.\",\n].join(\"\\n\");\n\n/**\n * Wires `loadCms` into the root `+layout.server.ts`, creating the file when\n * the project has none:\n *\n * - `loadCms` needs the whole request event, so a destructured parameter is\n * renamed to `event` and the destructuring becomes the first statement.\n * - The tombstone triple (`redirectTo`, `gone`, `notFound`) is handled just\n * before the return.\n * - `cms` is added to the returned object, ahead of any spread so nothing\n * later can shadow it.\n *\n * Anything else — no exported `load`, an expression-bodied arrow, several\n * returns, a non-literal return — is reported as `failed` with the snippet to\n * paste, and the file is left exactly as it was.\n */\nexport function modifyLayoutServer(\n layoutServerPath: string,\n locale: LayoutServerLocale = DEFAULT_LOCALE,\n): ModifyOutcome {\n if (!fs.existsSync(layoutServerPath)) {\n fs.mkdirSync(path.dirname(layoutServerPath), { recursive: true });\n fs.writeFileSync(layoutServerPath, createdLayoutServer(locale));\n return { status: \"success\", changed: true };\n }\n\n const original = fs.readFileSync(layoutServerPath, \"utf8\");\n if (original.includes(\"loadCms(\")) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutServerPath);\n\n // --- Inspect everything before touching anything. ---\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"failed\", message: FAILURE_HINT };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n const object = returned && returnedObject(returned);\n if (!returned || !object) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const eventName = event.kind === \"identifier\" ? event.name : \"event\";\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n if (!hasProperty(object, \"cms\")) {\n const spreadIndex = object\n .getProperties()\n .findIndex((property) => Node.isSpreadAssignment(property));\n if (spreadIndex === -1) {\n object.addShorthandPropertyAssignment({ name: \"cms\" });\n } else {\n object.insertShorthandPropertyAssignment(spreadIndex, { name: \"cms\" });\n }\n }\n\n const returnIndex = body.getStatements().indexOf(returned);\n body.insertStatements(\n returnIndex,\n `\\n${cmsSnippet(eventName, locale.expression(eventName))}\\n`,\n );\n\n if (event.kind === \"binding\") {\n const destructuring = event.pattern.getText();\n body.insertStatements(0, `const ${destructuring} = ${eventName};`);\n const typeText = event.param.getTypeNode()?.getText();\n event.param.replaceWithText(\n typeText ? `${eventName}: ${typeText}` : eventName,\n );\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: eventName });\n }\n\n if (!fn.isAsync()) fn.setIsAsync(true);\n\n ensureNamedImports(sourceFile, \"@sveltejs/kit\", [\"error\", \"redirect\"]);\n ensureNamedImports(sourceFile, \"$lib/cms\", [\"loadCms\"]);\n for (const spec of locale.imports ?? []) {\n ensureImportSpec(sourceFile, spec);\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Node } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport {\n findFinalReturn,\n findLoadFunction,\n hasSpreadOf,\n inspectEventParameter,\n newProject,\n returnedObject,\n} from \"./load-function\";\n\nconst FAILURE_HINT = dedent`\n Forward the server load's data through the root +layout.ts, so \\`cms\\` reaches\n the page:\n\n export const load = async ({ url, data }) => {\n // ...existing code...\n return { ...data, /* existing keys */ };\n };\n`;\n\n/**\n * Make a universal root \\`+layout.ts\\` forward its server load's data.\n *\n * SvelteKit hands a universal load the server load's result as \\`data\\`, and\n * only what the universal load returns reaches the page. A layout that\n * returns its own object without spreading \\`data\\` — the static template\n * does — would drop \\`cms\\` on the floor once \\`+layout.server.ts\\` exists.\n *\n * No file, or a file without a \\`load\\`, needs nothing: server data flows\n * through on its own.\n */\nexport function modifyLayoutUniversal(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"success\", changed: false };\n }\n\n const sourceFile = newProject().addSourceFileAtPath(layoutPath);\n\n const fn = findLoadFunction(sourceFile);\n if (!fn) return { status: \"success\", changed: false };\n\n const body = fn.getBody();\n if (!body || !Node.isBlock(body)) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const event = inspectEventParameter(fn);\n if (event.kind === \"unsupported\") {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const returned = findFinalReturn(fn, body);\n if (!returned) return { status: \"failed\", message: FAILURE_HINT };\n\n const dataExpression =\n event.kind === \"identifier\" ? `${event.name}.data` : \"data\";\n\n // `return data;` already forwards everything.\n const expression = returned.getExpression();\n if (expression && expression.getText() === dataExpression) {\n return { status: \"success\", changed: false };\n }\n\n const object = returnedObject(returned);\n if (!object) return { status: \"failed\", message: FAILURE_HINT };\n if (hasSpreadOf(object, dataExpression)) {\n return { status: \"success\", changed: false };\n }\n\n // --- Mutate bottom-up so earlier node references stay valid. ---\n // First, so the layout's own keys still win over anything the server sent.\n object.insertSpreadAssignment(0, { expression: dataExpression });\n\n if (event.kind === \"binding\") {\n const hasData = event.pattern\n .getElements()\n .some((element) => element.getName() === \"data\");\n if (!hasData) {\n const text = event.pattern.getText();\n event.pattern.replaceWithText(text.replace(/^\\{\\s*/, \"{ data, \"));\n }\n } else if (event.kind === \"none\") {\n fn.addParameter({ name: \"{ data }\" });\n }\n\n sourceFile.formatText();\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n}\n","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 IMPORT_SNIPPET = dedent`\n import { AdminBar } from '@velastack/cms';\n`;\n\nconst MARKUP_SNIPPET = \"\\n<AdminBar />\\n\";\n\nconst NOT_FOUND_HINT = [\n \"Create the root src/routes/+layout.svelte and mount <AdminBar /> 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:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Mount <AdminBar /> 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:\",\n MARKUP_SNIPPET.trim(),\n].join(\"\\n\");\n\n/** Mounts `<AdminBar />` at the top level of the root layout. */\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(\"AdminBar\")) {\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 { namedImports: [\"AdminBar\"], moduleSpecifier: \"@velastack/cms\" },\n ]);\n });\n return out;\n });\n\n file.appendMarkup(MARKUP_SNIPPET);\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n probeFirstExisting,\n VITE_CONFIG_CANDIDATES,\n} from \"../../../runtime/config-target\";\nimport { resolveMode, type CmsMode } from \"./generate\";\nimport { modifyViteConfig } from \"./modifies/vite-config\";\nimport {\n DEFAULT_LOCALE,\n WUCHALE_LOCALE,\n modifyLayoutServer,\n} from \"./modifies/layout.server\";\nimport { modifyLayoutUniversal } from \"./modifies/layout\";\nimport { modifyLayoutSvelte } from \"./modifies/layout.svelte\";\n\n/**\n * Drop any create that already exists on disk.\n *\n * `writeResult` overwrites an existing create whose content differs and\n * reports it as a modify, which for these files would mean a re-run silently\n * resetting a developer's edits to `$lib/cms.ts` or the backend config. The\n * wiring is theirs once it has been written; a re-run only fills in what is\n * missing.\n */\nexport function keepMissing(creates: File[], root: string): File[] {\n return creates.filter((file) => !fs.existsSync(path.join(root, file.path)));\n}\n\n/** The locale list from `wuchale.config.js`, or null when it cannot be read. */\nexport function readWuchaleLocales(root: string): string[] | null {\n const configPath = path.join(root, \"wuchale.config.js\");\n if (!fs.existsSync(configPath)) return null;\n const match = fs\n .readFileSync(configPath, \"utf8\")\n .match(/locales:\\s*\\[([^\\]]*)\\]/);\n if (!match) return null;\n const locales = [...match[1].matchAll(/['\"]([^'\"]+)['\"]/g)].map((m) => m[1]);\n return locales.length > 0 ? locales : null;\n}\n\n/**\n * Arguments for the `cms()` Vite plugin.\n *\n * A hosted CMS needs the endpoint and locales at build time so media can be\n * downloaded into the prerendered site. An app hosting the backend itself\n * needs nothing: the media steps are no-ops without an endpoint.\n */\nexport function vitePluginArgs(mode: CmsMode, locales: string[]): string {\n if (mode.local) return \"\";\n const list = locales.map((locale) => `'${locale}'`).join(\", \");\n return `{ endpoint: '${mode.endpoint}', locales: [${list}] }`;\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const mode = resolveMode(options);\n const i18n = options.features.i18n;\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying vite.config\");\n const viteConfigPath =\n probeFirstExisting(options.root, VITE_CONFIG_CANDIDATES) ??\n path.join(options.root, VITE_CONFIG_CANDIDATES[0]);\n const locales = (i18n && readWuchaleLocales(options.root)) || [\"en\"];\n pushResult(\n modifyOutcomeToFile(\n viteConfigPath,\n modifyViteConfig(viteConfigPath, vitePluginArgs(mode, locales)),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.server.ts\");\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n const locale = i18n ? WUCHALE_LOCALE : DEFAULT_LOCALE;\n pushResult(\n modifyOutcomeToFile(\n layoutServerPath,\n modifyLayoutServer(layoutServerPath, locale),\n ),\n );\n\n // A universal root layout has to pass the server load's data along, or\n // `cms` never reaches the page. The static template has one.\n logger.info(\"Modifying src/routes/+layout.ts\");\n const layoutUniversalPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.ts\",\n );\n pushResult(\n modifyOutcomeToFile(\n layoutUniversalPath,\n modifyLayoutUniversal(layoutUniversalPath),\n ),\n );\n\n logger.info(\"Modifying src/routes/+layout.svelte\");\n const layoutSveltePath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutSveltePath, modifyLayoutSvelte(layoutSveltePath)),\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":";;;;;;;;;;AAWA,IAAM,IAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAEL,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAS,EAAY,GAAsB;CACzC,OAAO,EAAK,QAAQ,OAAO,EAAE;AAC/B;AAOA,SAAgB,EACd,GACA,IAAa,IACE;CACf,IAAM,IAAO,OAAO,EAAW;CAC/B,IAAI,CAAC,EAAG,WAAW,CAAc,GAC/B,OAAO;EAAE,QAAQ;EAAa,SAAS;CAAe;CAOxD,IAAM,IAAa,IAJC,EAAQ;EAC1B,iBAAiB,EAAE,SAAS,GAAK;EACjC,sBAAsB,EAAE,WAAW,EAAU,OAAO;CACtD,CACmB,CAAA,CAAQ,oBAAoB,CAAc,GAEzD,IAAU,IACV,IAAS;CAMb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