@plitzi/sdk-authoring 0.38.23 → 0.39.0
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/CHANGELOG.md +162 -1
- package/dist/index-src.js +27619 -16681
- package/dist/index.d.ts +2750 -694
- package/dist/index.js +2 -2
- package/dist/node.d.ts +1283 -559
- package/dist/node.js +511 -289
- package/dist/plugin.d.ts +57 -1
- package/package.json +8 -8
- package/skills/plitzi-authoring/CHEATSHEET.md +6 -6
- package/skills/plitzi-authoring/SKILL.md +4 -2
- package/skills/plitzi-authoring/recipes/accordion.ts +2 -1
- package/skills/plitzi-authoring/recipes/carousel.ts +24 -3
- package/skills/plitzi-authoring/recipes/detail-page.ts +0 -1
- package/skills/plitzi-authoring/recipes/embed-and-svg.ts +3 -1
- package/skills/plitzi-authoring/recipes/filter-a-list.ts +0 -1
- package/skills/plitzi-authoring/recipes/show-data.ts +0 -1
- package/skills/plitzi-authoring/recipes/typed-data.ts +0 -1
- package/skills/plitzi-authoring/reference/accessibility.md +7 -2
- package/skills/plitzi-authoring/reference/auth.md +15 -4
- package/skills/plitzi-authoring/reference/authoring-errors.md +51 -10
- package/skills/plitzi-authoring/reference/colours-and-motion.md +7 -1
- package/skills/plitzi-authoring/reference/components.md +4 -1
- package/skills/plitzi-authoring/reference/data-and-visibility.md +31 -22
- package/skills/plitzi-authoring/reference/efficiency.md +2 -1
- package/skills/plitzi-authoring/reference/elements-and-styles.md +16 -15
- package/skills/plitzi-authoring/reference/flows.md +20 -8
- package/skills/plitzi-authoring/reference/kept-state.md +8 -0
- package/skills/plitzi-authoring/reference/layouts.md +18 -2
- package/skills/plitzi-authoring/reference/lists.md +20 -4
- package/skills/plitzi-authoring/reference/plugin-reach.md +12 -0
- package/skills/plitzi-authoring/reference/plugins.md +13 -2
- package/skills/plitzi-authoring/reference/realtime.md +8 -5
- package/skills/plitzi-authoring/reference/structure.md +17 -1
- package/skills/plitzi-authoring/reference/templates.md +11 -3
- package/skills/plitzi-authoring/reference/testing.md +82 -5
- package/skills/plitzi-authoring/reference/typed-sources.md +6 -0
- package/skills/plitzi-authoring/reference/validation.md +1 -1
package/dist/node.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ar as t$1, Cr as g$1, Do as element, Dr as o$3, Er as m$2, Ir as buildHandles, Ka as container, Kr as s$3, Mr as v$1, Nr as y$1, Or as p$2, So as component, Sr as f$2, Tr as l$3, _r as S$1, br as c$3, gr as N$1, hr as M$1, hs as J, jr as u$3, kr as s$4, l as validateSpace, n as authorSpace, u as compactSvg, vr as _, wr as j$1, xr as d$2, xs as e$2, yr as b$1 } from "./index-src.js";
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
3
|
-
import
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import e from "node:path";
|
|
4
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import "node:crypto";
|
|
5
7
|
import { spawn } from "node:child_process";
|
|
6
|
-
//#region ../sdk-shared/dist/project/layout.mjs
|
|
7
|
-
var
|
|
8
|
+
//#region ../sdk-shared/dist/project/layout/codes.mjs
|
|
9
|
+
var e$1 = {
|
|
8
10
|
"plugin-entry-missing": {
|
|
9
11
|
level: "error",
|
|
10
12
|
means: "a folder of src/plugins/ with no index.ts (or index.tsx), which the server builds the plugin from"
|
|
@@ -31,11 +33,11 @@ var v = {
|
|
|
31
33
|
},
|
|
32
34
|
"plugin-functions-entry-missing": {
|
|
33
35
|
level: "error",
|
|
34
|
-
means: "a plugin’s functions/ with code and no
|
|
36
|
+
means: "a plugin’s functions/ with code and no file at its top, which its server half is built from"
|
|
35
37
|
},
|
|
36
38
|
"functions-entry-missing": {
|
|
37
39
|
level: "error",
|
|
38
|
-
means: "src/functions/ with code and no
|
|
40
|
+
means: "src/functions/ with code and no file at its top, which the project’s functions are built from"
|
|
39
41
|
},
|
|
40
42
|
"runtime-entry-missing": {
|
|
41
43
|
level: "error",
|
|
@@ -102,56 +104,58 @@ var v = {
|
|
|
102
104
|
means: "a file in public/ named like a secret (.env, a key, a dump): served to anyone who asks"
|
|
103
105
|
}
|
|
104
106
|
};
|
|
105
|
-
var
|
|
106
|
-
level:
|
|
107
|
-
code:
|
|
108
|
-
file:
|
|
109
|
-
message:
|
|
110
|
-
fix:
|
|
111
|
-
...
|
|
107
|
+
var t = (t, n, r, i, a) => ({
|
|
108
|
+
level: e$1[t].level,
|
|
109
|
+
code: t,
|
|
110
|
+
file: n,
|
|
111
|
+
message: r,
|
|
112
|
+
fix: i,
|
|
113
|
+
...a ? { autofix: a } : {}
|
|
112
114
|
});
|
|
113
|
-
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region ../sdk-shared/dist/project/layout/files.mjs
|
|
117
|
+
var r$1 = /* @__PURE__ */ new Set([
|
|
114
118
|
".gitkeep",
|
|
115
119
|
"README.md",
|
|
116
120
|
".DS_Store"
|
|
117
121
|
]);
|
|
118
|
-
var
|
|
119
|
-
var
|
|
120
|
-
var
|
|
121
|
-
let
|
|
122
|
+
var i$1 = /^index\.(?:js|jsx|mjs|cjs)$/;
|
|
123
|
+
var a$2 = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
124
|
+
var o$2 = (r) => {
|
|
125
|
+
let i = {
|
|
122
126
|
files: [],
|
|
123
127
|
folders: []
|
|
124
128
|
};
|
|
125
129
|
try {
|
|
126
|
-
for (let
|
|
127
|
-
let
|
|
128
|
-
|
|
130
|
+
for (let a of readdirSync(r, { withFileTypes: !0 })) {
|
|
131
|
+
let t = a.isSymbolicLink() ? statSync(e.join(r, a.name), { throwIfNoEntry: !1 }) : void 0;
|
|
132
|
+
a.isFile() || t?.isFile() ? i.files.push(a.name) : (a.isDirectory() || t?.isDirectory()) && i.folders.push(a.name);
|
|
129
133
|
}
|
|
130
134
|
} catch {
|
|
131
|
-
return
|
|
135
|
+
return i;
|
|
132
136
|
}
|
|
133
137
|
return {
|
|
134
|
-
files:
|
|
135
|
-
folders:
|
|
138
|
+
files: i.files.sort(),
|
|
139
|
+
folders: i.folders.sort()
|
|
136
140
|
};
|
|
137
141
|
};
|
|
138
|
-
var
|
|
139
|
-
let
|
|
140
|
-
for (let [
|
|
141
|
-
let { files:
|
|
142
|
-
if (!(
|
|
143
|
-
|
|
142
|
+
var s$2 = (t, n, r) => {
|
|
143
|
+
let i = n.split("/").filter((e) => e !== "" && e !== "."), a = t;
|
|
144
|
+
for (let [t, n] of i.entries()) {
|
|
145
|
+
let { files: s, folders: c } = o$2(a);
|
|
146
|
+
if (!(t === i.length - 1 && r === "file" ? s : c).includes(n)) return !1;
|
|
147
|
+
a = e.join(a, n);
|
|
144
148
|
}
|
|
145
149
|
return !0;
|
|
146
150
|
};
|
|
147
|
-
var
|
|
148
|
-
let { files:
|
|
149
|
-
return [...
|
|
151
|
+
var c$2 = (t, n, r = /* @__PURE__ */ new Set()) => {
|
|
152
|
+
let { files: i, folders: a } = o$2(e.join(t, n));
|
|
153
|
+
return [...i.map((e) => `${n}/${e}`), ...a.filter((e) => !r.has(e)).flatMap((e) => c$2(t, `${n}/${e}`, r))];
|
|
150
154
|
};
|
|
151
|
-
var
|
|
152
|
-
var
|
|
153
|
-
var
|
|
154
|
-
var
|
|
155
|
+
var l$2 = ({ files: e, folders: t }) => t.length > 0 || e.some((e) => !r$1.has(e));
|
|
156
|
+
var u$2 = (e, t) => e.toLowerCase() === t.toLowerCase();
|
|
157
|
+
var d$1 = (e) => `${e.charAt(0).toUpperCase()}${e.slice(1)}`;
|
|
158
|
+
var f$1 = (e, t) => {
|
|
155
159
|
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)));
|
|
156
160
|
for (let r = 1; r <= e.length; r++) for (let i = 1; i <= t.length; i++) {
|
|
157
161
|
let a = e[r - 1] === t[i - 1] ? 0 : 1;
|
|
@@ -159,263 +163,277 @@ var O = (e, t) => {
|
|
|
159
163
|
}
|
|
160
164
|
return n[e.length][t.length];
|
|
161
165
|
};
|
|
162
|
-
var
|
|
166
|
+
var p$1 = (e, t) => {
|
|
163
167
|
if (e === t) return !1;
|
|
164
168
|
let n = e.toLowerCase(), r = t.toLowerCase();
|
|
165
|
-
return n === r || n === `${r}s` || `${n}s` === r || r.length >= 5 &&
|
|
166
|
-
};
|
|
167
|
-
var
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (s
|
|
179
|
-
let
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
169
|
+
return n === r || n === `${r}s` || `${n}s` === r || r.length >= 5 && f$1(n, r) <= 1;
|
|
170
|
+
};
|
|
171
|
+
var m$1 = "macOS and Windows disks ignore case, so it is found there — and not on Linux, where the project is deployed.";
|
|
172
|
+
var h$1 = (e, t) => u$2(e, t) ? `git mv ${e} ${e}-tmp && git mv ${e}-tmp ${t}` : `git mv ${e} ${t}`;
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region ../sdk-shared/dist/project/layout/vendor.mjs
|
|
175
|
+
var s$1 = (t) => e$2(t.assets) ? Object.values(t.assets).flatMap((t) => e$2(t) && typeof t.src == "string" && typeof t.type == "string" ? [{
|
|
176
|
+
src: t.src,
|
|
177
|
+
type: t.type,
|
|
178
|
+
isMain: t.isMain === !0
|
|
179
|
+
}] : []) : [];
|
|
180
|
+
var c$1 = (c, l) => {
|
|
181
|
+
let u = `${p$2}/${l}`, d = `${u}/${m$2}`, f = `npx plitzi space pull brings it again — or delete ${u}/, and the space renders no ${l}.`;
|
|
182
|
+
if (!s$2(c, d, "file")) return { problem: t("vendor-manifest-missing", `${u}/`, `${u}/ has no ${m$2}: the server runs a built plugin by what its manifest names, so ${l} does not run.`, f) };
|
|
183
|
+
let p;
|
|
184
|
+
try {
|
|
185
|
+
p = JSON.parse(readFileSync(e.join(c, d), "utf-8"));
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return { problem: t("vendor-manifest-invalid", d, `${d} is not JSON (${e instanceof Error ? e.message : String(e)}), so ${l} does not run.`, f) };
|
|
188
|
+
}
|
|
189
|
+
if (!e$2(p)) return { problem: t("vendor-manifest-invalid", d, `${d} is not a manifest, so ${l} does not run.`, f) };
|
|
190
|
+
let m = s$1(p), h = m.find((e) => e.type === "script" && e.isMain) ?? m.find((e) => e.type === "script");
|
|
191
|
+
if (!h) return { problem: t("vendor-script-missing", d, `${d} names no script to run, so ${l} does not run.`, f) };
|
|
192
|
+
if (!s$2(c, e.posix.join(u, h.src), "file")) return { problem: t("vendor-script-missing", d, `${d} names ${h.src} as the script to run, and ${u}/${h.src} is not there, so ${l} does not run.`, f) };
|
|
193
|
+
let g = m.find((e) => e.type === "style");
|
|
194
|
+
return {
|
|
195
|
+
script: e.join(c, u, h.src),
|
|
196
|
+
...g ? { style: e.join(c, u, g.src) } : {},
|
|
197
|
+
version: typeof p.version == "string" ? p.version : "1.0.0",
|
|
198
|
+
...typeof p.functions == "string" ? { functions: e.join(c, u, p.functions) } : {}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region ../sdk-shared/dist/project/layout/plugins.mjs
|
|
203
|
+
var b = (e) => `${e.charAt(0).toLowerCase()}${e.slice(1)}`;
|
|
204
|
+
var x$1 = (e) => {
|
|
205
|
+
let t = e.split(/[^A-Za-z0-9]+/).filter(Boolean).map(d$1).join(""), n = /^\d+/.exec(t)?.[0] ?? "", r = `${d$1(t.slice(n.length))}${n}`;
|
|
206
|
+
return a$2.test(r) ? r : void 0;
|
|
207
|
+
};
|
|
208
|
+
var w$1 = (e) => e.length > 1 ? `${e[0]} (or ${e.slice(1).join(", ")})` : e[0];
|
|
209
|
+
var T$1 = (e$16, i) => {
|
|
210
|
+
let { folder: a, accepted: o, code: u, lost: p } = i, m = o$2(e.join(e$16, a)), h = o.filter((e) => m.files.includes(e));
|
|
211
|
+
if (h.length === 1) return [];
|
|
212
|
+
if (h.length > 1) return [t("plugin-entry-ambiguous", `${a}/`, `${a}/ has both ${h.join(" and ")}, and a plugin is built from one of them.`, `Keep one — ${h[h.length - 1]} when it writes JSX — and delete the other.`)];
|
|
213
|
+
let g = m.files.find((e) => i$1.test(e));
|
|
214
|
+
if (g) {
|
|
215
|
+
let e = g.endsWith(".jsx") && o.includes("index.tsx") ? "index.tsx" : "index.ts";
|
|
216
|
+
return [t("entry-not-typescript", `${a}/${g}`, `${a}/${g} is JavaScript, and ${a}/ is built from ${w$1(o)}: the project's code is TypeScript, so ${p}.`, `Rename it ${e} — JavaScript is TypeScript already, types left out: ${h$1(`${a}/${g}`, `${a}/${e}`)}`, {
|
|
183
217
|
action: "move",
|
|
184
|
-
from: `${
|
|
185
|
-
to: `${
|
|
218
|
+
from: `${a}/${g}`,
|
|
219
|
+
to: `${a}/${e}`
|
|
186
220
|
})];
|
|
187
221
|
}
|
|
188
|
-
let
|
|
189
|
-
if (
|
|
190
|
-
let e =
|
|
191
|
-
return [
|
|
222
|
+
let _ = m.files.find((e) => o.some((t) => p$1(e, t)));
|
|
223
|
+
if (_) {
|
|
224
|
+
let e = o.find((e) => p$1(_, e)) ?? o[0];
|
|
225
|
+
return [t(u, `${a}/${_}`, `${a}/ has no ${e} — did you mean ${_}? Named otherwise, ${p}.${u$2(_, e) ? ` ${m$1}` : ""}`, `Rename it ${e}: ${h$1(`${a}/${_}`, `${a}/${e}`)}`, {
|
|
192
226
|
action: "move",
|
|
193
|
-
from: `${
|
|
194
|
-
to: `${
|
|
227
|
+
from: `${a}/${_}`,
|
|
228
|
+
to: `${a}/${e}`
|
|
195
229
|
})];
|
|
196
230
|
}
|
|
197
|
-
let
|
|
198
|
-
return
|
|
231
|
+
let v = m.folders.find((t) => o.some((n) => s$2(e$16, `${a}/${t}/${n}`, "file")));
|
|
232
|
+
return v ? [t(u, `${a}/${v}/`, `${a}/ has no ${w$1(o)}, and ${a}/${v}/ has: one folder too deep, so ${p}.`, `Move what ${a}/${v}/ holds up into ${a}/.`, {
|
|
199
233
|
action: "move",
|
|
200
|
-
from: `${
|
|
201
|
-
to: `${
|
|
202
|
-
})] : [
|
|
203
|
-
};
|
|
204
|
-
var
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
234
|
+
from: `${a}/${v}/`,
|
|
235
|
+
to: `${a}/`
|
|
236
|
+
})] : [t(u, `${a}/`, `${a}/ has no ${w$1(o)}, so ${p}.`, i.write)];
|
|
237
|
+
};
|
|
238
|
+
var E$1 = (n, r) => {
|
|
239
|
+
let i = o$2(e.join(n, r.folder));
|
|
240
|
+
if (!l$2(i) || i.files.some(s$3)) return [];
|
|
241
|
+
let a = i.folders.find((t) => o$2(e.join(n, r.folder, t)).files.some(s$3));
|
|
242
|
+
return [t(r.code, `${r.folder}/${a === void 0 ? "" : `${a}/`}`, `${r.folder}/ has no file at its top${a === void 0 ? "" : `, and ${r.folder}/${a}/ has: a folder there is helpers`}, so ${r.lost}.`, r.write)];
|
|
243
|
+
};
|
|
244
|
+
var D$1 = (e$17, t) => l$2(o$2(e.join(e$17, t.folder))) ? T$1(e$17, t) : [];
|
|
245
|
+
var O = (e) => {
|
|
246
|
+
let n = x$1(e), r = `${l$3}/${e}`;
|
|
247
|
+
return t("plugin-name-invalid", `${r}/`, `${r}/ cannot be a plugin: a folder of ${l$3}/ is registered as the element type its name makes, and a type is a letter followed by letters and digits.${n ? ` Did you mean ${n}?` : ""}`, n ? `Rename it ${n} — the type ${b(n)}: ${h$1(r, `${l$3}/${n}`)}; then type: '${b(n)}' in its ${d$2}, and renderType: '${b(n)}' where the space renders it.` : "Rename it with letters and digits, starting with a letter: StatCard is the type statCard.");
|
|
248
|
+
};
|
|
249
|
+
var k = (e, t) => e.find((e) => e === `${t}.tsx`) ?? e.find((e) => e === `${t}.ts`);
|
|
250
|
+
var A = (e$18, r) => {
|
|
251
|
+
let i = `${l$3}/${r}`, { files: a } = o$2(e.join(e$18, i));
|
|
252
|
+
if (a.includes("declaration.ts")) return [];
|
|
253
|
+
let o = b(r), c = `authoring holds none of the space's ${o} elements to its attributes, and the builder does not offer it`, u = a.find((e) => p$1(e, d$2));
|
|
254
|
+
return u ? [t("plugin-declaration-missing", `${i}/${u}`, `${i}/ has no ${d$2} — did you mean ${u}? Named otherwise, ${c}.${u$2(u, "declaration.ts") ? ` ${m$1}` : ""}`, `Rename it ${d$2}: ${h$1(`${i}/${u}`, `${i}/${d$2}`)}`, {
|
|
215
255
|
action: "move",
|
|
216
|
-
from: `${
|
|
217
|
-
to: `${
|
|
218
|
-
})] : [
|
|
256
|
+
from: `${i}/${u}`,
|
|
257
|
+
to: `${i}/${d$2}`
|
|
258
|
+
})] : [t("plugin-declaration-missing", `${i}/`, `${i}/ has no ${d$2}: ${c}.`, `Write ${i}/${d$2} — export default { type: '${o}', … } — as npx plitzi plugin add writes one beside the component it makes.`)];
|
|
219
259
|
};
|
|
220
|
-
var
|
|
221
|
-
if (!
|
|
222
|
-
let n = `${
|
|
260
|
+
var j = (e$19, t) => {
|
|
261
|
+
if (!a$2.test(t)) return [O(t)];
|
|
262
|
+
let n = `${l$3}/${t}`, r = b(t), i = k(o$2(e.join(e$19, n)).files, t);
|
|
223
263
|
return [
|
|
224
|
-
...
|
|
264
|
+
...T$1(e$19, {
|
|
225
265
|
folder: n,
|
|
226
|
-
accepted:
|
|
266
|
+
accepted: u$3,
|
|
227
267
|
code: "plugin-entry-missing",
|
|
228
268
|
lost: `the server cannot build the plugin ${r}`,
|
|
229
|
-
write: `Write ${n}/index.ts exporting the component by default${
|
|
269
|
+
write: `Write ${n}/index.ts exporting the component by default${i ? ` — export { default } from './${i}';` : ""} — as npx plitzi plugin add writes it. Every folder of ${l$3}/ is a plugin: code several plugins share goes outside it (src/shared/).`
|
|
230
270
|
}),
|
|
231
|
-
...
|
|
232
|
-
folder: `${n}/${
|
|
233
|
-
accepted: ["index.ts"],
|
|
271
|
+
...E$1(e$19, {
|
|
272
|
+
folder: `${n}/${f$2}`,
|
|
234
273
|
code: "plugin-functions-entry-missing",
|
|
235
274
|
lost: `none of the plugin's server half runs (its routes under /fn/plugins/${r}/)`,
|
|
236
|
-
write: `Write ${n}/${
|
|
275
|
+
write: `Write ${n}/${f$2}/index.ts exporting defineFunctions({ … }) by default — as npx plitzi plugin add --server writes it.`
|
|
237
276
|
}),
|
|
238
|
-
...
|
|
277
|
+
...A(e$19, t)
|
|
239
278
|
];
|
|
240
279
|
};
|
|
241
|
-
var
|
|
242
|
-
let
|
|
243
|
-
for (let
|
|
244
|
-
return [...
|
|
245
|
-
};
|
|
246
|
-
var H = (t) => e(t.assets) ? Object.values(t.assets).flatMap((t) => e(t) && typeof t.src == "string" && typeof t.type == "string" ? [{
|
|
247
|
-
src: t.src,
|
|
248
|
-
type: t.type,
|
|
249
|
-
isMain: t.isMain === !0
|
|
250
|
-
}] : []) : [];
|
|
251
|
-
var U = (t, n) => {
|
|
252
|
-
let r = `${u}/${n}`, i = `${r}/${d}`, a = `npx plitzi space pull brings it again — or delete ${r}/, and the space renders no ${n}.`;
|
|
253
|
-
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) };
|
|
254
|
-
let o;
|
|
255
|
-
try {
|
|
256
|
-
o = JSON.parse(readFileSync(m.join(t, i), "utf-8"));
|
|
257
|
-
} catch (e) {
|
|
258
|
-
return { problem: y("vendor-manifest-invalid", i, `${i} is not JSON (${e instanceof Error ? e.message : String(e)}), so ${n} does not run.`, a) };
|
|
259
|
-
}
|
|
260
|
-
if (!e(o)) return { problem: y("vendor-manifest-invalid", i, `${i} is not a manifest, so ${n} does not run.`, a) };
|
|
261
|
-
let s = H(o), l = s.find((e) => e.type === "script" && e.isMain) ?? s.find((e) => e.type === "script");
|
|
262
|
-
if (!l) return { problem: y("vendor-script-missing", i, `${i} names no script to run, so ${n} does not run.`, a) };
|
|
263
|
-
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) };
|
|
264
|
-
let u$1 = s.find((e) => e.type === "style");
|
|
265
|
-
return {
|
|
266
|
-
script: m.join(t, r, l.src),
|
|
267
|
-
...u$1 ? { style: m.join(t, r, u$1.src) } : {},
|
|
268
|
-
version: typeof o.version == "string" ? o.version : "1.0.0",
|
|
269
|
-
...typeof o.functions == "string" ? { functions: m.join(t, r, o.functions) } : {}
|
|
270
|
-
};
|
|
280
|
+
var M = (e) => {
|
|
281
|
+
let n = /* @__PURE__ */ new Map();
|
|
282
|
+
for (let t of e.filter((e) => a$2.test(e))) n.set(b(t), [...n.get(b(t)) ?? [], t]);
|
|
283
|
+
return [...n].flatMap(([e, n]) => n.slice(1).map((r) => t("plugin-type-taken", `${l$3}/${r}/`, `${l$3}/${n[0]}/ and ${l$3}/${r}/ 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 ${l$3}/${r} ${l$3}/<AnotherName>`)));
|
|
271
284
|
};
|
|
272
|
-
var
|
|
273
|
-
let { files:
|
|
274
|
-
let { name:
|
|
275
|
-
return
|
|
276
|
-
}),
|
|
277
|
-
let n =
|
|
285
|
+
var N = (e$20) => {
|
|
286
|
+
let { files: n, folders: r } = o$2(e.join(e$20, l$3)), o = n.filter((e) => !r$1.has(e) && e !== "declarations.ts").map((e$21) => {
|
|
287
|
+
let { name: n } = e.parse(e$21), r = n !== "index" && x$1(n) || "<Name>";
|
|
288
|
+
return t("plugin-file-loose", `${l$3}/${e$21}`, `${l$3}/${e$21} is a file, and every plugin is a folder of ${l$3}/: the server reads nothing of it.`, `Give it a folder with an index.ts that exports it by default — ${l$3}/${r}/${e$21} and ${l$3}/${r}/index.ts, as npx plitzi plugin add writes them — or move it out of ${l$3}/.`);
|
|
289
|
+
}), c = o$2(e.join(e$20, p$2)).folders, l = new Set(r.filter((e) => a$2.test(e)).map(b)), u = c.filter((e) => l.has(e)).map((e) => t("plugin-shadowed", `${p$2}/${e}/`, `${e} is both ${p$2}/${e}/, as it was built, and a folder of ${l$3}/: the server runs the built one, and a change to the source shows nowhere.`, `Delete ${p$2}/${e}/: the source is the plugin now.`)), d = c.flatMap((t) => {
|
|
290
|
+
let n = c$1(e$20, t);
|
|
278
291
|
return "problem" in n ? [n.problem] : [];
|
|
279
292
|
});
|
|
280
293
|
return [
|
|
281
|
-
...
|
|
282
|
-
...
|
|
283
|
-
...
|
|
284
|
-
...
|
|
285
|
-
...
|
|
294
|
+
...r.flatMap((t) => j(e$20, t)),
|
|
295
|
+
...M(r),
|
|
296
|
+
...o,
|
|
297
|
+
...u,
|
|
298
|
+
...d
|
|
299
|
+
];
|
|
300
|
+
};
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region ../sdk-shared/dist/project/layout/contents.mjs
|
|
303
|
+
var l$1 = (e) => e.split("\n").map((e) => e.replace(/^(\s*(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=).*$/, "$1")).join("\n");
|
|
304
|
+
var u$1 = (t$4) => {
|
|
305
|
+
let i = o$2(t$4).files, a = i.includes(".env"), u = i.includes(".env.example"), d = c$2(t$4, "src", /* @__PURE__ */ new Set(["node_modules"])).filter((e$10) => e.posix.basename(e$10) === ".env"), f = !a && d.length === 1, p = d.map((t$3) => t("env-in-src", t$3, `${t$3} 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).`, f ? `Move it to the root: mv ${t$3} .env` : `Copy what it sets into the root's .env, then delete ${t$3}.`, f ? {
|
|
306
|
+
action: "move",
|
|
307
|
+
from: t$3,
|
|
308
|
+
to: ".env"
|
|
309
|
+
} : void 0)), m = `${e.resolve(t$4).split(e.sep).join("/")}/`.includes(`/${t$1}/`), h = a || m || p.length > 0 ? [] : [t("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.", u ? "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.", u ? {
|
|
310
|
+
action: "copy",
|
|
311
|
+
from: ".env.example",
|
|
312
|
+
to: ".env"
|
|
313
|
+
} : void 0)], g = u ? [] : [t("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.", a ? "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.", a ? {
|
|
314
|
+
action: "write",
|
|
315
|
+
file: ".env.example",
|
|
316
|
+
contents: l$1(readFileSync(e.join(t$4, ".env"), "utf-8"))
|
|
317
|
+
} : void 0)];
|
|
318
|
+
return [
|
|
319
|
+
...p,
|
|
320
|
+
...h,
|
|
321
|
+
...g
|
|
286
322
|
];
|
|
287
323
|
};
|
|
288
|
-
var
|
|
289
|
-
var
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
324
|
+
var d = (n) => c$2(n, _).filter((e$11) => !r$1.has(e.posix.basename(e$11)) && !e$11.endsWith(".json")).map((t$5) => t("data-not-json", t$5, `${t$5} is not JSON: a provider's /data/<file> and ctx.data read JSON files only, and plitzi space push leaves it behind.`, `Keep it as JSON (${t$5.replace(/\.[^./]*$/, "")}.json), or move it out of ${_}/.`));
|
|
325
|
+
var f = /^\.env(?:\..*)?$|\.(?:pem|key|p12|pfx|jks|keystore|sqlite3?|db|sql|dump)$|secret|credential|password|passwd|private[-_.]?key|id_rsa|id_ed25519|service[-_]?account/i;
|
|
326
|
+
var p = (t$7, n) => {
|
|
327
|
+
let o = c$2(t$7, g$1, /* @__PURE__ */ new Set(["node_modules"])), c = o.filter((e$12) => f.test(e.posix.basename(e$12))).map((t$6) => t("public-secret-file", t$6, `${t$6} is served to anyone who asks, as it is — everything in ${g$1}/ 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 ${g$1}/: settings go in the root's .env${n === "server" ? `, data only the server reads in ${_}/` : ""}.`)), l = `${g$1}/data`, u = n === "server" ? o.filter((e) => e.startsWith(`${l}/`) && e.endsWith(".json")) : [], d = u.slice(0, 3).map((e$13) => e.posix.basename(e$13)), p = u.length > 0 ? [t("public-data", `${l}/`, `${l}/ holds ${String(u.length)} JSON file${u.length === 1 ? "" : "s"} (${d.join(", ")}${u.length > d.length ? ", …" : ""}), served to anyone who asks: every visitor can read all of ${u.length === 1 ? "it" : "them"}, not only what a page shows.`, `Data only the server should read goes in ${_}/ — 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.`)] : [];
|
|
328
|
+
return [...c, ...p];
|
|
329
|
+
};
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region ../sdk-shared/dist/project/layout/folders.mjs
|
|
332
|
+
var x = (e, t) => t.map((t) => e.find((e) => u$2(e, t))).find((e) => e !== void 0);
|
|
333
|
+
var S = (e$5) => (t) => {
|
|
334
|
+
for (let n of o$2(e.join(e$5, t)).folders) {
|
|
335
|
+
let i = x(o$2(e.join(e$5, t, n)).files, [...u$3, d$2]);
|
|
336
|
+
if (i) return `${t}/${n}/${i}`;
|
|
293
337
|
}
|
|
294
338
|
};
|
|
295
|
-
var
|
|
296
|
-
let n =
|
|
339
|
+
var C = (e$6) => (t) => {
|
|
340
|
+
let n = x(o$2(e.join(e$6, t)).files, ["index.ts"]);
|
|
297
341
|
return n ? `${t}/${n}` : void 0;
|
|
298
342
|
};
|
|
299
|
-
var
|
|
343
|
+
var w = (e, { mode: t, space: n }) => [
|
|
300
344
|
{
|
|
301
|
-
at:
|
|
302
|
-
reads: `the server builds plugins from ${
|
|
303
|
-
holds:
|
|
345
|
+
at: l$3,
|
|
346
|
+
reads: `the server builds plugins from ${l$3}/ only`,
|
|
347
|
+
holds: S(e)
|
|
304
348
|
},
|
|
305
349
|
{
|
|
306
|
-
at:
|
|
307
|
-
reads: `the project's functions are built from ${
|
|
308
|
-
holds:
|
|
350
|
+
at: y$1,
|
|
351
|
+
reads: `the project's functions are built from ${y$1}/ only`,
|
|
352
|
+
holds: C(e)
|
|
309
353
|
},
|
|
310
354
|
{
|
|
311
|
-
at:
|
|
312
|
-
reads: `the space's runtime is run from ${
|
|
313
|
-
holds:
|
|
355
|
+
at: b$1,
|
|
356
|
+
reads: `the space's runtime is run from ${b$1}/ only`,
|
|
357
|
+
holds: C(e)
|
|
314
358
|
},
|
|
315
|
-
...
|
|
316
|
-
at:
|
|
317
|
-
reads: `the server's entry point and ${
|
|
318
|
-
holds:
|
|
359
|
+
...n === "local" ? [{
|
|
360
|
+
at: s$4,
|
|
361
|
+
reads: `the server's entry point and ${o$3} import the space from ${c$3}`,
|
|
362
|
+
holds: C(e)
|
|
319
363
|
}] : [],
|
|
320
|
-
...
|
|
321
|
-
at:
|
|
322
|
-
reads: `the server reads the project's data from ${
|
|
364
|
+
...t === "server" ? [{
|
|
365
|
+
at: _,
|
|
366
|
+
reads: `the server reads the project's data from ${_}/ only (/data/<file>, ctx.data)`
|
|
323
367
|
}] : [],
|
|
324
368
|
{
|
|
325
|
-
at:
|
|
326
|
-
reads: `the server serves ${
|
|
369
|
+
at: g$1,
|
|
370
|
+
reads: `the server serves ${g$1}/ only, at the site's root`
|
|
327
371
|
}
|
|
328
372
|
];
|
|
329
|
-
var
|
|
330
|
-
let n =
|
|
331
|
-
return [...
|
|
332
|
-
};
|
|
333
|
-
var
|
|
334
|
-
let
|
|
335
|
-
|
|
336
|
-
let
|
|
373
|
+
var T = (e$7, t) => {
|
|
374
|
+
let n = e.posix.dirname(t), i = e.posix.basename(t), a = n === "." ? "src" : ".", s = o$2(e.join(e$7, n)).folders.filter((e) => p$1(e, i)).map((e$8) => e.posix.join(n, e$8)), c = o$2(e.join(e$7, a)).folders.filter((e) => e === i || p$1(e, i)).map((e$9) => e.posix.join(a, e$9));
|
|
375
|
+
return [...s, ...c];
|
|
376
|
+
};
|
|
377
|
+
var E = (r, o) => w(r, o).flatMap(({ at: o, reads: c, holds: l }) => T(r, o).map((u) => {
|
|
378
|
+
let d = l?.(u), f = u$2(u, o), p = `did you mean ${o}/? ${d$1(c)}.${f ? ` ${m$1}` : ""}`, m = `Move it: ${h$1(u, o)}`;
|
|
379
|
+
f ? m = `Rename it: ${h$1(u, o)}` : s$2(r, o, "folder") && (m = `Move what it holds into ${o}/, and delete it.`);
|
|
380
|
+
let h = {
|
|
337
381
|
action: "move",
|
|
338
|
-
from: `${
|
|
339
|
-
to: `${
|
|
382
|
+
from: `${u}/`,
|
|
383
|
+
to: `${o}/`
|
|
340
384
|
};
|
|
341
|
-
return
|
|
385
|
+
return d ? t("folder-misplaced", `${u}/`, `${u}/ holds ${d}, and nothing reads it there — ${p}`, m, h) : t("folder-near-miss", `${u}/`, `${u}/ is read by nothing — ${p}`, m, h);
|
|
342
386
|
}));
|
|
343
|
-
var
|
|
344
|
-
if (!
|
|
345
|
-
folder:
|
|
387
|
+
var D = (t$2, n) => {
|
|
388
|
+
if (!s$2(t$2, "src/space/index.ts", "file")) return n.some((e) => e.code === "folder-misplaced" && e.autofix?.action === "move" && e.autofix.to === "src/space/") ? [] : T$1(t$2, {
|
|
389
|
+
folder: s$4,
|
|
346
390
|
accepted: ["index.ts"],
|
|
347
391
|
code: "space-entry-missing",
|
|
348
|
-
lost: `the server's entry point and ${
|
|
349
|
-
write: `Write ${
|
|
392
|
+
lost: `the server's entry point and ${o$3}, which import the space from ${c$3}, do not start`,
|
|
393
|
+
write: `Write ${c$3} exporting the space — export const space = { name, permanentUrl, pages } — or bring back the one git has: git checkout -- ${c$3}`
|
|
350
394
|
});
|
|
351
|
-
let r
|
|
352
|
-
return
|
|
353
|
-
};
|
|
354
|
-
var ie = (e) => e.split("\n").map((e) => e.replace(/^(\s*(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=).*$/, "$1")).join("\n");
|
|
355
|
-
var ae = (e) => {
|
|
356
|
-
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 ? {
|
|
357
|
-
action: "move",
|
|
358
|
-
from: e,
|
|
359
|
-
to: ".env"
|
|
360
|
-
} : 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 ? {
|
|
361
|
-
action: "copy",
|
|
362
|
-
from: ".env.example",
|
|
363
|
-
to: ".env"
|
|
364
|
-
} : 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 ? {
|
|
365
|
-
action: "write",
|
|
366
|
-
file: ".env.example",
|
|
367
|
-
contents: ie(readFileSync(m.join(e, ".env"), "utf-8"))
|
|
368
|
-
} : void 0)];
|
|
369
|
-
return [
|
|
370
|
-
...o,
|
|
371
|
-
...s,
|
|
372
|
-
...c
|
|
373
|
-
];
|
|
395
|
+
let r = readFileSync(e.join(t$2, c$3), "utf-8"), a = /^\s*export\s+default\b/m.test(r), o = /\bexport\s+(?:const|let|var|function)\s+space\b/.test(r) || /\bexport\s*\{[^}]*\bspace\b[^}]*\}/.test(r);
|
|
396
|
+
return a && !o ? [t("space-default-export", c$3, `${c$3} exports the space by default, and it is imported by name — import { space } from './space/index.ts' — so the server's entry point and ${o$3} find no space.`, "Export it as `export const space = …` instead of `export default …`.")] : [];
|
|
374
397
|
};
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
var
|
|
378
|
-
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.`)] : [];
|
|
379
|
-
return [...i, ...c];
|
|
380
|
-
};
|
|
381
|
-
var Z = (t) => {
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region ../sdk-shared/dist/project/layout/check.mjs
|
|
400
|
+
var m = (t) => {
|
|
382
401
|
try {
|
|
383
|
-
let n = JSON.parse(readFileSync(
|
|
384
|
-
return e(n) && [n.dependencies, n.devDependencies].some((t) => e(t) && "@plitzi/sdk-server" in t);
|
|
402
|
+
let n = JSON.parse(readFileSync(e.join(t, "package.json"), "utf-8"));
|
|
403
|
+
return e$2(n) && [n.dependencies, n.devDependencies].some((t) => e$2(t) && "@plitzi/sdk-server" in t);
|
|
385
404
|
} catch {
|
|
386
405
|
return !1;
|
|
387
406
|
}
|
|
388
407
|
};
|
|
389
|
-
var
|
|
390
|
-
mode:
|
|
391
|
-
space:
|
|
408
|
+
var h = (e, n) => ({
|
|
409
|
+
mode: n.mode ?? (m(e) ? "server" : "client"),
|
|
410
|
+
space: n.space ?? (s$2(e, "src/space", "folder") || s$2(e, ".plitzi/author.ts", "file") ? "local" : "cloud")
|
|
392
411
|
});
|
|
393
|
-
var
|
|
394
|
-
let
|
|
395
|
-
...
|
|
396
|
-
...
|
|
397
|
-
folder:
|
|
398
|
-
accepted: ["index.ts"],
|
|
412
|
+
var g = (e, t = {}) => {
|
|
413
|
+
let f = h(e, t), p$3 = E(e, f), m = [
|
|
414
|
+
...N(e),
|
|
415
|
+
...E$1(e, {
|
|
416
|
+
folder: y$1,
|
|
399
417
|
code: "functions-entry-missing",
|
|
400
418
|
lost: "none of the project’s functions runs",
|
|
401
|
-
write: `Write ${
|
|
419
|
+
write: `Write the domain's file at the top of ${y$1}/ (rooms.ts) exporting defineFunctions({ tasks: [ … ] }) by default — a domain a file, nothing to list.`
|
|
402
420
|
}),
|
|
403
|
-
...
|
|
404
|
-
folder:
|
|
421
|
+
...D$1(e, {
|
|
422
|
+
folder: b$1,
|
|
405
423
|
accepted: ["index.ts"],
|
|
406
424
|
code: "runtime-entry-missing",
|
|
407
425
|
lost: "the space’s runtime does not run",
|
|
408
|
-
write: `Write ${
|
|
426
|
+
write: `Write ${b$1}/index.ts exporting defineRuntime(…) by default — npx plitzi runtime add writes one.`
|
|
409
427
|
}),
|
|
410
|
-
...
|
|
411
|
-
...
|
|
412
|
-
...
|
|
413
|
-
...
|
|
414
|
-
...
|
|
428
|
+
...f.space === "local" ? D(e, p$3) : [],
|
|
429
|
+
...p$3,
|
|
430
|
+
...u$1(e),
|
|
431
|
+
...f.mode === "server" ? d(e) : [],
|
|
432
|
+
...p(e, f.mode)
|
|
415
433
|
];
|
|
416
|
-
return [...
|
|
434
|
+
return [...m.filter((e) => e.level === "error"), ...m.filter((e) => e.level === "warning")];
|
|
417
435
|
};
|
|
418
|
-
var
|
|
436
|
+
var v = class extends Error {
|
|
419
437
|
#e;
|
|
420
438
|
get findings() {
|
|
421
439
|
return this.#e;
|
|
@@ -425,45 +443,137 @@ var $ = class extends Error {
|
|
|
425
443
|
super(`The project is not laid out as Plitzi reads it — ${t}:\n\n${n}\n\n${a}`), this.name = "ProjectLayoutError", this.#e = e;
|
|
426
444
|
}
|
|
427
445
|
};
|
|
428
|
-
Object.defineProperty(
|
|
429
|
-
var
|
|
430
|
-
let n =
|
|
431
|
-
if (r.length > 0) throw new
|
|
446
|
+
Object.defineProperty(v, "name", { value: "ProjectLayoutError" });
|
|
447
|
+
var y = (e, t = {}) => {
|
|
448
|
+
let n = g(e, t), r = n.filter((e) => e.level === "error");
|
|
449
|
+
if (r.length > 0) throw new v(r);
|
|
432
450
|
return n;
|
|
433
451
|
};
|
|
434
452
|
//#endregion
|
|
435
453
|
//#region ../sdk-shared/dist/project/root.mjs
|
|
436
|
-
var
|
|
437
|
-
var
|
|
454
|
+
var a$1 = ["package.json", "src/"];
|
|
455
|
+
var o$1 = class extends Error {
|
|
438
456
|
constructor(e, t) {
|
|
439
457
|
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";
|
|
440
458
|
}
|
|
441
459
|
};
|
|
442
|
-
Object.defineProperty(
|
|
443
|
-
var
|
|
444
|
-
let r =
|
|
445
|
-
if (r.length > 0) throw new
|
|
446
|
-
return e;
|
|
460
|
+
Object.defineProperty(o$1, "name", { value: "ProjectRootError" });
|
|
461
|
+
var s = (e$3) => {
|
|
462
|
+
let r = a$1.filter((r) => !existsSync(e.join(e$3, r)));
|
|
463
|
+
if (r.length > 0) throw new o$1(e$3, r);
|
|
464
|
+
return e$3;
|
|
447
465
|
};
|
|
448
|
-
var
|
|
449
|
-
var
|
|
466
|
+
var c = () => s(process.cwd());
|
|
467
|
+
var l = (e$4) => {
|
|
450
468
|
try {
|
|
451
|
-
return realpathSync(e);
|
|
469
|
+
return realpathSync(e$4);
|
|
452
470
|
} catch {
|
|
453
|
-
return
|
|
471
|
+
return e.resolve(e$4);
|
|
454
472
|
}
|
|
455
473
|
};
|
|
456
|
-
var
|
|
457
|
-
let a =
|
|
458
|
-
return
|
|
474
|
+
var u = (n, r, i) => {
|
|
475
|
+
let a = l(e.join(n, S$1)), o = i !== void 0 && l(i).startsWith(`${a}${e.sep}`);
|
|
476
|
+
return e.join(n, o ? e.join(S$1, e.relative("src", r)).replace(/\.tsx?$/, ".js") : r);
|
|
477
|
+
};
|
|
478
|
+
//#endregion
|
|
479
|
+
//#region ../sdk-shared/dist/project/pages/index.mjs
|
|
480
|
+
var r = /\.(?:[cm]?[jt]sx?)$/;
|
|
481
|
+
var i = /\.(?:test|spec)\.[cm]?[jt]sx?$|\.d\.[cm]?ts$/;
|
|
482
|
+
var a = [
|
|
483
|
+
"index.ts",
|
|
484
|
+
"index.tsx",
|
|
485
|
+
"index.js"
|
|
486
|
+
];
|
|
487
|
+
var o = (o) => existsSync(o) ? readdirSync(o, { withFileTypes: !0 }).flatMap((n) => {
|
|
488
|
+
if (n.isFile()) return r.test(n.name) && !i.test(n.name) ? [e.join(o, n.name)] : [];
|
|
489
|
+
let s = n.isDirectory() ? a.find((r) => existsSync(e.join(o, n.name, r))) : void 0;
|
|
490
|
+
return s ? [e.join(o, n.name, s)] : [];
|
|
491
|
+
}).sort() : [];
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/preview.ts
|
|
494
|
+
/**
|
|
495
|
+
* Why the element asked to be drawn alone cannot be: a name that is no component or type, an address the space uses, a
|
|
496
|
+
* file that is not one. Its message is the whole report — a project's server says it alone, with no stack.
|
|
497
|
+
*/
|
|
498
|
+
var SpacePreviewError = class extends Error {
|
|
499
|
+
constructor(message, options) {
|
|
500
|
+
super(message, options);
|
|
501
|
+
this.name = "SpacePreviewError";
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
Object.defineProperty(SpacePreviewError, "name", { value: "SpacePreviewError" });
|
|
505
|
+
var PREVIEW_ID = M$1;
|
|
506
|
+
var BUILT_IN = new Set(Object.values(J).map((declaration) => declaration.type));
|
|
507
|
+
/** A preview file read as one, or why it is not, said whole. */
|
|
508
|
+
var parsePreview = (value) => {
|
|
509
|
+
if (!e$2(value) || typeof value.element !== "string" || value.element === "") return { problem: "it names no element: write { \"element\": \"<a component or an element type>\", \"copies\": [{ … }] }" };
|
|
510
|
+
const { element: name, copies } = value;
|
|
511
|
+
if (!Array.isArray(copies) || copies.length === 0 || !copies.every(e$2)) return { problem: `"copies" is not a list of objects: each copy is the props or the attributes of one "${name}" — [{}] draws one as it is declared` };
|
|
512
|
+
return {
|
|
513
|
+
element: name,
|
|
514
|
+
copies: copies.filter(e$2)
|
|
515
|
+
};
|
|
516
|
+
};
|
|
517
|
+
/**
|
|
518
|
+
* The space with a page of its own drawing `preview` alone, at `PREVIEW_SLUG`, in no layout — the space's theme, fonts
|
|
519
|
+
* and classes as any page has them. A page the space already answers there is refused: the preview would hide it.
|
|
520
|
+
*/
|
|
521
|
+
var withPreview = (space, preview, pluginTypes = []) => {
|
|
522
|
+
if (space.pages.some((page) => page.slug === "plitzi-preview" && page.folder === void 0)) throw new SpacePreviewError(`The space has a page at /${M$1} already: an element is drawn alone there — rename that page's slug to look at one`);
|
|
523
|
+
const components = (space.components ?? []).map((each) => each.id);
|
|
524
|
+
const isComponent = components.includes(preview.element);
|
|
525
|
+
if (!isComponent && !pluginTypes.includes(preview.element) && !BUILT_IN.has(preview.element)) throw new SpacePreviewError(`"${preview.element}" is no component of the space and no element type to draw alone: its components are ${components.join(", ") || "none"}; its plugins' elements ${pluginTypes.join(", ") || "none"} — or a built-in type (heading, container…)`);
|
|
526
|
+
const page = {
|
|
527
|
+
id: PREVIEW_ID,
|
|
528
|
+
name: `${preview.element}, alone`,
|
|
529
|
+
slug: M$1,
|
|
530
|
+
robots: "noindex, nofollow",
|
|
531
|
+
body: [container({
|
|
532
|
+
id: `${PREVIEW_ID}-copies`,
|
|
533
|
+
css: {
|
|
534
|
+
display: "flex",
|
|
535
|
+
"flex-direction": "column",
|
|
536
|
+
"row-gap": "48px",
|
|
537
|
+
padding: "48px 24px"
|
|
538
|
+
},
|
|
539
|
+
children: preview.copies.map((copy, index) => isComponent ? component(preview.element, {
|
|
540
|
+
id: N$1(index),
|
|
541
|
+
props: copy
|
|
542
|
+
}) : element(preview.element, {
|
|
543
|
+
...copy,
|
|
544
|
+
id: N$1(index)
|
|
545
|
+
}))
|
|
546
|
+
})]
|
|
547
|
+
};
|
|
548
|
+
return {
|
|
549
|
+
...space,
|
|
550
|
+
pages: [...space.pages, page]
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* The preview the process is started with (`PREVIEW_FILE_ENV`), read: undefined when it names none. A file that is not
|
|
555
|
+
* one is refused, saying what to write — never a space served without the page it was started to draw.
|
|
556
|
+
*/
|
|
557
|
+
var previewOfProcess = () => {
|
|
558
|
+
const file = process.env[j$1];
|
|
559
|
+
if (file === void 0 || file === "") return;
|
|
560
|
+
let value;
|
|
561
|
+
try {
|
|
562
|
+
value = JSON.parse(readFileSync(file, "utf-8"));
|
|
563
|
+
} catch (error) {
|
|
564
|
+
throw new SpacePreviewError(`${j$1} names ${file}, which is not JSON to read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
565
|
+
}
|
|
566
|
+
const preview = parsePreview(value);
|
|
567
|
+
if ("problem" in preview) throw new SpacePreviewError(`${j$1} names ${file}, which is not an element to draw alone: ${preview.problem}`);
|
|
568
|
+
return preview;
|
|
459
569
|
};
|
|
460
570
|
//#endregion
|
|
461
571
|
//#region src/isolated.ts
|
|
462
572
|
/** The `node_modules` nearest the module that has `@plitzi/sdk-authoring` in it: where its imports resolve. */
|
|
463
573
|
var modulesOf = (dir) => {
|
|
464
|
-
for (let at = dir;; at =
|
|
465
|
-
if (existsSync(
|
|
466
|
-
if (
|
|
574
|
+
for (let at = dir;; at = e.dirname(at)) {
|
|
575
|
+
if (existsSync(e.join(at, "node_modules", "@plitzi", "sdk-authoring"))) return e.join(at, "node_modules");
|
|
576
|
+
if (e.dirname(at) === at) return;
|
|
467
577
|
}
|
|
468
578
|
};
|
|
469
579
|
/**
|
|
@@ -471,9 +581,16 @@ var modulesOf = (dir) => {
|
|
|
471
581
|
* elsewhere (a workspace) — the folder it really is in, which is the path Node reads it by.
|
|
472
582
|
*/
|
|
473
583
|
var readable = (dir, modules) => {
|
|
474
|
-
const linked = readdirSync(
|
|
584
|
+
const linked = readdirSync(e.join(modules, "@plitzi")).map((name) => realpathSync(e.join(modules, "@plitzi", name)));
|
|
585
|
+
const root = realpathSync(e.dirname(modules));
|
|
586
|
+
const project = dir === root || dir.startsWith(`${root}${e.sep}`) ? [
|
|
587
|
+
e.join(root, "src"),
|
|
588
|
+
e.join(root, "package.json"),
|
|
589
|
+
e.join(root, "node_modules")
|
|
590
|
+
] : [];
|
|
475
591
|
return [.../* @__PURE__ */ new Set([
|
|
476
592
|
dir,
|
|
593
|
+
...project,
|
|
477
594
|
modules,
|
|
478
595
|
realpathSync(modules),
|
|
479
596
|
...linked
|
|
@@ -486,7 +603,7 @@ var readable = (dir, modules) => {
|
|
|
486
603
|
*/
|
|
487
604
|
var runner = (file) => `
|
|
488
605
|
const FILE = ${JSON.stringify(pathToFileURL(file).href)};
|
|
489
|
-
const NAME = ${JSON.stringify(
|
|
606
|
+
const NAME = ${JSON.stringify(e.basename(file))};
|
|
490
607
|
const send = message => new Promise(resolve => process.send(message, () => resolve()));
|
|
491
608
|
const firstLine = error => String(error instanceof Error ? error.message : error).split('\\n')[0];
|
|
492
609
|
const located = error => {
|
|
@@ -534,7 +651,7 @@ process.exit(0);
|
|
|
534
651
|
`;
|
|
535
652
|
/** What the process answered, read for its shape and the space checked again: nothing it says is taken on trust. */
|
|
536
653
|
var readAnswer = (answer) => {
|
|
537
|
-
if (!e(answer) || typeof answer.ok !== "boolean") return;
|
|
654
|
+
if (!e$2(answer) || typeof answer.ok !== "boolean") return;
|
|
538
655
|
if (!answer.ok) {
|
|
539
656
|
const message = typeof answer.message === "string" ? answer.message : "The module was not authored";
|
|
540
657
|
return answer.reason === "refused" && Array.isArray(answer.refusals) ? {
|
|
@@ -580,21 +697,21 @@ var readAnswer = (answer) => {
|
|
|
580
697
|
}
|
|
581
698
|
};
|
|
582
699
|
};
|
|
583
|
-
var isRefusal = (value) => e(value) && typeof value.message === "string" && typeof value.place === "string";
|
|
700
|
+
var isRefusal = (value) => e$2(value) && typeof value.message === "string" && typeof value.place === "string";
|
|
584
701
|
/**
|
|
585
702
|
* The shape of that answer. The documents are what `validateSpace` checks; the rest is what the author said about them,
|
|
586
703
|
* read by whoever asked.
|
|
587
704
|
*/
|
|
588
|
-
var isWireAuthored = (value) => e(value) && e(value.schema) && e(value.style) && e(value.handles) && e(value.handles.pages) && e(value.handles.layouts) && Array.isArray(value.warnings) && Array.isArray(value.suggestions);
|
|
705
|
+
var isWireAuthored = (value) => e$2(value) && e$2(value.schema) && e$2(value.style) && e$2(value.handles) && e$2(value.handles.pages) && e$2(value.handles.layouts) && Array.isArray(value.warnings) && Array.isArray(value.suggestions);
|
|
589
706
|
var authorIsolated = (file, options = {}) => {
|
|
590
707
|
const { timeoutMs = 1e4, memoryMb = 512 } = options;
|
|
591
|
-
const module =
|
|
708
|
+
const module = e.resolve(file);
|
|
592
709
|
if (!existsSync(module)) return Promise.resolve({
|
|
593
710
|
ok: false,
|
|
594
711
|
reason: "failed",
|
|
595
712
|
message: `${file} does not exist`
|
|
596
713
|
});
|
|
597
|
-
const dir =
|
|
714
|
+
const dir = e.dirname(module);
|
|
598
715
|
const modules = modulesOf(dir);
|
|
599
716
|
if (!modules) return Promise.resolve({
|
|
600
717
|
ok: false,
|
|
@@ -667,8 +784,9 @@ var authorIsolated = (file, options = {}) => {
|
|
|
667
784
|
* one stays what it is — data and functions over data, for a browser as much as a build script.
|
|
668
785
|
*
|
|
669
786
|
* ```ts
|
|
670
|
-
* import { svgFile, svgFiles } from '@plitzi/sdk-authoring/node';
|
|
787
|
+
* import { pagesIn, svgFile, svgFiles } from '@plitzi/sdk-authoring/node';
|
|
671
788
|
*
|
|
789
|
+
* const pages = await pagesIn(new URL('./pages/', import.meta.url)); // every page of the folder, by being there
|
|
672
790
|
* const logos = svgFiles(new URL('./logos/', import.meta.url)); // { stripe: '<svg…>', shopify: '<svg…>' }
|
|
673
791
|
* svg(logos.stripe, { label: 'Stripe' });
|
|
674
792
|
* svg(svgFile(new URL('./icons/arrow.svg', import.meta.url)));
|
|
@@ -693,16 +811,16 @@ var svgFile = (file) => {
|
|
|
693
811
|
*/
|
|
694
812
|
var svgFiles = (folder) => {
|
|
695
813
|
const at = pathOf(folder);
|
|
696
|
-
return Object.fromEntries(readdirSync(at).filter((name) => name.toLowerCase().endsWith(".svg")).sort().map((name) => [
|
|
814
|
+
return Object.fromEntries(readdirSync(at).filter((name) => name.toLowerCase().endsWith(".svg")).sort().map((name) => [e.basename(name, e.extname(name)), svgFile(e.join(at, name))]));
|
|
697
815
|
};
|
|
698
816
|
/** A JSON file under `prefix`, read once from the same path inside `folder`; `undefined` for anything else. */
|
|
699
817
|
var fileReader = (folder, prefix) => {
|
|
700
|
-
const root =
|
|
818
|
+
const root = e.resolve(pathOf(folder));
|
|
701
819
|
const read = /* @__PURE__ */ new Map();
|
|
702
820
|
return (query) => {
|
|
703
821
|
if (!query.startsWith(prefix) || query.startsWith("//") || query.includes("{{")) return;
|
|
704
|
-
const file =
|
|
705
|
-
if (!file.startsWith(`${root}${
|
|
822
|
+
const file = e.resolve(root, `.${query.split(/[?#]/)[0].slice(prefix.length - 1)}`);
|
|
823
|
+
if (!file.startsWith(`${root}${e.sep}`)) return;
|
|
706
824
|
if (!read.has(file)) {
|
|
707
825
|
let value;
|
|
708
826
|
try {
|
|
@@ -727,7 +845,7 @@ var publicData = (folder) => fileReader(folder, "/");
|
|
|
727
845
|
* never serves (`dataDir`) — for `authorSpace`'s `serverData`: bindings are held to the file, and a provider reading
|
|
728
846
|
* one from the browser is refused.
|
|
729
847
|
*/
|
|
730
|
-
var projectData = (folder) => fileReader(folder,
|
|
848
|
+
var projectData = (folder) => fileReader(folder, v$1);
|
|
731
849
|
/**
|
|
732
850
|
* Every plugin under `folder` — `src/plugins/<Name>/declaration.ts`, its default export — with the folder it is in.
|
|
733
851
|
* Found by folder, as the server finds the plugins themselves, so a plugin is declared by being there and no list can
|
|
@@ -736,9 +854,9 @@ var projectData = (folder) => fileReader(folder, h);
|
|
|
736
854
|
*/
|
|
737
855
|
var pluginFolders = async (folder) => {
|
|
738
856
|
const root = pathOf(folder);
|
|
739
|
-
const names = existsSync(root) ? readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(
|
|
857
|
+
const names = existsSync(root) ? readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && existsSync(e.join(root, entry.name, "declaration.ts"))).map((entry) => entry.name).sort() : [];
|
|
740
858
|
return Promise.all(names.map(async (name) => {
|
|
741
|
-
const file =
|
|
859
|
+
const file = e.join(root, name, d$2);
|
|
742
860
|
const loaded = await importProjectModule(file, root);
|
|
743
861
|
const declaration = typeof loaded === "object" && loaded !== null && "default" in loaded ? loaded.default : void 0;
|
|
744
862
|
if (typeof declaration !== "object" || declaration === null || !("type" in declaration) || typeof declaration.type !== "string") throw new Error(`${file} exports no declaration by default: \`export default { type: '…', … }\`.`);
|
|
@@ -748,13 +866,74 @@ var pluginFolders = async (folder) => {
|
|
|
748
866
|
};
|
|
749
867
|
}));
|
|
750
868
|
};
|
|
869
|
+
/** What a page module's default export must at least be: a page — its name, slug and body — or a list of them. */
|
|
870
|
+
var isPage = (value) => e$2(value) && typeof value.name === "string" && typeof value.slug === "string" && Array.isArray(value.body);
|
|
871
|
+
/**
|
|
872
|
+
* Every page under `folder` — each module in it (`pets.ts`) and each folder's `index.ts` (`home/index.ts`), by its
|
|
873
|
+
* default export: a page, or the list of a page family (`pageFamily`, a page per record). Found by folder, as the
|
|
874
|
+
* plugins are, so a page is part of the space by being there: no list in the entry to forget one, nor one line that
|
|
875
|
+
* every new page writes. The CLI follows its imports through the same folder (`plitzi space overview`, the lint's
|
|
876
|
+
* unused files), so a page there is never taken for a stray file.
|
|
877
|
+
*
|
|
878
|
+
* In path order, but the home page first — the first page is the space's default unless one says `isDefault`. A module
|
|
879
|
+
* there that exports no page by default is refused, naming it: a helper belongs in a page's own folder, or beside it.
|
|
880
|
+
*
|
|
881
|
+
* ```ts
|
|
882
|
+
* const pages = await pagesIn(new URL('./pages/', import.meta.url));
|
|
883
|
+
* export const space: SpaceSpec = { …, pages: [...pages, notFound] };
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
var pagesIn = async (folder) => {
|
|
887
|
+
const root = pathOf(folder);
|
|
888
|
+
const pages = (await Promise.all(o(root).map(async (file) => {
|
|
889
|
+
const loaded = await importProjectModule(file, root);
|
|
890
|
+
const exported = e$2(loaded) ? loaded.default : void 0;
|
|
891
|
+
const pages = Array.isArray(exported) ? exported : [exported];
|
|
892
|
+
if (pages.length === 0 || !pages.every(isPage)) throw new Error(`${file} exports no page by default: \`export default page\` (a PageSpec, or a page family's list). A module that is no page goes in a page's own folder.`);
|
|
893
|
+
return pages;
|
|
894
|
+
}))).flat();
|
|
895
|
+
const home = pages.findIndex((page) => page.isDefault === true);
|
|
896
|
+
const first = home === -1 ? pages.findIndex((page) => page.slug === "") : home;
|
|
897
|
+
return first <= 0 ? pages : [pages[first], ...pages.filter((_, index) => index !== first)];
|
|
898
|
+
};
|
|
899
|
+
/** A server action as `defineAction` and `taskAction` make one: its id, and the document the server runs. */
|
|
900
|
+
var isActionEntry = (value) => e$2(value) && typeof value.id === "string" && e$2(value.document);
|
|
901
|
+
/** A file of a folder of actions: a module at its top, never its `index` (the list itself), a test or a declaration. */
|
|
902
|
+
var ACTION_MODULE = /^(?!index\.)[^.].*\.(ts|js|mjs)$/;
|
|
903
|
+
var NOT_AN_ACTION = /\.(test|spec)\.(ts|js|mjs)$|\.d\.ts$/;
|
|
904
|
+
/**
|
|
905
|
+
* Every server action of a folder — a project's `src/actions/` — a domain a file, read by what each exports: an action
|
|
906
|
+
* (`defineAction`, `taskAction`) or a list of them, by any name. Nothing lists them: a run's agents all appended to one
|
|
907
|
+
* `actions/index.ts`, and its conflicts and integration tasks were that list. The folder's `index` is where this is
|
|
908
|
+
* called from, and is not read. One action exported twice (on its own and in its file's list) counts once; two of one id
|
|
909
|
+
* are refused, naming both files.
|
|
910
|
+
*/
|
|
911
|
+
var actionsIn = async (folder) => {
|
|
912
|
+
const root = pathOf(folder);
|
|
913
|
+
if (!existsSync(root)) return [];
|
|
914
|
+
const files = readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isFile() && ACTION_MODULE.test(entry.name) && !NOT_AN_ACTION.test(entry.name)).map((entry) => e.join(root, entry.name)).sort();
|
|
915
|
+
const actions = [];
|
|
916
|
+
const fileOf = /* @__PURE__ */ new Map();
|
|
917
|
+
for (const file of files) {
|
|
918
|
+
const loaded = await importProjectModule(file, root);
|
|
919
|
+
const exported = e$2(loaded) ? Object.values(loaded) : [];
|
|
920
|
+
for (const value of exported.flatMap((each) => Array.isArray(each) ? each : [each]).filter(isActionEntry)) {
|
|
921
|
+
if (actions.includes(value)) continue;
|
|
922
|
+
const before = fileOf.get(value.id);
|
|
923
|
+
if (before !== void 0) throw new Error(`The action ${value.id} is defined twice: in ${e.relative(root, before)} and in ${e.relative(root, file)} — one file defines it`);
|
|
924
|
+
fileOf.set(value.id, file);
|
|
925
|
+
actions.push(value);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return actions;
|
|
929
|
+
};
|
|
751
930
|
/** The declaration of every plugin under `folder`, for `authorSpace`'s `plugins`: what each fires, answers and reads. */
|
|
752
931
|
var pluginDeclarations = async (folder) => (await pluginFolders(folder)).map(({ declaration }) => declaration);
|
|
753
932
|
/** The manifest of a plugin run as it was built, read; nothing when it cannot be — the layout check says why first. */
|
|
754
933
|
var manifestOf = (file) => {
|
|
755
934
|
try {
|
|
756
935
|
const manifest = JSON.parse(readFileSync(file, "utf-8"));
|
|
757
|
-
return e(manifest) ? manifest : {};
|
|
936
|
+
return e$2(manifest) ? manifest : {};
|
|
758
937
|
} catch {
|
|
759
938
|
return {};
|
|
760
939
|
}
|
|
@@ -764,17 +943,53 @@ var manifestOf = (file) => {
|
|
|
764
943
|
* space): each folder's type and every element its manifest provides (`pluginSchema`). None in most projects.
|
|
765
944
|
*/
|
|
766
945
|
var builtPluginTypes = (folder) => existsSync(folder) ? readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name)).flatMap((entry) => {
|
|
767
|
-
const { pluginSchema } = manifestOf(
|
|
768
|
-
return [entry.name, ...e(pluginSchema) ? Object.keys(pluginSchema) : []];
|
|
946
|
+
const { pluginSchema } = manifestOf(e.join(folder, entry.name, m$2));
|
|
947
|
+
return [entry.name, ...e$2(pluginSchema) ? Object.keys(pluginSchema) : []];
|
|
769
948
|
}) : [];
|
|
770
949
|
/**
|
|
771
950
|
* The stylesheets of the plugins under `folder` — every `.css` in a plugin's folder, at any depth — as their text, for
|
|
772
951
|
* `authorSpace`'s `stylesheets`: the tokens a plugin's own CSS reads are tokens the space uses.
|
|
773
952
|
*/
|
|
774
|
-
var pluginStylesheets = (folder) =>
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
953
|
+
var pluginStylesheets = (folder) => {
|
|
954
|
+
if (!existsSync(folder)) return [];
|
|
955
|
+
const files = readdirSync(folder, {
|
|
956
|
+
recursive: true,
|
|
957
|
+
withFileTypes: true
|
|
958
|
+
}).filter((entry) => entry.isFile()).map((entry) => e.join(entry.parentPath, entry.name)).sort();
|
|
959
|
+
const own = files.filter((file) => file.endsWith(".css"));
|
|
960
|
+
const imported = files.filter((file) => /\.[cm]?[jt]sx?$/.test(file) && !/\.(?:test|spec)\.[cm]?[jt]sx?$/.test(file)).flatMap((file) => importedStylesheets(file)).filter((file) => !own.includes(file));
|
|
961
|
+
return [.../* @__PURE__ */ new Set([...own, ...imported])].map((file) => readFileSync(file, "utf-8"));
|
|
962
|
+
};
|
|
963
|
+
/** A side-effect import's specifier: `import '@vizzele/css'`, `import '../styles/bridge.css'`. */
|
|
964
|
+
var SIDE_EFFECT_IMPORT = /^\s*import\s+['"]([^'"]+)['"]\s*;?/gm;
|
|
965
|
+
/**
|
|
966
|
+
* The stylesheets `file` imports for their effect, resolved as Node resolves them from it: a `.css` it names, or a
|
|
967
|
+
* package's — its `style` field, when what it exports is no stylesheet. One that does not resolve is not read.
|
|
968
|
+
*/
|
|
969
|
+
var importedStylesheets = (file) => {
|
|
970
|
+
const from = createRequire(file);
|
|
971
|
+
return [...readFileSync(file, "utf-8").matchAll(SIDE_EFFECT_IMPORT)].flatMap(([, specifier = ""]) => {
|
|
972
|
+
const resolved = (() => {
|
|
973
|
+
try {
|
|
974
|
+
return from.resolve(specifier);
|
|
975
|
+
} catch {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
})();
|
|
979
|
+
if (resolved?.endsWith(".css")) return [resolved];
|
|
980
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) return [];
|
|
981
|
+
const name = specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0] ?? "";
|
|
982
|
+
try {
|
|
983
|
+
const manifest = from.resolve(`${name}/package.json`);
|
|
984
|
+
const declared = JSON.parse(readFileSync(manifest, "utf-8"));
|
|
985
|
+
const style = e$2(declared) && typeof declared.style === "string" ? declared.style : void 0;
|
|
986
|
+
const sheet = style === void 0 ? void 0 : e.join(e.dirname(manifest), style);
|
|
987
|
+
return sheet !== void 0 && existsSync(sheet) ? [sheet] : [];
|
|
988
|
+
} catch {
|
|
989
|
+
return [];
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
};
|
|
778
993
|
/**
|
|
779
994
|
* What `authorSpace` checks the space of a project `@plitzi/cli` writes against, read from the project the process runs
|
|
780
995
|
* — so its server, `npm run author` and the CLI's checks hold the space to the same thing:
|
|
@@ -796,21 +1011,21 @@ var pluginStylesheets = (folder) => existsSync(folder) ? readdirSync(folder, {
|
|
|
796
1011
|
* authorSpace(space, await projectAuthoring());
|
|
797
1012
|
* ```
|
|
798
1013
|
*/
|
|
799
|
-
var projectAuthoring = async () => projectAuthoringAt(
|
|
1014
|
+
var projectAuthoring = async () => projectAuthoringAt(c());
|
|
800
1015
|
/**
|
|
801
1016
|
* `projectAuthoring` of the project at `root`, held to the same check: for a tool that works on a project from another
|
|
802
1017
|
* folder — the CLI, run anywhere inside one. A project's own code calls `projectAuthoring()`.
|
|
803
1018
|
*/
|
|
804
1019
|
var projectAuthoringAt = async (root) => {
|
|
805
|
-
const at =
|
|
806
|
-
|
|
807
|
-
const serverData =
|
|
1020
|
+
const at = s(root);
|
|
1021
|
+
y(at, { space: "local" });
|
|
1022
|
+
const serverData = e.join(at, _);
|
|
808
1023
|
return {
|
|
809
|
-
plugins: await pluginDeclarations(
|
|
810
|
-
pluginTypes: builtPluginTypes(
|
|
811
|
-
stylesheets: pluginStylesheets(
|
|
1024
|
+
plugins: await pluginDeclarations(e.join(at, l$3)),
|
|
1025
|
+
pluginTypes: builtPluginTypes(e.join(at, p$2)),
|
|
1026
|
+
stylesheets: pluginStylesheets(e.join(at, l$3)),
|
|
812
1027
|
...existsSync(serverData) ? { serverData: projectData(serverData) } : {},
|
|
813
|
-
data: publicData(
|
|
1028
|
+
data: publicData(e.join(at, g$1))
|
|
814
1029
|
};
|
|
815
1030
|
};
|
|
816
1031
|
/** A project whose space module (`src/space/index.ts`) exports no space: its message says what to export. */
|
|
@@ -853,11 +1068,11 @@ var moduleProblem = (error, root) => {
|
|
|
853
1068
|
const ownFile = (file) => [file, realOf(file)].some((each) => roots.some((at) => each.startsWith(at))) && !file.includes("/node_modules/");
|
|
854
1069
|
if (error instanceof Error) {
|
|
855
1070
|
const located = error.message.split("\n").map((line) => LOCATED_LINE.exec(line.trim())).find((match) => match !== null && ownFile(match[1]));
|
|
856
|
-
if (located) return `${
|
|
1071
|
+
if (located) return `${e.relative(process.cwd(), located[1])}:${located[2]}: ${located[3]}`;
|
|
857
1072
|
}
|
|
858
1073
|
const message = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
859
1074
|
const frame = (error instanceof Error ? error.stack ?? "" : "").split("\n").map((line) => /(?:file:\/\/)?(\/[^\s:()]+\.(?:tsx?|m?js|json)):(\d+)/.exec(line)).find((match) => match !== null && ownFile(match[1]));
|
|
860
|
-
const at = frame ? `${
|
|
1075
|
+
const at = frame ? `${e.relative(process.cwd(), frame[1])}:${frame[2]}` : void 0;
|
|
861
1076
|
return at ? `${at}: ${message}` : message;
|
|
862
1077
|
};
|
|
863
1078
|
/**
|
|
@@ -876,16 +1091,16 @@ var importProjectModule = async (file, root) => {
|
|
|
876
1091
|
* What the module exports as `space`, taken as a declaration when it has the shape of one. `authorSpace` checks the
|
|
877
1092
|
* rest of it, field by field, and says what is wrong — so this only has to tell a space from anything else.
|
|
878
1093
|
*/
|
|
879
|
-
var isSpaceSpec = (value) => e(value) && typeof value.name === "string" && typeof value.permanentUrl === "string" && Array.isArray(value.pages);
|
|
1094
|
+
var isSpaceSpec = (value) => e$2(value) && typeof value.name === "string" && typeof value.permanentUrl === "string" && Array.isArray(value.pages);
|
|
880
1095
|
/**
|
|
881
1096
|
* `projectSpace` of the project at `root`, held to the same checks: for a tool that works on a project from another
|
|
882
1097
|
* folder — the CLI, run anywhere inside one. A project's own code calls `projectSpace()` or `authorProjectSpace()`.
|
|
883
1098
|
*/
|
|
884
1099
|
var projectSpaceAt = async (root) => {
|
|
885
1100
|
const authoring = await projectAuthoringAt(root);
|
|
886
|
-
const module = await importProjectModule(
|
|
887
|
-
const space = e(module) ? module.space : void 0;
|
|
888
|
-
if (!isSpaceSpec(space)) throw new ProjectSpaceError(
|
|
1101
|
+
const module = await importProjectModule(u(root, c$3, process.argv[1]), root);
|
|
1102
|
+
const space = e$2(module) ? module.space : void 0;
|
|
1103
|
+
if (!isSpaceSpec(space)) throw new ProjectSpaceError(c$3);
|
|
889
1104
|
return {
|
|
890
1105
|
space,
|
|
891
1106
|
authoring
|
|
@@ -897,7 +1112,14 @@ var projectSpaceAt = async (root) => {
|
|
|
897
1112
|
* given as the space's files load is said like the rest — the message, not a stack. A module that exports no space is
|
|
898
1113
|
* refused, saying what to export (`ProjectSpaceError`).
|
|
899
1114
|
*/
|
|
900
|
-
var projectSpace = async () =>
|
|
1115
|
+
var projectSpace = async () => {
|
|
1116
|
+
const { space, authoring } = await projectSpaceAt(c());
|
|
1117
|
+
const preview = previewOfProcess();
|
|
1118
|
+
return {
|
|
1119
|
+
space: preview ? withPreview(space, preview, [...authoring.plugins.map((plugin) => plugin.type), ...authoring.pluginTypes]) : space,
|
|
1120
|
+
authoring
|
|
1121
|
+
};
|
|
1122
|
+
};
|
|
901
1123
|
/**
|
|
902
1124
|
* The project's space, authored: what a project's server serves — `serveProject({ space: authorProjectSpace })` — and
|
|
903
1125
|
* its visual tests read. `projectSpace`, then `authorSpace` with what it is checked against.
|
|
@@ -907,4 +1129,4 @@ var authorProjectSpace = async () => {
|
|
|
907
1129
|
return authorSpace(space, authoring);
|
|
908
1130
|
};
|
|
909
1131
|
//#endregion
|
|
910
|
-
export { ProjectModuleError, ProjectSpaceError, authorIsolated, authorProjectSpace, compactSvg, moduleProblem, pluginDeclarations, pluginFolders, projectAuthoring, projectAuthoringAt, projectData, projectSpace, projectSpaceAt, publicData, svgFile, svgFiles };
|
|
1132
|
+
export { ProjectModuleError, ProjectSpaceError, actionsIn, authorIsolated, authorProjectSpace, compactSvg, moduleProblem, pagesIn, pluginDeclarations, pluginFolders, pluginStylesheets, projectAuthoring, projectAuthoringAt, projectData, projectSpace, projectSpaceAt, publicData, svgFile, svgFiles };
|