@plitzi/sdk-authoring 0.38.6 → 0.38.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/node.js CHANGED
@@ -1,7 +1,478 @@
1
- import { n as e, t as compactSvg } from "./index-compactSvg.js";
2
- import { existsSync, readFileSync, readdirSync } from "node:fs";
3
- import path from "node:path";
1
+ import { Vr as e, d as compactSvg, n as authorSpace, un as e$1 } from "./index-src.js";
2
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
3
+ import m from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
+ var r = `plitzi/author.ts`;
6
+ var i$1 = "src/space";
7
+ var a$1 = `${i$1}/index.ts`;
8
+ var o$1 = "src/plugins";
9
+ var s$1 = ["index.ts", "index.tsx"];
10
+ var c$1 = "declaration.ts";
11
+ var l$1 = "functions";
12
+ var u = "vendor/plugins";
13
+ var d = "plugin-manifest.json";
14
+ var p = "public";
15
+ var m$1 = "src/data";
16
+ var h = "src/functions";
17
+ var g = "src/runtime";
18
+ `${g}`;
19
+ var v$1 = "dist";
20
+ //#endregion
21
+ //#region ../sdk-shared/dist/project/layout.mjs
22
+ var v = {
23
+ "plugin-entry-missing": {
24
+ level: "error",
25
+ means: "a folder of src/plugins/ with no index.ts (or index.tsx), which the server builds the plugin from"
26
+ },
27
+ "plugin-entry-ambiguous": {
28
+ level: "error",
29
+ means: "a folder of src/plugins/ with both index.ts and index.tsx: a plugin starts at one"
30
+ },
31
+ "entry-not-typescript": {
32
+ level: "error",
33
+ means: "an entry the server builds or runs written as JavaScript (index.js, .jsx, .mjs, .cjs): the project is TypeScript"
34
+ },
35
+ "plugin-name-invalid": {
36
+ level: "error",
37
+ means: "a folder of src/plugins/ whose name cannot be an element type: a letter, then letters and digits"
38
+ },
39
+ "plugin-type-taken": {
40
+ level: "error",
41
+ means: "two folders of src/plugins/ that are the same element type (StoryEditor and storyEditor)"
42
+ },
43
+ "plugin-shadowed": {
44
+ level: "error",
45
+ means: "a plugin both in src/plugins/ and, as it was built, in vendor/plugins/: the built one runs"
46
+ },
47
+ "plugin-functions-entry-missing": {
48
+ level: "error",
49
+ means: "a plugin’s functions/ with code and no index.ts, which its server half is built from"
50
+ },
51
+ "functions-entry-missing": {
52
+ level: "error",
53
+ means: "src/functions/ with code and no index.ts, which the project’s functions are built from"
54
+ },
55
+ "runtime-entry-missing": {
56
+ level: "error",
57
+ means: "src/runtime/ with code and no index.ts, which the space’s runtime starts at"
58
+ },
59
+ "space-entry-missing": {
60
+ level: "error",
61
+ means: "a space written in the project with no src/space/index.ts, which the server and npm run author import"
62
+ },
63
+ "space-default-export": {
64
+ level: "error",
65
+ means: "src/space/index.ts exporting the space by default, where it is imported by name: `space`"
66
+ },
67
+ "vendor-manifest-missing": {
68
+ level: "error",
69
+ means: "a built plugin (vendor/plugins/<type>/) with no plugin-manifest.json"
70
+ },
71
+ "vendor-manifest-invalid": {
72
+ level: "error",
73
+ means: "a built plugin’s plugin-manifest.json that is not a manifest"
74
+ },
75
+ "vendor-script-missing": {
76
+ level: "error",
77
+ means: "a built plugin’s manifest naming no script to run, or one that is not there"
78
+ },
79
+ "env-in-src": {
80
+ level: "error",
81
+ means: ".env inside src/: Node reads the project’s settings from the .env at its root"
82
+ },
83
+ "folder-misplaced": {
84
+ level: "error",
85
+ means: "code in a folder named like one the server reads (src/plugin/, plugins/ at the root): nothing reads it"
86
+ },
87
+ "folder-near-miss": {
88
+ level: "warning",
89
+ means: "a folder named like one the server reads (src/Data/, src/runtimes/), which nothing reads"
90
+ },
91
+ "plugin-declaration-missing": {
92
+ level: "warning",
93
+ means: "a plugin folder with no declaration.ts: the space’s use of the plugin is held to nothing"
94
+ },
95
+ "plugin-file-loose": {
96
+ level: "warning",
97
+ means: "a file directly in src/plugins/, where every plugin is a folder"
98
+ },
99
+ "data-not-json": {
100
+ level: "warning",
101
+ means: "a file of src/data/ that is not JSON, which no provider and no ctx.data reads"
102
+ },
103
+ "env-missing": {
104
+ level: "warning",
105
+ means: "no .env at the project’s root: none of its settings is set"
106
+ },
107
+ "env-example-missing": {
108
+ level: "warning",
109
+ means: "no .env.example: a clone does not know what .env must hold"
110
+ },
111
+ "public-data": {
112
+ level: "warning",
113
+ means: "JSON in public/data/ of a project with a server: served to anyone who asks"
114
+ },
115
+ "public-secret-file": {
116
+ level: "warning",
117
+ means: "a file in public/ named like a secret (.env, a key, a dump): served to anyone who asks"
118
+ }
119
+ };
120
+ var y = (e, t, n, r, i) => ({
121
+ level: v[e].level,
122
+ code: e,
123
+ file: t,
124
+ message: n,
125
+ fix: r,
126
+ ...i ? { autofix: i } : {}
127
+ });
128
+ var b = /* @__PURE__ */ new Set([
129
+ ".gitkeep",
130
+ "README.md",
131
+ ".DS_Store"
132
+ ]);
133
+ var ee = /^index\.(?:js|jsx|mjs|cjs)$/;
134
+ var x = /^[A-Za-z][A-Za-z0-9]*$/;
135
+ var S = (e) => {
136
+ let t = {
137
+ files: [],
138
+ folders: []
139
+ };
140
+ try {
141
+ for (let n of readdirSync(e, { withFileTypes: !0 })) {
142
+ let r = n.isSymbolicLink() ? statSync(m.join(e, n.name), { throwIfNoEntry: !1 }) : void 0;
143
+ n.isFile() || r?.isFile() ? t.files.push(n.name) : (n.isDirectory() || r?.isDirectory()) && t.folders.push(n.name);
144
+ }
145
+ } catch {
146
+ return t;
147
+ }
148
+ return {
149
+ files: t.files.sort(),
150
+ folders: t.folders.sort()
151
+ };
152
+ };
153
+ var C = (e, t, n) => {
154
+ let r = t.split("/").filter((e) => e !== "" && e !== "."), i = e;
155
+ for (let [e, t] of r.entries()) {
156
+ let { files: a, folders: o } = S(i);
157
+ if (!(e === r.length - 1 && n === "file" ? a : o).includes(t)) return !1;
158
+ i = m.join(i, t);
159
+ }
160
+ return !0;
161
+ };
162
+ var w = (e, t, n = /* @__PURE__ */ new Set()) => {
163
+ let { files: r, folders: i } = S(m.join(e, t));
164
+ return [...r.map((e) => `${t}/${e}`), ...i.filter((e) => !n.has(e)).flatMap((r) => w(e, `${t}/${r}`, n))];
165
+ };
166
+ var T = ({ files: e, folders: t }) => t.length > 0 || e.some((e) => !b.has(e));
167
+ var E = (e, t) => e.toLowerCase() === t.toLowerCase();
168
+ var D = (e) => `${e.charAt(0).toUpperCase()}${e.slice(1)}`;
169
+ var O = (e, t) => {
170
+ let n = Array.from({ length: e.length + 1 }, (e, n) => Array.from({ length: t.length + 1 }, (e, t) => Math.max(n, t) * Number(n === 0 || t === 0)));
171
+ for (let r = 1; r <= e.length; r++) for (let i = 1; i <= t.length; i++) {
172
+ let a = e[r - 1] === t[i - 1] ? 0 : 1;
173
+ n[r][i] = Math.min(n[r - 1][i] + 1, n[r][i - 1] + 1, n[r - 1][i - 1] + a), r > 1 && i > 1 && e[r - 1] === t[i - 2] && e[r - 2] === t[i - 1] && (n[r][i] = Math.min(n[r][i], n[r - 2][i - 2] + 1));
174
+ }
175
+ return n[e.length][t.length];
176
+ };
177
+ var k = (e, t) => {
178
+ if (e === t) return !1;
179
+ let n = e.toLowerCase(), r = t.toLowerCase();
180
+ return n === r || n === `${r}s` || `${n}s` === r || r.length >= 5 && O(n, r) <= 1;
181
+ };
182
+ var A = "macOS and Windows disks ignore case, so it is found there — and not on Linux, where the project is deployed.";
183
+ var j = (e, t) => E(e, t) ? `git mv ${e} ${e}-tmp && git mv ${e}-tmp ${t}` : `git mv ${e} ${t}`;
184
+ var M = (e) => `${e.charAt(0).toLowerCase()}${e.slice(1)}`;
185
+ var N = (e) => {
186
+ let t = e.split(/[^A-Za-z0-9]+/).filter(Boolean).map(D).join(""), n = /^\d+/.exec(t)?.[0] ?? "", r = `${D(t.slice(n.length))}${n}`;
187
+ return x.test(r) ? r : void 0;
188
+ };
189
+ var I = (e) => e.length > 1 ? `${e[0]} (or ${e.slice(1).join(", ")})` : e[0];
190
+ var L = (e, t) => {
191
+ let { folder: n, accepted: r, code: i, lost: a } = t, o = S(m.join(e, n)), s = r.filter((e) => o.files.includes(e));
192
+ if (s.length === 1) return [];
193
+ if (s.length > 1) return [y("plugin-entry-ambiguous", `${n}/`, `${n}/ has both ${s.join(" and ")}, and a plugin is built from one of them.`, `Keep one — ${s[s.length - 1]} when it writes JSX — and delete the other.`)];
194
+ let c = o.files.find((e) => ee.test(e));
195
+ if (c) {
196
+ let e = c.endsWith(".jsx") && r.includes("index.tsx") ? "index.tsx" : "index.ts";
197
+ return [y("entry-not-typescript", `${n}/${c}`, `${n}/${c} is JavaScript, and ${n}/ is built from ${I(r)}: the project's code is TypeScript, so ${a}.`, `Rename it ${e} — JavaScript is TypeScript already, types left out: ${j(`${n}/${c}`, `${n}/${e}`)}`, {
198
+ action: "move",
199
+ from: `${n}/${c}`,
200
+ to: `${n}/${e}`
201
+ })];
202
+ }
203
+ let l = o.files.find((e) => r.some((t) => k(e, t)));
204
+ if (l) {
205
+ let e = r.find((e) => k(l, e)) ?? r[0];
206
+ return [y(i, `${n}/${l}`, `${n}/ has no ${e} — did you mean ${l}? Named otherwise, ${a}.${E(l, e) ? ` ${A}` : ""}`, `Rename it ${e}: ${j(`${n}/${l}`, `${n}/${e}`)}`, {
207
+ action: "move",
208
+ from: `${n}/${l}`,
209
+ to: `${n}/${e}`
210
+ })];
211
+ }
212
+ let u = o.folders.find((t) => r.some((r) => C(e, `${n}/${t}/${r}`, "file")));
213
+ return u ? [y(i, `${n}/${u}/`, `${n}/ has no ${I(r)}, and ${n}/${u}/ has: one folder too deep, so ${a}.`, `Move what ${n}/${u}/ holds up into ${n}/.`, {
214
+ action: "move",
215
+ from: `${n}/${u}/`,
216
+ to: `${n}/`
217
+ })] : [y(i, `${n}/`, `${n}/ has no ${I(r)}, so ${a}.`, t.write)];
218
+ };
219
+ var R = (e, t) => T(S(m.join(e, t.folder))) ? L(e, t) : [];
220
+ var te = (e) => {
221
+ let t = N(e), n = `${o$1}/${e}`;
222
+ return y("plugin-name-invalid", `${n}/`, `${n}/ cannot be a plugin: a folder of ${o$1}/ is registered as the element type its name makes, and a type is a letter followed by letters and digits.${t ? ` Did you mean ${t}?` : ""}`, t ? `Rename it ${t} — the type ${M(t)}: ${j(n, `${o$1}/${t}`)}; then type: '${M(t)}' in its ${c$1}, and renderType: '${M(t)}' where the space renders it.` : "Rename it with letters and digits, starting with a letter: StatCard is the type statCard.");
223
+ };
224
+ var ne = (e, t) => e.find((e) => e === `${t}.tsx`) ?? e.find((e) => e === `${t}.ts`);
225
+ var z = (e, t) => {
226
+ let n = `${o$1}/${t}`, { files: r } = S(m.join(e, n));
227
+ if (r.includes("declaration.ts")) return [];
228
+ let o = M(t), s = `authoring holds none of the space's ${o} elements to its attributes, and the builder does not offer it`, c = r.find((e) => k(e, c$1));
229
+ return c ? [y("plugin-declaration-missing", `${n}/${c}`, `${n}/ has no ${c$1} — did you mean ${c}? Named otherwise, ${s}.${E(c, "declaration.ts") ? ` ${A}` : ""}`, `Rename it ${c$1}: ${j(`${n}/${c}`, `${n}/${c$1}`)}`, {
230
+ action: "move",
231
+ from: `${n}/${c}`,
232
+ to: `${n}/${c$1}`
233
+ })] : [y("plugin-declaration-missing", `${n}/`, `${n}/ has no ${c$1}: ${s}.`, `Write ${n}/${c$1} — export default { type: '${o}', … } — as npx plitzi add plugin writes one beside the component it makes.`)];
234
+ };
235
+ var B = (e, t) => {
236
+ if (!x.test(t)) return [te(t)];
237
+ let n = `${o$1}/${t}`, r = M(t), a = ne(S(m.join(e, n)).files, t);
238
+ return [
239
+ ...L(e, {
240
+ folder: n,
241
+ accepted: s$1,
242
+ code: "plugin-entry-missing",
243
+ lost: `the server cannot build the plugin ${r}`,
244
+ write: `Write ${n}/index.ts exporting the component by default${a ? ` — export { default } from './${a}';` : ""} — as npx plitzi add plugin writes it. Every folder of ${o$1}/ is a plugin: code several plugins share goes outside it (src/shared/).`
245
+ }),
246
+ ...R(e, {
247
+ folder: `${n}/${l$1}`,
248
+ accepted: ["index.ts"],
249
+ code: "plugin-functions-entry-missing",
250
+ lost: `none of the plugin's server half runs (its routes under /fn/plugins/${r}/)`,
251
+ write: `Write ${n}/${l$1}/index.ts exporting defineFunctions({ … }) by default — as npx plitzi add plugin --server writes it.`
252
+ }),
253
+ ...z(e, t)
254
+ ];
255
+ };
256
+ var V = (e) => {
257
+ let t = /* @__PURE__ */ new Map();
258
+ for (let n of e.filter((e) => x.test(e))) t.set(M(n), [...t.get(M(n)) ?? [], n]);
259
+ return [...t].flatMap(([e, t]) => t.slice(1).map((n) => y("plugin-type-taken", `${o$1}/${n}/`, `${o$1}/${t[0]}/ and ${o$1}/${n}/ are both the plugin ${e}: the server registers a folder by its name with a small first letter, and keeps one.`, `Put them in one folder, or rename one: git mv ${o$1}/${n} ${o$1}/<AnotherName>`)));
260
+ };
261
+ var H = (t) => e(t.assets) ? Object.values(t.assets).flatMap((t) => e(t) && typeof t.src == "string" && typeof t.type == "string" ? [{
262
+ src: t.src,
263
+ type: t.type,
264
+ isMain: t.isMain === !0
265
+ }] : []) : [];
266
+ var U = (t, n) => {
267
+ let r = `${u}/${n}`, i = `${r}/${d}`, a = `npx plitzi pull brings it again — or delete ${r}/, and the space renders no ${n}.`;
268
+ if (!C(t, i, "file")) return { problem: y("vendor-manifest-missing", `${r}/`, `${r}/ has no ${d}: the server runs a built plugin by what its manifest names, so ${n} does not run.`, a) };
269
+ let o;
270
+ try {
271
+ o = JSON.parse(readFileSync(m.join(t, i), "utf-8"));
272
+ } catch (e) {
273
+ return { problem: y("vendor-manifest-invalid", i, `${i} is not JSON (${e instanceof Error ? e.message : String(e)}), so ${n} does not run.`, a) };
274
+ }
275
+ if (!e(o)) return { problem: y("vendor-manifest-invalid", i, `${i} is not a manifest, so ${n} does not run.`, a) };
276
+ let s = H(o), l = s.find((e) => e.type === "script" && e.isMain) ?? s.find((e) => e.type === "script");
277
+ if (!l) return { problem: y("vendor-script-missing", i, `${i} names no script to run, so ${n} does not run.`, a) };
278
+ if (!C(t, m.posix.join(r, l.src), "file")) return { problem: y("vendor-script-missing", i, `${i} names ${l.src} as the script to run, and ${r}/${l.src} is not there, so ${n} does not run.`, a) };
279
+ let u$1 = s.find((e) => e.type === "style");
280
+ return {
281
+ script: m.join(t, r, l.src),
282
+ ...u$1 ? { style: m.join(t, r, u$1.src) } : {},
283
+ version: typeof o.version == "string" ? o.version : "1.0.0",
284
+ ...typeof o.functions == "string" ? { functions: m.join(t, r, o.functions) } : {}
285
+ };
286
+ };
287
+ var W = (e) => {
288
+ let { files: t, folders: n } = S(m.join(e, o$1)), r = t.filter((e) => !b.has(e) && e !== "declarations.ts").map((e) => {
289
+ let { name: t } = m.parse(e), n = t !== "index" && N(t) || "<Name>";
290
+ return y("plugin-file-loose", `${o$1}/${e}`, `${o$1}/${e} is a file, and every plugin is a folder of ${o$1}/: the server reads nothing of it.`, `Give it a folder with an index.ts that exports it by default — ${o$1}/${n}/${e} and ${o$1}/${n}/index.ts, as npx plitzi add plugin writes them — or move it out of ${o$1}/.`);
291
+ }), a = S(m.join(e, u)).folders, o = new Set(n.filter((e) => x.test(e)).map(M)), s = a.filter((e) => o.has(e)).map((e) => y("plugin-shadowed", `${u}/${e}/`, `${e} is both ${u}/${e}/, as it was built, and a folder of ${o$1}/: the server runs the built one, and a change to the source shows nowhere.`, `Delete ${u}/${e}/: the source is the plugin now.`)), c = a.flatMap((t) => {
292
+ let n = U(e, t);
293
+ return "problem" in n ? [n.problem] : [];
294
+ });
295
+ return [
296
+ ...n.flatMap((t) => B(e, t)),
297
+ ...V(n),
298
+ ...r,
299
+ ...s,
300
+ ...c
301
+ ];
302
+ };
303
+ var G = (e, t) => t.map((t) => e.find((e) => E(e, t))).find((e) => e !== void 0);
304
+ var K = (e) => (t) => {
305
+ for (let n of S(m.join(e, t)).folders) {
306
+ let r = G(S(m.join(e, t, n)).files, [...s$1, c$1]);
307
+ if (r) return `${t}/${n}/${r}`;
308
+ }
309
+ };
310
+ var q = (e) => (t) => {
311
+ let n = G(S(m.join(e, t)).files, ["index.ts"]);
312
+ return n ? `${t}/${n}` : void 0;
313
+ };
314
+ var J = (e, { mode: a, space: o }) => [
315
+ {
316
+ at: o$1,
317
+ reads: `the server builds plugins from ${o$1}/ only`,
318
+ holds: K(e)
319
+ },
320
+ {
321
+ at: h,
322
+ reads: `the project's functions are built from ${h}/ only`,
323
+ holds: q(e)
324
+ },
325
+ {
326
+ at: g,
327
+ reads: `the space's runtime is run from ${g}/ only`,
328
+ holds: q(e)
329
+ },
330
+ ...o === "local" ? [{
331
+ at: i$1,
332
+ reads: `the server's entry point and ${r} import the space from ${a$1}`,
333
+ holds: q(e)
334
+ }] : [],
335
+ ...a === "server" ? [{
336
+ at: m$1,
337
+ reads: `the server reads the project's data from ${m$1}/ only (/data/<file>, ctx.data)`
338
+ }] : [],
339
+ {
340
+ at: p,
341
+ reads: `the server serves ${p}/ only, at the site's root`
342
+ }
343
+ ];
344
+ var Y = (e, t) => {
345
+ let n = m.posix.dirname(t), r = m.posix.basename(t), i = n === "." ? "src" : ".", a = S(m.join(e, n)).folders.filter((e) => k(e, r)).map((e) => m.posix.join(n, e)), o = S(m.join(e, i)).folders.filter((e) => e === r || k(e, r)).map((e) => m.posix.join(i, e));
346
+ return [...a, ...o];
347
+ };
348
+ var X = (e, t) => J(e, t).flatMap(({ at: t, reads: n, holds: r }) => Y(e, t).map((i) => {
349
+ let a = r?.(i), o = E(i, t), s = `did you mean ${t}/? ${D(n)}.${o ? ` ${A}` : ""}`, c = `Move it: ${j(i, t)}`;
350
+ o ? c = `Rename it: ${j(i, t)}` : C(e, t, "folder") && (c = `Move what it holds into ${t}/, and delete it.`);
351
+ let l = {
352
+ action: "move",
353
+ from: `${i}/`,
354
+ to: `${t}/`
355
+ };
356
+ return a ? y("folder-misplaced", `${i}/`, `${i}/ holds ${a}, and nothing reads it there — ${s}`, c, l) : y("folder-near-miss", `${i}/`, `${i}/ is read by nothing — ${s}`, c, l);
357
+ }));
358
+ var re = (e, n) => {
359
+ if (!C(e, a$1, "file")) return n.some((e) => e.code === "folder-misplaced" && e.autofix?.action === "move" && e.autofix.to === "src/space/") ? [] : L(e, {
360
+ folder: i$1,
361
+ accepted: ["index.ts"],
362
+ code: "space-entry-missing",
363
+ lost: `the server's entry point and ${r}, which import the space from ${a$1}, do not start`,
364
+ write: `Write ${a$1} exporting the space — export const space = { name, permanentUrl, pages } — or bring back the one git has: git checkout -- ${a$1}`
365
+ });
366
+ let r$1 = readFileSync(m.join(e, a$1), "utf-8"), i = /^\s*export\s+default\b/m.test(r$1), a = /\bexport\s+(?:const|let|var|function)\s+space\b/.test(r$1) || /\bexport\s*\{[^}]*\bspace\b[^}]*\}/.test(r$1);
367
+ return i && !a ? [y("space-default-export", a$1, `${a$1} exports the space by default, and it is imported by name — import { space } from './space/index.ts' — so the server's entry point and ${r} find no space.`, "Export it as `export const space = …` instead of `export default …`.")] : [];
368
+ };
369
+ var ie = (e) => e.split("\n").map((e) => e.replace(/^(\s*(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=).*$/, "$1")).join("\n");
370
+ var ae = (e) => {
371
+ let t = S(e).files, n = t.includes(".env"), r = t.includes(".env.example"), i = w(e, "src", /* @__PURE__ */ new Set(["node_modules"])).filter((e) => m.posix.basename(e) === ".env"), a = !n && i.length === 1, o = i.map((e) => y("env-in-src", e, `${e} is never read: Node reads the project's settings from the .env at its root, as its scripts start it (--env-file-if-exists=.env).`, a ? `Move it to the root: mv ${e} .env` : `Copy what it sets into the root's .env, then delete ${e}.`, a ? {
372
+ action: "move",
373
+ from: e,
374
+ to: ".env"
375
+ } : void 0)), s = n || o.length > 0 ? [] : [y("env-missing", ".env", ".env is missing at the project’s root: none of its settings is set — the keys and secrets its code reads from process.env.", r ? "Copy .env.example and fill it in: cp .env.example .env" : "Write .env with the settings the project reads (process.env.*), and .env.example naming them.", r ? {
376
+ action: "copy",
377
+ from: ".env.example",
378
+ to: ".env"
379
+ } : void 0)], c = r ? [] : [y("env-example-missing", ".env.example", ".env.example is missing: committed where .env never is, it names the settings .env holds, with no secret in them — so a clone knows what to fill in.", n ? "Write it from .env with every value left empty, and commit it." : "Write it — each setting the project reads, as KEY= with no value — and commit it.", n ? {
380
+ action: "write",
381
+ file: ".env.example",
382
+ contents: ie(readFileSync(m.join(e, ".env"), "utf-8"))
383
+ } : void 0)];
384
+ return [
385
+ ...o,
386
+ ...s,
387
+ ...c
388
+ ];
389
+ };
390
+ var oe = (e) => w(e, m$1).filter((e) => !b.has(m.posix.basename(e)) && !e.endsWith(".json")).map((e) => y("data-not-json", e, `${e} is not JSON: a provider's /data/<file> and ctx.data read JSON files only, and plitzi push leaves it behind.`, `Keep it as JSON (${e.replace(/\.[^./]*$/, "")}.json), or move it out of ${m$1}/.`));
391
+ var se = /^\.env(?:\..*)?$|\.(?:pem|key|p12|pfx|jks|keystore|sqlite3?|db|sql|dump)$|secret|credential|password|passwd|private[-_.]?key|id_rsa|id_ed25519|service[-_]?account/i;
392
+ var ce = (e, t) => {
393
+ let r = w(e, p, /* @__PURE__ */ new Set(["node_modules"])), i = r.filter((e) => se.test(m.posix.basename(e))).map((e) => y("public-secret-file", e, `${e} is served to anyone who asks, as it is — everything in ${p}/ is on the internet once the project is deployed — and its name says it holds a secret, a key or a database.`, `Take it out of ${p}/: settings go in the root's .env${t === "server" ? `, data only the server reads in ${m$1}/` : ""}.`)), a = `${p}/data`, o = t === "server" ? r.filter((e) => e.startsWith(`${a}/`) && e.endsWith(".json")) : [], s = o.slice(0, 3).map((e) => m.posix.basename(e)), c = o.length > 0 ? [y("public-data", `${a}/`, `${a}/ holds ${String(o.length)} JSON file${o.length === 1 ? "" : "s"} (${s.join(", ")}${o.length > s.length ? ", …" : ""}), served to anyone who asks: every visitor can read all of ${o.length === 1 ? "it" : "them"}, not only what a page shows.`, `Data only the server should read goes in ${m$1}/ — a provider reads it on the server (runtime: 'server', query: '/data/<file>'), a function with ctx.data('<file>'), and neither serves the file. What every visitor may read can stay.`)] : [];
394
+ return [...i, ...c];
395
+ };
396
+ var Z = (t) => {
397
+ try {
398
+ let n = JSON.parse(readFileSync(m.join(t, "package.json"), "utf-8"));
399
+ return e(n) && [n.dependencies, n.devDependencies].some((t) => e(t) && "@plitzi/sdk-server" in t);
400
+ } catch {
401
+ return !1;
402
+ }
403
+ };
404
+ var le = (e, n) => ({
405
+ mode: n.mode ?? (Z(e) ? "server" : "client"),
406
+ space: n.space ?? (C(e, "src/space", "folder") || C(e, r, "file") ? "local" : "cloud")
407
+ });
408
+ var Q = (e, t = {}) => {
409
+ let n = le(e, t), i = X(e, n), a = [
410
+ ...W(e),
411
+ ...R(e, {
412
+ folder: h,
413
+ accepted: ["index.ts"],
414
+ code: "functions-entry-missing",
415
+ lost: "none of the project’s functions runs",
416
+ write: `Write ${h}/index.ts exporting defineFunctions({ … }) by default.`
417
+ }),
418
+ ...R(e, {
419
+ folder: g,
420
+ accepted: ["index.ts"],
421
+ code: "runtime-entry-missing",
422
+ lost: "the space’s runtime does not run",
423
+ write: `Write ${g}/index.ts exporting defineRuntime(…) by default — npx plitzi add runtime writes one.`
424
+ }),
425
+ ...n.space === "local" ? re(e, i) : [],
426
+ ...i,
427
+ ...ae(e),
428
+ ...n.mode === "server" ? oe(e) : [],
429
+ ...ce(e, n.mode)
430
+ ];
431
+ return [...a.filter((e) => e.level === "error"), ...a.filter((e) => e.level === "warning")];
432
+ };
433
+ var $ = class extends Error {
434
+ #e;
435
+ get findings() {
436
+ return this.#e;
437
+ }
438
+ constructor(e) {
439
+ let t = e.length === 1 ? "one error" : `${String(e.length)} errors`, n = e.map((e, t) => `${String(t + 1)}. ${e.message}\n → ${e.fix}`).join("\n\n"), r = e.filter((e) => e.autofix).length, i = r === e.length ? "these fixes" : `${String(r)} of these fixes`, a = r > 0 ? `npx plitzi doctor --fix makes ${i} itself.` : "npx plitzi doctor says these with the rest of the project.";
440
+ super(`The project is not laid out as Plitzi reads it — ${t}:\n\n${n}\n\n${a}`), this.name = "ProjectLayoutError", this.#e = e;
441
+ }
442
+ };
443
+ Object.defineProperty($, "name", { value: "ProjectLayoutError" });
444
+ var de = (e, t = {}) => {
445
+ let n = Q(e, t), r = n.filter((e) => e.level === "error");
446
+ if (r.length > 0) throw new $(r);
447
+ return n;
448
+ };
449
+ //#endregion
450
+ //#region ../sdk-shared/dist/project/root.mjs
451
+ var i = ["package.json", "src/"];
452
+ var a = class extends Error {
453
+ constructor(e, t) {
454
+ super(`${e} is not the root of a Plitzi project: it has no ${t.join(" and no ")}. Run it from the project's root, the folder its package.json is in — where its scripts run it (npm start, npm run author).`), this.name = "ProjectRootError";
455
+ }
456
+ };
457
+ Object.defineProperty(a, "name", { value: "ProjectRootError" });
458
+ var o = (e) => {
459
+ let r = i.filter((r) => !existsSync(m.join(e, r)));
460
+ if (r.length > 0) throw new a(e, r);
461
+ return e;
462
+ };
463
+ var s = () => o(process.cwd());
464
+ var c = (e) => {
465
+ try {
466
+ return realpathSync(e);
467
+ } catch {
468
+ return m.resolve(e);
469
+ }
470
+ };
471
+ var l = (n, r, i) => {
472
+ let a = c(m.join(n, v$1)), o = i !== void 0 && c(i).startsWith(`${a}${m.sep}`);
473
+ return m.join(n, o ? m.join(v$1, m.relative("src", r)).replace(/\.tsx?$/, ".js") : r);
474
+ };
475
+ //#endregion
5
476
  //#region src/node.ts
6
477
  /**
7
478
  * What only an author running on Node can do: read the project's own files. A separate entry, so the package's main
@@ -16,6 +487,8 @@ import { fileURLToPath, pathToFileURL } from "node:url";
16
487
  *
17
488
  * authorSpace(space, { data: publicData(new URL('../public/', import.meta.url)) }); // bindings held to the files
18
489
  * authorSpace(space, { serverData: projectData(new URL('./data/', import.meta.url)) }); // …and read on the server only
490
+ * authorSpace(space, await projectAuthoring()); // all of a CLI project's
491
+ * await authorProjectSpace(); // …and its own space, `src/space/index.ts`
19
492
  * ```
20
493
  */
21
494
  var pathOf = (where) => where instanceof URL ? fileURLToPath(where) : where;
@@ -32,16 +505,16 @@ var svgFile = (file) => {
32
505
  */
33
506
  var svgFiles = (folder) => {
34
507
  const at = pathOf(folder);
35
- return Object.fromEntries(readdirSync(at).filter((name) => name.toLowerCase().endsWith(".svg")).sort().map((name) => [path.basename(name, path.extname(name)), svgFile(path.join(at, name))]));
508
+ return Object.fromEntries(readdirSync(at).filter((name) => name.toLowerCase().endsWith(".svg")).sort().map((name) => [m.basename(name, m.extname(name)), svgFile(m.join(at, name))]));
36
509
  };
37
510
  /** A JSON file under `prefix`, read once from the same path inside `folder`; `undefined` for anything else. */
38
511
  var fileReader = (folder, prefix) => {
39
- const root = path.resolve(pathOf(folder));
512
+ const root = m.resolve(pathOf(folder));
40
513
  const read = /* @__PURE__ */ new Map();
41
514
  return (query) => {
42
515
  if (!query.startsWith(prefix) || query.startsWith("//") || query.includes("{{")) return;
43
- const file = path.resolve(root, `.${query.split(/[?#]/)[0].slice(prefix.length - 1)}`);
44
- if (!file.startsWith(`${root}${path.sep}`)) return;
516
+ const file = m.resolve(root, `.${query.split(/[?#]/)[0].slice(prefix.length - 1)}`);
517
+ if (!file.startsWith(`${root}${m.sep}`)) return;
45
518
  if (!read.has(file)) {
46
519
  let value;
47
520
  try {
@@ -66,9 +539,7 @@ var publicData = (folder) => fileReader(folder, "/");
66
539
  * never serves (`dataDir`) — for `authorSpace`'s `serverData`: bindings are held to the file, and a provider reading
67
540
  * one from the browser is refused.
68
541
  */
69
- var projectData = (folder) => fileReader(folder, e);
70
- /** The file a plugin folder declares itself in, as `plitzi add plugin` writes it. */
71
- var DECLARATION_FILE = "declaration.ts";
542
+ var projectData = (folder) => fileReader(folder, e$1);
72
543
  /**
73
544
  * The declaration of every plugin under `folder` — `src/plugins/<Name>/declaration.ts`, its default export — for
74
545
  * `authorSpace`'s `plugins`: what each fires, answers and reads. Found by folder, as the server finds the plugins
@@ -78,7 +549,7 @@ var DECLARATION_FILE = "declaration.ts";
78
549
  */
79
550
  var pluginDeclarations = async (folder) => {
80
551
  const root = pathOf(folder);
81
- const files = existsSync(root) ? readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => path.join(root, entry.name, DECLARATION_FILE)).filter((file) => existsSync(file)).sort() : [];
552
+ const files = existsSync(root) ? readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => m.join(root, entry.name, c$1)).filter((file) => existsSync(file)).sort() : [];
82
553
  return Promise.all(files.map(async (file) => {
83
554
  const loaded = await import(pathToFileURL(file).href);
84
555
  const declaration = typeof loaded === "object" && loaded !== null && "default" in loaded ? loaded.default : void 0;
@@ -86,5 +557,100 @@ var pluginDeclarations = async (folder) => {
86
557
  return declaration;
87
558
  }));
88
559
  };
560
+ /** The manifest of a plugin run as it was built, read; nothing when it cannot be — the layout check says why first. */
561
+ var manifestOf = (file) => {
562
+ try {
563
+ const manifest = JSON.parse(readFileSync(file, "utf-8"));
564
+ return e(manifest) ? manifest : {};
565
+ } catch {
566
+ return {};
567
+ }
568
+ };
569
+ /**
570
+ * The element types of the plugins a project runs as they were built (`vendor/plugins/<type>/`, a project made from a
571
+ * space): each folder's type and every element its manifest provides (`pluginSchema`). None in most projects.
572
+ */
573
+ var builtPluginTypes = (folder) => existsSync(folder) ? readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name)).flatMap((entry) => {
574
+ const { pluginSchema } = manifestOf(m.join(folder, entry.name, d));
575
+ return [entry.name, ...e(pluginSchema) ? Object.keys(pluginSchema) : []];
576
+ }) : [];
577
+ /**
578
+ * What `authorSpace` checks the space of a project `@plitzi/cli` writes against, read from the project the process runs
579
+ * — so its server, `npm run author` and the CLI's checks hold the space to the same thing:
580
+ *
581
+ * - `plugins`: every plugin folder's declaration (`src/plugins/<Name>/declaration.ts`, `pluginDeclarations`);
582
+ * - `pluginTypes`: the element types of the plugins it runs as they were built (`vendor/plugins/`);
583
+ * - `serverData`: the project's own data, which only its server reads (`src/data/`, `projectData`) — a server-mode
584
+ * project's; one with no server has no such folder, and its providers read `public/data/` from the browser;
585
+ * - `data`: the JSON files it serves (`public/`, `publicData`).
586
+ *
587
+ * A folder the project does not have is nothing to check against. The project is the working directory — its scripts
588
+ * run there, `npm start` and `npm run author` alike — and a process started anywhere else is refused, saying what is
589
+ * missing (`projectRoot` of `@plitzi/sdk-shared/project/root`, the check its server makes too). So is a project laid out
590
+ * where nothing reads it — a plugin folder with no `index.ts`, code in `src/plugin/`, `.env` in `src/` — every error at
591
+ * once (`assertProjectLayout` of `@plitzi/sdk-shared/project/layout`, what its server and `plitzi doctor` say too).
592
+ *
593
+ * ```ts
594
+ * authorSpace(space, await projectAuthoring());
595
+ * ```
596
+ */
597
+ var projectAuthoring = async () => projectAuthoringAt(s());
598
+ /**
599
+ * `projectAuthoring` of the project at `root`, held to the same check: for a tool that works on a project from another
600
+ * folder — the CLI, run anywhere inside one. A project's own code calls `projectAuthoring()`.
601
+ */
602
+ var projectAuthoringAt = async (root) => {
603
+ const at = o(root);
604
+ de(at, { space: "local" });
605
+ const serverData = m.join(at, m$1);
606
+ return {
607
+ plugins: await pluginDeclarations(m.join(at, o$1)),
608
+ pluginTypes: builtPluginTypes(m.join(at, u)),
609
+ ...existsSync(serverData) ? { serverData: projectData(serverData) } : {},
610
+ data: publicData(m.join(at, p))
611
+ };
612
+ };
613
+ /** A project whose space module (`src/space/index.ts`) exports no space: its message says what to export. */
614
+ var ProjectSpaceError = class extends Error {
615
+ constructor(module) {
616
+ super(`${module} exports no \`space\`: the space's declaration, \`export const space: SpaceSpec = { name, permanentUrl, pages, … }\` — what the server, \`npm run author\` and the CLI's checks read.`);
617
+ this.name = "ProjectSpaceError";
618
+ }
619
+ };
620
+ Object.defineProperty(ProjectSpaceError, "name", { value: "ProjectSpaceError" });
621
+ /**
622
+ * What the module exports as `space`, taken as a declaration when it has the shape of one. `authorSpace` checks the
623
+ * rest of it, field by field, and says what is wrong — so this only has to tell a space from anything else.
624
+ */
625
+ var isSpaceSpec = (value) => e(value) && typeof value.name === "string" && typeof value.permanentUrl === "string" && Array.isArray(value.pages);
626
+ /**
627
+ * `projectSpace` of the project at `root`, held to the same checks: for a tool that works on a project from another
628
+ * folder — the CLI, run anywhere inside one. A project's own code calls `projectSpace()` or `authorProjectSpace()`.
629
+ */
630
+ var projectSpaceAt = async (root) => {
631
+ const authoring = await projectAuthoringAt(root);
632
+ const module = await import(pathToFileURL(l(root, a$1, process.argv[1])).href);
633
+ const space = e(module) ? module.space : void 0;
634
+ if (!isSpaceSpec(space)) throw new ProjectSpaceError(a$1);
635
+ return {
636
+ space,
637
+ authoring
638
+ };
639
+ };
640
+ /**
641
+ * The space of the project this process runs — `src/space/index.ts`'s `space` — with what it is checked against, once
642
+ * the project's root and layout are (`projectAuthoring`). Imported only then, so a factory that refuses what it is
643
+ * given as the space's files load is said like the rest — the message, not a stack. A module that exports no space is
644
+ * refused, saying what to export (`ProjectSpaceError`).
645
+ */
646
+ var projectSpace = async () => projectSpaceAt(s());
647
+ /**
648
+ * The project's space, authored: what a project's server serves — `serveProject({ space: authorProjectSpace })` — and
649
+ * its visual tests read. `projectSpace`, then `authorSpace` with what it is checked against.
650
+ */
651
+ var authorProjectSpace = async () => {
652
+ const { space, authoring } = await projectSpace();
653
+ return authorSpace(space, authoring);
654
+ };
89
655
  //#endregion
90
- export { compactSvg, pluginDeclarations, projectData, publicData, svgFile, svgFiles };
656
+ export { ProjectSpaceError, authorProjectSpace, compactSvg, pluginDeclarations, projectAuthoring, projectAuthoringAt, projectData, projectSpace, projectSpaceAt, publicData, svgFile, svgFiles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-authoring",
3
- "version": "0.38.6",
3
+ "version": "0.38.7",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist/index.js",
@@ -53,12 +53,12 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@microsoft/api-extractor": "^7.59.3",
56
- "@plitzi/plitzi-ui": "^1.6.31",
57
- "@plitzi/sdk-elements": "0.38.6",
58
- "@plitzi/sdk-interactions": "0.38.6",
59
- "@plitzi/sdk-schema": "0.38.6",
60
- "@plitzi/sdk-shared": "0.38.6",
61
- "@plitzi/sdk-style": "0.38.6",
56
+ "@plitzi/plitzi-ui": "^1.6.32",
57
+ "@plitzi/sdk-elements": "0.38.7",
58
+ "@plitzi/sdk-interactions": "0.38.7",
59
+ "@plitzi/sdk-schema": "0.38.7",
60
+ "@plitzi/sdk-shared": "0.38.7",
61
+ "@plitzi/sdk-style": "0.38.7",
62
62
  "@types/react": "^19.3.0",
63
63
  "eslint": "^9.39.5",
64
64
  "prettier": "^3.9.9",