mirrorbook 0.6.0 → 0.8.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/SKILL.md +12 -2
- package/dist/cli.js +382 -10
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -21,7 +21,7 @@ npx mirrorbook deploy ./dist --slug my-demo --wait --json
|
|
|
21
21
|
- If the slug is taken by someone else, a 4-character suffix is added (`demo` → `demo-k3x9`) and `slugAdjusted` is `true`. Always read the final `url`/`slug` from the output. Re-deploying with the original `--slug demo` keeps updating that same `demo-k3x9` site. Pass `--strict-slug` to fail (exit 2, `slug_taken`) instead.
|
|
22
22
|
- Output (with `--json`): `{"url","previewUrl","slug","deploymentId","status","error","errorCode","errorParams","number","created","requestedSlug","slugAdjusted","lockTitle","lockMessage"}`.
|
|
23
23
|
- When `status` is `failed`, `errorCode` says why: `missing_index` (no index.html at the zip root), `zip_invalid`, `zip_path_invalid`, `zip_encrypted`, `file_too_large`, `unzipped_too_large`, `too_many_files`, `quota_exceeded`, `upload_missing`, `file_read_failed`, `owner_missing`, `processing_failed`.
|
|
24
|
-
- Sites go live as soon as processing finishes (`status: "approved"`); admins review afterwards and may take a version down (`rejected`). A new account
|
|
24
|
+
- Sites go live as soon as processing finishes (`status: "approved"`); admins review afterwards and may take a version down (`rejected`). A new account has to be approved once before it can publish (exit 3, `pending_approval`): it is approved automatically when the user clicks the verification link emailed at sign-up, otherwise an admin approves it.
|
|
25
25
|
- Each account has a site limit (default 10) and a storage quota (default 100 MB); going over exits with 4 (`quota_exceeded`).
|
|
26
26
|
|
|
27
27
|
Exit codes: 0 ok · 2 usage (bad path or slug) · 3 auth (missing token, account pending) · 4 quota · 5 failed or rejected.
|
|
@@ -40,6 +40,16 @@ npx mirrorbook access my-demo --clear-lock # back to the default copy
|
|
|
40
40
|
|
|
41
41
|
The copy only appears on password-protected sites — setting it on a site with no password stores it but visitors never see it (the CLI prints a `note:` line in that case). Passing the option alone is enough to change it; you don't need to re-supply `--password`.
|
|
42
42
|
|
|
43
|
+
Cover: each site can have its own cover image, shown on site lists, picks and the author's profile. It must be an SVG (max 32 KB, 16:10 works best, e.g. `viewBox="0 0 320 200"`). Scripts, event handlers, links and external images/fonts are stripped; for dark mode use `@media (prefers-color-scheme: dark)` inside `<style>`. Without one, a pattern generated from the slug is shown.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx mirrorbook cover my-demo cover.svg # set (or - to read stdin)
|
|
47
|
+
npx mirrorbook deploy ./dist --slug my-demo --cover cover.svg
|
|
48
|
+
npx mirrorbook cover my-demo --remove # back to the default pattern
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
An invalid SVG exits with 2 before anything is uploaded. `--json` returns `coverUrl` and `dropped` (what was removed).
|
|
52
|
+
|
|
43
53
|
Install this skill for Claude Code with `npx mirrorbook skill --install` (or `--dir ./.claude/skills` for one project); `mirrorbook skill` prints it.
|
|
44
54
|
|
|
45
|
-
Other commands: `pull <slug> [version] [-o file.zip]` (download a version's files as a zip; owner only, defaults to the live version), `access <slug>`, `ls` (shows each entry's kind: `site` or `collection`; collections are curated pages made in the console and can't be deployed to), `status <slug>` (lists versions, or the member sites of a collection), `rollback <slug> <version>` (alias `set-default`; version is `3`, `#3`, or a deployment id), `rm-version <slug> <version> --yes`, `rm <slug> --yes`, `whoami`. Add `--json` to any of them.
|
|
55
|
+
Other commands: `pull <slug> [version] [-o file.zip]` (download a version's files as a zip; owner only, defaults to the live version), `access <slug>`, `cover <slug> [file.svg] [--remove]`, `ls` (shows each entry's kind: `site` or `collection`; collections are curated pages made in the console and can't be deployed to), `status <slug>` (lists versions, or the member sites of a collection), `rollback <slug> <version>` (alias `set-default`; version is `3`, `#3`, or a deployment id), `rm-version <slug> <version> --yes`, `rm <slug> --yes`, `whoami`. Add `--json` to any of them.
|
package/dist/cli.js
CHANGED
|
@@ -72,6 +72,320 @@ var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", ".svn", ".hg",
|
|
|
72
72
|
var SKIP_FILES = /* @__PURE__ */ new Set([".DS_Store", "Thumbs.db", ".env"]);
|
|
73
73
|
var isSkippedFile = (name) => SKIP_FILES.has(name) || name.startsWith(".env.");
|
|
74
74
|
|
|
75
|
+
// ../shared/src/cover-svg.ts
|
|
76
|
+
var COVER_MAX_BYTES = 32 * 1024;
|
|
77
|
+
var MAX_ELEMENTS = 2e3;
|
|
78
|
+
var MAX_DEPTH = 48;
|
|
79
|
+
var ELEMENTS = /* @__PURE__ */ new Set([
|
|
80
|
+
"svg",
|
|
81
|
+
"g",
|
|
82
|
+
"defs",
|
|
83
|
+
"symbol",
|
|
84
|
+
"use",
|
|
85
|
+
"title",
|
|
86
|
+
"desc",
|
|
87
|
+
"style",
|
|
88
|
+
"path",
|
|
89
|
+
"rect",
|
|
90
|
+
"circle",
|
|
91
|
+
"ellipse",
|
|
92
|
+
"line",
|
|
93
|
+
"polyline",
|
|
94
|
+
"polygon",
|
|
95
|
+
"text",
|
|
96
|
+
"tspan",
|
|
97
|
+
"linearGradient",
|
|
98
|
+
"radialGradient",
|
|
99
|
+
"stop",
|
|
100
|
+
"pattern",
|
|
101
|
+
"clipPath",
|
|
102
|
+
"mask",
|
|
103
|
+
"marker",
|
|
104
|
+
"filter",
|
|
105
|
+
"feBlend",
|
|
106
|
+
"feColorMatrix",
|
|
107
|
+
"feComponentTransfer",
|
|
108
|
+
"feComposite",
|
|
109
|
+
"feFlood",
|
|
110
|
+
"feGaussianBlur",
|
|
111
|
+
"feMerge",
|
|
112
|
+
"feMergeNode",
|
|
113
|
+
"feMorphology",
|
|
114
|
+
"feOffset",
|
|
115
|
+
"feTurbulence",
|
|
116
|
+
"feDisplacementMap",
|
|
117
|
+
"feFuncR",
|
|
118
|
+
"feFuncG",
|
|
119
|
+
"feFuncB",
|
|
120
|
+
"feFuncA",
|
|
121
|
+
"feDropShadow"
|
|
122
|
+
]);
|
|
123
|
+
var ATTRS = /* @__PURE__ */ new Set([
|
|
124
|
+
// 通用
|
|
125
|
+
"id",
|
|
126
|
+
"class",
|
|
127
|
+
"style",
|
|
128
|
+
"transform",
|
|
129
|
+
"opacity",
|
|
130
|
+
"visibility",
|
|
131
|
+
"display",
|
|
132
|
+
// 布局 / 几何
|
|
133
|
+
"viewBox",
|
|
134
|
+
"preserveAspectRatio",
|
|
135
|
+
"width",
|
|
136
|
+
"height",
|
|
137
|
+
"x",
|
|
138
|
+
"y",
|
|
139
|
+
"x1",
|
|
140
|
+
"y1",
|
|
141
|
+
"x2",
|
|
142
|
+
"y2",
|
|
143
|
+
"cx",
|
|
144
|
+
"cy",
|
|
145
|
+
"r",
|
|
146
|
+
"rx",
|
|
147
|
+
"ry",
|
|
148
|
+
"fx",
|
|
149
|
+
"fy",
|
|
150
|
+
"fr",
|
|
151
|
+
"d",
|
|
152
|
+
"points",
|
|
153
|
+
"pathLength",
|
|
154
|
+
// 填充 / 描边
|
|
155
|
+
"fill",
|
|
156
|
+
"fill-opacity",
|
|
157
|
+
"fill-rule",
|
|
158
|
+
"stroke",
|
|
159
|
+
"stroke-width",
|
|
160
|
+
"stroke-opacity",
|
|
161
|
+
"stroke-linecap",
|
|
162
|
+
"stroke-linejoin",
|
|
163
|
+
"stroke-miterlimit",
|
|
164
|
+
"stroke-dasharray",
|
|
165
|
+
"stroke-dashoffset",
|
|
166
|
+
"vector-effect",
|
|
167
|
+
"color",
|
|
168
|
+
"paint-order",
|
|
169
|
+
"shape-rendering",
|
|
170
|
+
"mix-blend-mode",
|
|
171
|
+
"isolation",
|
|
172
|
+
"clip-path",
|
|
173
|
+
"clip-rule",
|
|
174
|
+
"mask",
|
|
175
|
+
"filter",
|
|
176
|
+
"marker-start",
|
|
177
|
+
"marker-mid",
|
|
178
|
+
"marker-end",
|
|
179
|
+
// 文字
|
|
180
|
+
"font-family",
|
|
181
|
+
"font-size",
|
|
182
|
+
"font-weight",
|
|
183
|
+
"font-style",
|
|
184
|
+
"font-variant",
|
|
185
|
+
"letter-spacing",
|
|
186
|
+
"word-spacing",
|
|
187
|
+
"text-anchor",
|
|
188
|
+
"dominant-baseline",
|
|
189
|
+
"alignment-baseline",
|
|
190
|
+
"baseline-shift",
|
|
191
|
+
"text-decoration",
|
|
192
|
+
"writing-mode",
|
|
193
|
+
"dx",
|
|
194
|
+
"dy",
|
|
195
|
+
"rotate",
|
|
196
|
+
"textLength",
|
|
197
|
+
"lengthAdjust",
|
|
198
|
+
"xml:space",
|
|
199
|
+
// 渐变 / 图案 / 遮罩 / 标记
|
|
200
|
+
"offset",
|
|
201
|
+
"stop-color",
|
|
202
|
+
"stop-opacity",
|
|
203
|
+
"gradientUnits",
|
|
204
|
+
"gradientTransform",
|
|
205
|
+
"spreadMethod",
|
|
206
|
+
"patternUnits",
|
|
207
|
+
"patternContentUnits",
|
|
208
|
+
"patternTransform",
|
|
209
|
+
"clipPathUnits",
|
|
210
|
+
"maskUnits",
|
|
211
|
+
"maskContentUnits",
|
|
212
|
+
"markerWidth",
|
|
213
|
+
"markerHeight",
|
|
214
|
+
"markerUnits",
|
|
215
|
+
"refX",
|
|
216
|
+
"refY",
|
|
217
|
+
"orient",
|
|
218
|
+
// 滤镜
|
|
219
|
+
"filterUnits",
|
|
220
|
+
"primitiveUnits",
|
|
221
|
+
"in",
|
|
222
|
+
"in2",
|
|
223
|
+
"result",
|
|
224
|
+
"mode",
|
|
225
|
+
"type",
|
|
226
|
+
"values",
|
|
227
|
+
"stdDeviation",
|
|
228
|
+
"operator",
|
|
229
|
+
"k1",
|
|
230
|
+
"k2",
|
|
231
|
+
"k3",
|
|
232
|
+
"k4",
|
|
233
|
+
"flood-color",
|
|
234
|
+
"flood-opacity",
|
|
235
|
+
"baseFrequency",
|
|
236
|
+
"numOctaves",
|
|
237
|
+
"seed",
|
|
238
|
+
"stitchTiles",
|
|
239
|
+
"scale",
|
|
240
|
+
"xChannelSelector",
|
|
241
|
+
"yChannelSelector",
|
|
242
|
+
"radius",
|
|
243
|
+
"tableValues",
|
|
244
|
+
"slope",
|
|
245
|
+
"intercept",
|
|
246
|
+
"amplitude",
|
|
247
|
+
"exponent",
|
|
248
|
+
"color-interpolation-filters",
|
|
249
|
+
// 引用:只允许指向文档内部的 #id,下面单独检查
|
|
250
|
+
"href",
|
|
251
|
+
"xlink:href"
|
|
252
|
+
]);
|
|
253
|
+
var NS_ATTRS = /* @__PURE__ */ new Set(["xmlns", "xmlns:xlink", "version"]);
|
|
254
|
+
var NAME = /^[A-Za-z_][\w.:-]*$/;
|
|
255
|
+
var ENTITY = /&(?:amp|lt|gt|quot|apos|#\d{1,7}|#x[0-9a-fA-F]{1,6});/g;
|
|
256
|
+
function cssSafe(css) {
|
|
257
|
+
if (/@import|expression\s*\(|\\|javascript:/i.test(css)) return false;
|
|
258
|
+
for (const m of css.matchAll(/url\s*\(\s*(['"]?)(.*?)\1\s*\)/gi)) {
|
|
259
|
+
if (!/^#[\w.:-]+$/.test(m[2])) return false;
|
|
260
|
+
}
|
|
261
|
+
return !/url\s*\(/i.test(css.replace(/url\s*\(\s*(['"]?)#[\w.:-]+\1\s*\)/gi, ""));
|
|
262
|
+
}
|
|
263
|
+
function textSafe(s) {
|
|
264
|
+
return !s.includes("<") && !s.replace(ENTITY, "").includes("&");
|
|
265
|
+
}
|
|
266
|
+
var escAttr = (v) => v.replace(/"/g, """);
|
|
267
|
+
function parseAttrs(src) {
|
|
268
|
+
const out2 = [];
|
|
269
|
+
const re = /\s*([^\s=/>]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/y;
|
|
270
|
+
let i = 0;
|
|
271
|
+
while (i < src.length) {
|
|
272
|
+
if (/^\s*$/.test(src.slice(i))) break;
|
|
273
|
+
re.lastIndex = i;
|
|
274
|
+
const m = re.exec(src);
|
|
275
|
+
if (!m) return null;
|
|
276
|
+
out2.push([m[1], m[2] ?? m[3] ?? ""]);
|
|
277
|
+
i = re.lastIndex;
|
|
278
|
+
}
|
|
279
|
+
return out2;
|
|
280
|
+
}
|
|
281
|
+
function sanitizeCoverSvg(input) {
|
|
282
|
+
const src = input.replace(/^/, "").trim();
|
|
283
|
+
if (!src) return { ok: false, error: "empty" };
|
|
284
|
+
if (new TextEncoder().encode(src).length > COVER_MAX_BYTES) return { ok: false, error: "too_large" };
|
|
285
|
+
const out2 = [];
|
|
286
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
287
|
+
const stack = [];
|
|
288
|
+
let elements = 0;
|
|
289
|
+
let sawRoot = false;
|
|
290
|
+
let rootClosed = false;
|
|
291
|
+
let i = 0;
|
|
292
|
+
const skipping = () => stack.some((s) => s.skip);
|
|
293
|
+
const fail = (error, detail) => ({ ok: false, error, detail });
|
|
294
|
+
while (i < src.length) {
|
|
295
|
+
const lt = src.indexOf("<", i);
|
|
296
|
+
const text = src.slice(i, lt === -1 ? src.length : lt);
|
|
297
|
+
if (text) {
|
|
298
|
+
if (!textSafe(text)) return fail("parse_error", "bad text");
|
|
299
|
+
if (stack.length === 0) {
|
|
300
|
+
if (text.trim()) return fail("parse_error", "text outside <svg>");
|
|
301
|
+
} else if (!skipping()) {
|
|
302
|
+
const cur = stack[stack.length - 1].name;
|
|
303
|
+
if (cur === "style" && !cssSafe(text)) return fail("parse_error", "unsafe css");
|
|
304
|
+
out2.push(text);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (lt === -1) break;
|
|
308
|
+
i = lt;
|
|
309
|
+
if (src.startsWith("<!--", i)) {
|
|
310
|
+
const end = src.indexOf("-->", i + 4);
|
|
311
|
+
if (end === -1) return fail("parse_error", "unclosed comment");
|
|
312
|
+
i = end + 3;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (src.startsWith("<?", i)) {
|
|
316
|
+
if (sawRoot || !/^<\?xml[\s?]/.test(src.slice(i, i + 6))) return fail("parse_error", "processing instruction");
|
|
317
|
+
const end = src.indexOf("?>", i);
|
|
318
|
+
if (end === -1) return fail("parse_error", "unclosed declaration");
|
|
319
|
+
i = end + 2;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (src.startsWith("<!", i)) {
|
|
323
|
+
return fail(/^<!doctype/i.test(src.slice(i, i + 9)) ? "doctype" : "parse_error", "markup declaration");
|
|
324
|
+
}
|
|
325
|
+
const gt = src.indexOf(">", i);
|
|
326
|
+
if (gt === -1) return fail("parse_error", "unclosed tag");
|
|
327
|
+
const raw = src.slice(i + 1, gt);
|
|
328
|
+
i = gt + 1;
|
|
329
|
+
if (raw.startsWith("/")) {
|
|
330
|
+
const name2 = raw.slice(1).trim();
|
|
331
|
+
const top = stack.pop();
|
|
332
|
+
if (!top || top.name !== name2) return fail("parse_error", `mismatched </${name2}>`);
|
|
333
|
+
if (!top.skip && !skipping()) out2.push(`</${name2}>`);
|
|
334
|
+
if (stack.length === 0) rootClosed = true;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const selfClose = raw.endsWith("/");
|
|
338
|
+
const body = selfClose ? raw.slice(0, -1) : raw;
|
|
339
|
+
const nameMatch = /^([^\s/>]+)/.exec(body);
|
|
340
|
+
if (!nameMatch || !NAME.test(nameMatch[1])) return fail("parse_error", "bad tag name");
|
|
341
|
+
const name = nameMatch[1];
|
|
342
|
+
const attrs = parseAttrs(body.slice(name.length));
|
|
343
|
+
if (!attrs) return fail("parse_error", `bad attributes on <${name}>`);
|
|
344
|
+
for (const [, v] of attrs) if (!textSafe(v)) return fail("parse_error", `bad attribute value on <${name}>`);
|
|
345
|
+
const tag = { name, attrs, selfClose };
|
|
346
|
+
if (stack.length === 0) {
|
|
347
|
+
if (sawRoot || rootClosed) return fail("parse_error", "more than one root element");
|
|
348
|
+
if (name !== "svg") return fail("not_svg");
|
|
349
|
+
sawRoot = true;
|
|
350
|
+
}
|
|
351
|
+
if (++elements > MAX_ELEMENTS || stack.length >= MAX_DEPTH) return fail("too_complex");
|
|
352
|
+
const parentSkip = skipping();
|
|
353
|
+
const allowed = ELEMENTS.has(name);
|
|
354
|
+
if (!allowed) dropped.add(`<${name}>`);
|
|
355
|
+
if (!parentSkip && allowed) out2.push(renderOpen(tag, stack.length === 0, dropped));
|
|
356
|
+
if (!selfClose) stack.push({ name, skip: !allowed });
|
|
357
|
+
}
|
|
358
|
+
if (!sawRoot) return fail("not_svg");
|
|
359
|
+
if (stack.length) return fail("parse_error", `unclosed <${stack[stack.length - 1].name}>`);
|
|
360
|
+
const svg = out2.join("");
|
|
361
|
+
if (!/^<svg\b[^>]*\sviewBox="/.test(svg)) return fail("no_viewbox");
|
|
362
|
+
return { ok: true, svg, dropped: [...dropped] };
|
|
363
|
+
}
|
|
364
|
+
function renderOpen(tag, isRoot, dropped) {
|
|
365
|
+
const parts = [tag.name];
|
|
366
|
+
if (isRoot) parts.push('xmlns="http://www.w3.org/2000/svg"', 'xmlns:xlink="http://www.w3.org/1999/xlink"');
|
|
367
|
+
const seen = /* @__PURE__ */ new Set();
|
|
368
|
+
for (const [k, v] of tag.attrs) {
|
|
369
|
+
if (seen.has(k)) continue;
|
|
370
|
+
seen.add(k);
|
|
371
|
+
if (NS_ATTRS.has(k)) continue;
|
|
372
|
+
if (!ATTRS.has(k)) {
|
|
373
|
+
dropped.add(k);
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if ((k === "href" || k === "xlink:href") && !/^#[\w.:-]+$/.test(v.trim())) {
|
|
377
|
+
dropped.add(`${k} (external)`);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (/url\s*\(|@import|expression|javascript:/i.test(v) && !cssSafe(v)) {
|
|
381
|
+
dropped.add(`${k} (url)`);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
parts.push(`${k}="${escAttr(v)}"`);
|
|
385
|
+
}
|
|
386
|
+
return `<${parts.join(" ")}${tag.selfClose ? "/>" : ">"}`;
|
|
387
|
+
}
|
|
388
|
+
|
|
75
389
|
// src/api.ts
|
|
76
390
|
var CliError = class extends Error {
|
|
77
391
|
constructor(code, message, exitCode, status) {
|
|
@@ -134,11 +448,15 @@ function createClient(apiUrl, token) {
|
|
|
134
448
|
),
|
|
135
449
|
deviceToken: (deviceCode) => call("POST", "/cli/device/token", { deviceCode }),
|
|
136
450
|
deploy: (form) => call("POST", "/deploy", form),
|
|
451
|
+
// HTML 直接用 JSON 发布:{html, slug?, title?, onConflict?};返回 url 和 live(202 时还在处理中)
|
|
452
|
+
deployHtml: (body) => call("POST", "/deploy/html", body),
|
|
137
453
|
sites: () => call("GET", "/sites"),
|
|
138
454
|
site: (slug) => call("GET", `/sites/${encodeURIComponent(slug)}`),
|
|
139
455
|
deployment: (id) => call("GET", `/deployments/${encodeURIComponent(id)}`),
|
|
140
456
|
updateSite: (slug, body) => call("PATCH", `/sites/${encodeURIComponent(slug)}`, body),
|
|
141
457
|
rollback: (slug, deploymentId) => call("POST", `/sites/${encodeURIComponent(slug)}/rollback`, { deploymentId }),
|
|
458
|
+
setCover: (slug, svg) => call("PUT", `/sites/${encodeURIComponent(slug)}/cover`, { svg }),
|
|
459
|
+
removeCover: (slug) => call("DELETE", `/sites/${encodeURIComponent(slug)}/cover`),
|
|
142
460
|
remove: (slug) => call("DELETE", `/sites/${encodeURIComponent(slug)}`),
|
|
143
461
|
removeDeployment: (slug, id) => call("DELETE", `/sites/${encodeURIComponent(slug)}/deployments/${encodeURIComponent(id)}`)
|
|
144
462
|
};
|
|
@@ -246,7 +564,7 @@ import { fileURLToPath } from "url";
|
|
|
246
564
|
// package.json
|
|
247
565
|
var package_default = {
|
|
248
566
|
name: "mirrorbook",
|
|
249
|
-
version: "0.
|
|
567
|
+
version: "0.8.0",
|
|
250
568
|
description: "Publish HTML to a shareable URL. Agent-friendly: non-interactive, --json output, stable exit codes.",
|
|
251
569
|
type: "module",
|
|
252
570
|
bin: {
|
|
@@ -371,6 +689,7 @@ Recommended workflow:
|
|
|
371
689
|
Update a site ls (find the existing slug) \u2192 deploy <path> --slug <slug> --wait \u2192 status <slug>
|
|
372
690
|
Share privately deploy <path> --slug <slug> --password <pw> --expires 7d (or: access <slug> ...)
|
|
373
691
|
Went wrong status <slug> \u2192 rollback <slug> <version>
|
|
692
|
+
Set a cover cover <slug> cover.svg (or: deploy <path> --slug <slug> --cover cover.svg)
|
|
374
693
|
Use with AI agents mirrorbook skill --install (installs the usage guide into Claude Code)
|
|
375
694
|
After upgrading mirrorbook update (new CLI version? skill out of date? prints the fix commands)
|
|
376
695
|
|
|
@@ -587,19 +906,49 @@ var lockLines = (s) => {
|
|
|
587
906
|
...s.passwordProtected ? [] : [" note: no password set, so visitors never see this copy"]
|
|
588
907
|
];
|
|
589
908
|
};
|
|
590
|
-
|
|
909
|
+
async function readCover(file) {
|
|
910
|
+
const svg = file === "-" ? await readStdin2() : await readFile4(path4.resolve(file), "utf8").catch((e) => {
|
|
911
|
+
throw new CliError("usage", e.code === "ENOENT" ? `No such file: ${file}` : `Can't read ${file}: ${e.message}`, EXIT.usage);
|
|
912
|
+
});
|
|
913
|
+
const r = sanitizeCoverSvg(svg);
|
|
914
|
+
if (!r.ok) {
|
|
915
|
+
const why = {
|
|
916
|
+
empty: "the SVG is empty",
|
|
917
|
+
too_large: `it is larger than ${COVER_MAX_BYTES / 1024} KB`,
|
|
918
|
+
not_svg: "it is not an <svg> document",
|
|
919
|
+
parse_error: "the SVG could not be read (check that every tag is closed and attributes are quoted)",
|
|
920
|
+
doctype: "DOCTYPE declarations are not allowed",
|
|
921
|
+
no_viewbox: 'the <svg> needs a viewBox, e.g. viewBox="0 0 320 200"',
|
|
922
|
+
too_complex: "it has too many or too deeply nested elements"
|
|
923
|
+
};
|
|
924
|
+
throw new CliError(`cover_${r.error}`, `Can't use ${file} as a cover: ${why[r.error]}${r.detail ? ` (${r.detail})` : ""}`, EXIT.usage);
|
|
925
|
+
}
|
|
926
|
+
return svg;
|
|
927
|
+
}
|
|
928
|
+
async function applyCover(api, slug, svg) {
|
|
929
|
+
const r = await api.setCover(slug, svg);
|
|
930
|
+
if (r.dropped.length) info(`Cover saved. Removed: ${r.dropped.join(", ")}`);
|
|
931
|
+
return r;
|
|
932
|
+
}
|
|
933
|
+
program.command("deploy").description("Publish a directory, .zip, .html, .md, or .txt file. Markdown and text are turned into a web page. Re-deploying the same slug publishes a new version.").argument("<path>", "directory (with index.html or README.md), a .zip/.html/.md/.txt file, or - for stdin").option("-s, --slug <slug>", "subdomain: <slug>.mirrorbook.store (random if omitted; a suffix is added if it's taken)").option("--strict-slug", "fail with exit code 2 instead of adding a suffix when the slug is taken").option("-t, --title <title>", "site title").addOption(new Option("-f, --format <format>", "treat the input as html, markdown, or text (default: from the file extension; stdin is auto-detected)").choices(["html", "markdown", "text"])).option("-w, --wait", "wait until processing finishes").option("--timeout <sec>", "max seconds to wait", "300").option("--password <password>", "protect the site with a password (makes it unlisted; env MIRRORBOOK_SITE_PASSWORD avoids shell history)").option("--expires <when>", "how long the password stays valid: 7d, 12h, a date like 2026-12-31, or never").option("--lock-title <text>", `title shown on the password page (max ${LOCK_TITLE_MAX} chars)`).option("--lock-message <text>", `message shown above the password box, e.g. how to get the password (max ${LOCK_MESSAGE_MAX} chars)`).option("--clear-lock", "restore the default password page copy").option("--cover <file.svg>", "set the site's cover from an SVG file (see `mirrorbook cover --help`)").action(async (input, o) => {
|
|
934
|
+
if (o.cover === "-" && input === "-") throw new CliError("usage", "Only one of <path> and --cover can read from stdin", EXIT.usage);
|
|
935
|
+
const coverSvg = o.cover ? await readCover(o.cover) : void 0;
|
|
591
936
|
const api = await client();
|
|
592
937
|
const { blob, name, files, format } = await pack(input, o.format);
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
938
|
+
const onConflict = o.strictSlug ? "error" : void 0;
|
|
939
|
+
const res = format === "html" ? await api.deployHtml({ html: await blob.text(), slug: o.slug, title: o.title, onConflict }) : await (() => {
|
|
940
|
+
const form = new FormData();
|
|
941
|
+
form.set("file", blob, name);
|
|
942
|
+
if (format) form.set("format", format);
|
|
943
|
+
if (o.slug) form.set("slug", o.slug);
|
|
944
|
+
if (o.title) form.set("title", o.title);
|
|
945
|
+
if (onConflict) form.set("onConflict", onConflict);
|
|
946
|
+
return api.deploy(form);
|
|
947
|
+
})();
|
|
600
948
|
const { created, requestedSlug, slugAdjusted } = res;
|
|
601
949
|
let { site, deployment } = res;
|
|
602
950
|
site = await applyAccess(api, site.slug, o) ?? site;
|
|
951
|
+
if (coverSvg) site = (await applyCover(api, site.slug, coverSvg)).site;
|
|
603
952
|
if (o.wait) ({ site, deployment } = await waitFor(api, deployment.id, Number(o.timeout)));
|
|
604
953
|
out(
|
|
605
954
|
[
|
|
@@ -611,7 +960,7 @@ program.command("deploy").description("Publish a directory, .zip, .html, .md, or
|
|
|
611
960
|
` preview: ${deployment.previewUrl}`,
|
|
612
961
|
` status: ${describe(deployment)}`
|
|
613
962
|
].join("\n"),
|
|
614
|
-
{ url: site.url, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt, lockTitle: site.lockTitle, lockMessage: site.lockMessage, previewUrl: deployment.previewUrl, slug: site.slug, siteId: site.id, deploymentId: deployment.id, status: deployment.status, error: deployment.error, errorCode: deployment.errorCode, errorParams: deployment.errorParams, number: deployment.number, created, requestedSlug, slugAdjusted }
|
|
963
|
+
{ url: site.url, coverUrl: site.coverUrl, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt, lockTitle: site.lockTitle, lockMessage: site.lockMessage, previewUrl: deployment.previewUrl, slug: site.slug, siteId: site.id, deploymentId: deployment.id, status: deployment.status, error: deployment.error, errorCode: deployment.errorCode, errorParams: deployment.errorParams, number: deployment.number, created, requestedSlug, slugAdjusted }
|
|
615
964
|
);
|
|
616
965
|
process.exitCode = deploymentExit(deployment);
|
|
617
966
|
});
|
|
@@ -624,6 +973,29 @@ program.command("access").description("Set or change who can open a site: a pass
|
|
|
624
973
|
{ slug: site.slug, visibility: site.visibility, passwordProtected: site.passwordProtected, passwordExpiresAt: site.passwordExpiresAt, lockTitle: site.lockTitle, lockMessage: site.lockMessage }
|
|
625
974
|
);
|
|
626
975
|
});
|
|
976
|
+
program.command("cover").description("Set a site's cover (an SVG shown on site lists and your profile), or go back to the default pattern").argument("<slug>").argument("[file]", "an .svg file, or - for stdin").option("--remove", "remove the custom cover and use the default pattern").addHelpText(
|
|
977
|
+
"after",
|
|
978
|
+
`
|
|
979
|
+
SVG only, up to ${COVER_MAX_BYTES / 1024} KB, 16:10 works best (viewBox="0 0 320 200").
|
|
980
|
+
Scripts, event handlers, links, external images/fonts and url(...) to other files are removed.
|
|
981
|
+
For dark mode, use @media (prefers-color-scheme: dark) inside a <style> element.
|
|
982
|
+
|
|
983
|
+
Examples:
|
|
984
|
+
mirrorbook cover my-demo cover.svg
|
|
985
|
+
mirrorbook cover my-demo --remove`
|
|
986
|
+
).action(async (slug, file, o) => {
|
|
987
|
+
if (!!file === !!o.remove) throw new CliError("usage", "Pass an .svg file (or - for stdin), or --remove", EXIT.usage);
|
|
988
|
+
const svg = file ? await readCover(file) : void 0;
|
|
989
|
+
const api = await client();
|
|
990
|
+
if (!svg) {
|
|
991
|
+
const { site: site2 } = await api.removeCover(slug);
|
|
992
|
+
out(`${site2.slug}: using the default cover`, { ok: true, slug: site2.slug, coverUrl: null });
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
995
|
+
const { site, dropped } = await applyCover(api, slug, svg);
|
|
996
|
+
out(`${site.slug}: cover set
|
|
997
|
+
cover: ${site.coverUrl}`, { ok: true, slug: site.slug, coverUrl: site.coverUrl, dropped });
|
|
998
|
+
});
|
|
627
999
|
program.command("ls").description("List your sites").action(async () => {
|
|
628
1000
|
const { sites } = await (await client()).sites();
|
|
629
1001
|
const state = (s) => s.kind === "collection" ? `${s.itemCount} sites` : s.activeDeploymentId ? "live" : "not live";
|