mirrorbook 0.2.0 → 0.3.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/dist/cli.js +118 -12
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
|
-
import { cp, mkdir as
|
|
6
|
-
import { homedir as
|
|
7
|
-
import
|
|
8
|
-
import { fileURLToPath } from "url";
|
|
5
|
+
import { cp, mkdir as mkdir3, readFile as readFile4 } from "fs/promises";
|
|
6
|
+
import { homedir as homedir3, hostname, platform } from "os";
|
|
7
|
+
import path4 from "path";
|
|
8
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
9
9
|
import { createInterface } from "readline/promises";
|
|
10
10
|
import { Command, Option } from "commander";
|
|
11
11
|
|
|
@@ -220,10 +220,16 @@ async function pack(input, format) {
|
|
|
220
220
|
return { blob: new Blob([buf]), name: path2.basename(input), format: f };
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
// src/update.ts
|
|
224
|
+
import { readFile as readFile3, mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
225
|
+
import { homedir as homedir2 } from "os";
|
|
226
|
+
import path3 from "path";
|
|
227
|
+
import { fileURLToPath } from "url";
|
|
228
|
+
|
|
223
229
|
// package.json
|
|
224
230
|
var package_default = {
|
|
225
231
|
name: "mirrorbook",
|
|
226
|
-
version: "0.
|
|
232
|
+
version: "0.3.0",
|
|
227
233
|
description: "Publish HTML to a shareable URL. Agent-friendly: non-interactive, --json output, stable exit codes.",
|
|
228
234
|
type: "module",
|
|
229
235
|
bin: {
|
|
@@ -240,7 +246,8 @@ var package_default = {
|
|
|
240
246
|
scripts: {
|
|
241
247
|
dev: "tsx src/cli.ts",
|
|
242
248
|
build: "tsup",
|
|
243
|
-
typecheck: "tsc -p ."
|
|
249
|
+
typecheck: "tsc -p .",
|
|
250
|
+
prepack: "tsup"
|
|
244
251
|
},
|
|
245
252
|
devDependencies: {
|
|
246
253
|
"@mirrorbook/shared": "workspace:*"
|
|
@@ -251,6 +258,93 @@ var package_default = {
|
|
|
251
258
|
}
|
|
252
259
|
};
|
|
253
260
|
|
|
261
|
+
// src/update.ts
|
|
262
|
+
var CACHE = path3.join(path3.dirname(configPath), "update.json");
|
|
263
|
+
var DAY = 24 * 60 * 60 * 1e3;
|
|
264
|
+
var UPDATE_COMMAND = "npm i -g mirrorbook@latest";
|
|
265
|
+
var SKILL_COMMAND = "mirrorbook skill --install";
|
|
266
|
+
function isNewer(latest, current) {
|
|
267
|
+
const n = (v) => (v.split("-")[0] ?? "").split(".").map((x) => Number.parseInt(x, 10) || 0);
|
|
268
|
+
const [a, b] = [n(latest), n(current)];
|
|
269
|
+
for (let i = 0; i < 3; i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
async function readCache() {
|
|
273
|
+
try {
|
|
274
|
+
return JSON.parse(await readFile3(CACHE, "utf8"));
|
|
275
|
+
} catch {
|
|
276
|
+
return void 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async function writeCache(c) {
|
|
280
|
+
try {
|
|
281
|
+
await mkdir2(path3.dirname(CACHE), { recursive: true, mode: 448 });
|
|
282
|
+
await writeFile2(CACHE, JSON.stringify(c));
|
|
283
|
+
} catch {
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
async function fetchLatest(timeoutMs) {
|
|
287
|
+
try {
|
|
288
|
+
const res = await fetch("https://registry.npmjs.org/mirrorbook/latest", { signal: AbortSignal.timeout(timeoutMs) });
|
|
289
|
+
if (!res.ok) return void 0;
|
|
290
|
+
return (await res.json()).version;
|
|
291
|
+
} catch {
|
|
292
|
+
return void 0;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async function staleSkills() {
|
|
296
|
+
let bundled;
|
|
297
|
+
try {
|
|
298
|
+
bundled = await readFile3(fileURLToPath(new URL("../SKILL.md", import.meta.url)), "utf8");
|
|
299
|
+
} catch {
|
|
300
|
+
return { installed: [], stale: [] };
|
|
301
|
+
}
|
|
302
|
+
const candidates = [path3.join(homedir2(), ".claude", "skills", "mirrorbook", "SKILL.md"), path3.resolve(".claude", "skills", "mirrorbook", "SKILL.md")];
|
|
303
|
+
const installed = [];
|
|
304
|
+
const stale = [];
|
|
305
|
+
for (const p of candidates) {
|
|
306
|
+
try {
|
|
307
|
+
const text = await readFile3(p, "utf8");
|
|
308
|
+
installed.push(p);
|
|
309
|
+
if (text !== bundled) stale.push(p);
|
|
310
|
+
} catch {
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { installed, stale };
|
|
314
|
+
}
|
|
315
|
+
async function checkUpdate() {
|
|
316
|
+
const latest = await fetchLatest(5e3);
|
|
317
|
+
if (latest) await writeCache({ ...await readCache(), checkedAt: Date.now(), latest });
|
|
318
|
+
const skill = await staleSkills();
|
|
319
|
+
return {
|
|
320
|
+
current: package_default.version,
|
|
321
|
+
latest: latest ?? null,
|
|
322
|
+
updateAvailable: latest ? isNewer(latest, package_default.version) : false,
|
|
323
|
+
updateCommand: UPDATE_COMMAND,
|
|
324
|
+
skill: { installed: skill.installed, stale: skill.stale, updateCommand: SKILL_COMMAND },
|
|
325
|
+
error: latest ? null : "could not reach the npm registry"
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async function passiveNotice() {
|
|
329
|
+
if (process.env.MIRRORBOOK_NO_UPDATE_CHECK === "1") return;
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
let cache = await readCache() ?? { checkedAt: 0 };
|
|
332
|
+
if (now - cache.checkedAt > DAY) {
|
|
333
|
+
const latest = await fetchLatest(1500);
|
|
334
|
+
cache = { ...cache, checkedAt: now, latest: latest ?? cache.latest };
|
|
335
|
+
await writeCache(cache);
|
|
336
|
+
}
|
|
337
|
+
const lines = [];
|
|
338
|
+
if (cache.latest && isNewer(cache.latest, package_default.version)) lines.push(`mirrorbook ${cache.latest} is available (you have ${package_default.version}). Update: ${UPDATE_COMMAND}`);
|
|
339
|
+
const { stale } = await staleSkills();
|
|
340
|
+
if (stale.length) lines.push(`The installed mirrorbook skill is out of date (${stale.join(", ")}). Refresh: ${SKILL_COMMAND}`);
|
|
341
|
+
if (!lines.length || cache.notifiedAt && now - cache.notifiedAt < DAY) return;
|
|
342
|
+
await writeCache({ ...cache, notifiedAt: now });
|
|
343
|
+
process.stderr.write(`
|
|
344
|
+
${lines.map((l) => `notice: ${l}`).join("\n")}
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
347
|
+
|
|
254
348
|
// src/cli.ts
|
|
255
349
|
var program = new Command().name("mirrorbook").description("Publish HTML to a shareable URL on mirrorbook.mixdao.world").version(package_default.version).addOption(new Option("--json", "print one JSON object to stdout (also MIRRORBOOK_JSON=1)").default(process.env.MIRRORBOOK_JSON === "1")).option("-n, --server <name>", "use a saved server for this command (env MIRRORBOOK_SERVER); see `mirrorbook servers`").option("--api-url <url>", "server URL, overrides the saved one (env MIRRORBOOK_API_URL)").option("--token <token>", "API token, overrides the saved one (env MIRRORBOOK_TOKEN)").showHelpAfterError().addHelpText(
|
|
256
350
|
"after",
|
|
@@ -261,6 +355,7 @@ Recommended workflow:
|
|
|
261
355
|
Share privately deploy <path> --slug <slug> --password <pw> --expires 7d (or: access <slug> ...)
|
|
262
356
|
Went wrong status <slug> \u2192 rollback <slug> <version>
|
|
263
357
|
Use with AI agents mirrorbook skill --install (installs the usage guide into Claude Code)
|
|
358
|
+
After upgrading mirrorbook update (new CLI version? skill out of date? prints the fix commands)
|
|
264
359
|
|
|
265
360
|
Always run \`mirrorbook ls\` before picking a slug: re-deploying an existing slug publishes a new
|
|
266
361
|
version of that site, a new slug creates a new site.
|
|
@@ -401,17 +496,27 @@ program.command("use").description("Switch the current server").argument("<name>
|
|
|
401
496
|
out(`Now using ${name} (${cfg.servers[name].url})`, { ok: true, server: name, url: cfg.servers[name].url });
|
|
402
497
|
});
|
|
403
498
|
program.command("skill").description("Print the agent skill (SKILL.md) for this CLI, or install it for Claude Code with --install").option("--install", "copy SKILL.md to ~/.claude/skills/mirrorbook/ (Claude Code loads it automatically)").option("--dir <dir>", "install into <dir>/mirrorbook/ instead, e.g. ./.claude/skills for this project only").action(async (o) => {
|
|
404
|
-
const src =
|
|
499
|
+
const src = fileURLToPath2(new URL("../SKILL.md", import.meta.url));
|
|
405
500
|
if (!o.install && !o.dir) {
|
|
406
|
-
const text = await
|
|
501
|
+
const text = await readFile4(src, "utf8");
|
|
407
502
|
if (g().json) out("", { path: src, content: text });
|
|
408
503
|
else process.stdout.write(text);
|
|
409
504
|
return;
|
|
410
505
|
}
|
|
411
|
-
const dest =
|
|
412
|
-
await
|
|
413
|
-
await cp(src,
|
|
414
|
-
out(`Installed skill to ${dest}/SKILL.md. Restart Claude Code to pick it up.`, { ok: true, path:
|
|
506
|
+
const dest = path4.join(o.dir ? path4.resolve(o.dir) : path4.join(homedir3(), ".claude", "skills"), "mirrorbook");
|
|
507
|
+
await mkdir3(dest, { recursive: true });
|
|
508
|
+
await cp(src, path4.join(dest, "SKILL.md"));
|
|
509
|
+
out(`Installed skill to ${dest}/SKILL.md. Restart Claude Code to pick it up.`, { ok: true, path: path4.join(dest, "SKILL.md") });
|
|
510
|
+
});
|
|
511
|
+
program.command("update").description("Check npm for a newer mirrorbook and whether the installed Claude Code skill is out of date").action(async () => {
|
|
512
|
+
const r = await checkUpdate();
|
|
513
|
+
const lines = [`mirrorbook ${r.current}${r.latest ? ` (latest ${r.latest})` : ""}`];
|
|
514
|
+
if (r.error) lines.push(`! ${r.error}`);
|
|
515
|
+
else lines.push(r.updateAvailable ? `Update available: ${r.updateCommand}` : "Up to date");
|
|
516
|
+
if (r.skill.stale.length) lines.push(`Skill out of date: ${r.skill.stale.join(", ")} \u2192 ${r.skill.updateCommand}`);
|
|
517
|
+
else if (r.skill.installed.length) lines.push("Skill up to date");
|
|
518
|
+
else lines.push(`Skill not installed \u2192 ${r.skill.updateCommand}`);
|
|
519
|
+
out(lines.join("\n"), r);
|
|
415
520
|
});
|
|
416
521
|
program.command("whoami").description("Show the current server and account").action(async () => {
|
|
417
522
|
const { name, apiUrl } = await auth();
|
|
@@ -530,6 +635,7 @@ program.command("rm").description("Delete a site and all its versions").argument
|
|
|
530
635
|
});
|
|
531
636
|
try {
|
|
532
637
|
await program.parseAsync();
|
|
638
|
+
if (process.argv[2] !== "update") await passiveNotice();
|
|
533
639
|
} catch (e) {
|
|
534
640
|
const err = e instanceof CliError ? e : new CliError("internal", e.message, EXIT.error);
|
|
535
641
|
if (g().json) process.stdout.write(`${JSON.stringify({ error: { code: err.code, message: err.message } })}
|