@tobos/cli 0.4.43 → 0.4.44
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.
|
@@ -213,7 +213,7 @@ function mergeText(base, ours, theirs) {
|
|
|
213
213
|
...changes[0].map((h) => ({ ...h, side: 0 })),
|
|
214
214
|
...changes[1].map((h) => ({ ...h, side: 1 }))
|
|
215
215
|
].sort((x, y) => x.from - y.from || x.to - y.to);
|
|
216
|
-
const
|
|
216
|
+
const merged2 = [];
|
|
217
217
|
let at = 0;
|
|
218
218
|
for (let i = 0; i < hunks.length; ) {
|
|
219
219
|
const group = [hunks[i]];
|
|
@@ -242,11 +242,11 @@ function mergeText(base, ours, theirs) {
|
|
|
242
242
|
if (mine.join("") !== yours.join("")) return void 0;
|
|
243
243
|
lines = mine;
|
|
244
244
|
}
|
|
245
|
-
|
|
245
|
+
merged2.push(...b.slice(at, from), ...lines);
|
|
246
246
|
at = to;
|
|
247
247
|
}
|
|
248
|
-
|
|
249
|
-
return
|
|
248
|
+
merged2.push(...b.slice(at));
|
|
249
|
+
return merged2.join("");
|
|
250
250
|
}
|
|
251
251
|
function overlaps(hunk, from, to) {
|
|
252
252
|
return hunk.from < to || hunk.from === from || hunk.from === to && (hunk.to === to || from === to);
|
|
@@ -306,6 +306,160 @@ function middleHunks(a, b) {
|
|
|
306
306
|
close();
|
|
307
307
|
return hunks;
|
|
308
308
|
}
|
|
309
|
+
function mergeFile(path, base, ours, theirs) {
|
|
310
|
+
return path === "deck.json" ? mergeDeckJson(base, ours, theirs) : mergeText(base, ours, theirs);
|
|
311
|
+
}
|
|
312
|
+
var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
313
|
+
var canonical = (value) => JSON.stringify(
|
|
314
|
+
value,
|
|
315
|
+
(_, v) => isObject2(v) ? Object.fromEntries(Object.entries(v).sort(([x], [y]) => x < y ? -1 : 1)) : v
|
|
316
|
+
);
|
|
317
|
+
var same = (a, b) => canonical(a) === canonical(b);
|
|
318
|
+
function deckOf(text) {
|
|
319
|
+
let value;
|
|
320
|
+
try {
|
|
321
|
+
value = JSON.parse(text);
|
|
322
|
+
} catch {
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
325
|
+
if (!isObject2(value) || !Array.isArray(value.chapters)) return void 0;
|
|
326
|
+
const chapters = value.chapters;
|
|
327
|
+
const ok = chapters.every(
|
|
328
|
+
(c) => isObject2(c) && typeof c.id === "string" && Array.isArray(c.scenes) && c.scenes.every((s) => isObject2(s) && typeof s.id === "string")
|
|
329
|
+
);
|
|
330
|
+
if (!ok) return void 0;
|
|
331
|
+
const deck = value;
|
|
332
|
+
const ids = [
|
|
333
|
+
deck.chapters.map((c) => c.id),
|
|
334
|
+
deck.chapters.flatMap((c) => c.scenes.map((s) => s.id))
|
|
335
|
+
];
|
|
336
|
+
return ids.every((list) => new Set(list).size === list.length) ? deck : void 0;
|
|
337
|
+
}
|
|
338
|
+
var Conflict = class extends Error {
|
|
339
|
+
};
|
|
340
|
+
function merged(base, ours, theirs) {
|
|
341
|
+
if (same(ours, base)) return theirs;
|
|
342
|
+
if (same(theirs, base) || same(ours, theirs)) return ours;
|
|
343
|
+
if (!isObject2(ours) || !isObject2(theirs)) throw new Conflict();
|
|
344
|
+
const out = {};
|
|
345
|
+
const old = isObject2(base) ? base : {};
|
|
346
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(theirs), ...Object.keys(ours)])) {
|
|
347
|
+
const value = merged(old[key], ours[key], theirs[key]);
|
|
348
|
+
if (value !== void 0) out[key] = value;
|
|
349
|
+
}
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
function movedIn(base, side) {
|
|
353
|
+
const kept = side.filter((id) => base.includes(id));
|
|
354
|
+
const at = kept.map((id) => base.indexOf(id));
|
|
355
|
+
const tails = [];
|
|
356
|
+
const before = [];
|
|
357
|
+
at.forEach((value, i) => {
|
|
358
|
+
let lo = 0;
|
|
359
|
+
let hi = tails.length;
|
|
360
|
+
while (lo < hi) {
|
|
361
|
+
const mid = lo + hi >> 1;
|
|
362
|
+
if (at[tails[mid]] < value) lo = mid + 1;
|
|
363
|
+
else hi = mid;
|
|
364
|
+
}
|
|
365
|
+
before[i] = lo ? tails[lo - 1] : -1;
|
|
366
|
+
tails[lo] = i;
|
|
367
|
+
});
|
|
368
|
+
const run = /* @__PURE__ */ new Set();
|
|
369
|
+
for (let i = tails.at(-1) ?? -1; i >= 0; i = before[i]) run.add(kept[i]);
|
|
370
|
+
return new Set(kept.filter((id) => !run.has(id)));
|
|
371
|
+
}
|
|
372
|
+
function mergeDeckJson(base, ours, theirs) {
|
|
373
|
+
const lined = mergeText(base, ours, theirs);
|
|
374
|
+
const [b, o, t] = [deckOf(base), deckOf(ours), deckOf(theirs)];
|
|
375
|
+
if (!b || !o || !t) return lined;
|
|
376
|
+
try {
|
|
377
|
+
return byScene(b, o, t, lined, theirs);
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (error instanceof Conflict) return void 0;
|
|
380
|
+
throw error;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function putAfter(list, before, item) {
|
|
384
|
+
const at = before.map((id) => list.findIndex((x) => x.id === id)).find((x) => x >= 0);
|
|
385
|
+
list.splice((at ?? -1) + 1, 0, item);
|
|
386
|
+
}
|
|
387
|
+
var fieldsOf = ({ scenes: _, ...fields }) => fields;
|
|
388
|
+
function byScene(b, o, t, lined, theirs) {
|
|
389
|
+
const place = (deck) => new Map(deck.chapters.flatMap((c) => c.scenes.map((s) => [s.id, c.id])));
|
|
390
|
+
const order = (deck) => deck.chapters.flatMap((c) => c.scenes.map((s) => s.id));
|
|
391
|
+
const [inBase, inOurs] = [place(b), place(o)];
|
|
392
|
+
const sceneIn = (deck, id) => deck.chapters.flatMap((c) => c.scenes).find((s) => s.id === id);
|
|
393
|
+
const chapters = t.chapters.map((c) => ({ ...c, scenes: [...c.scenes] }));
|
|
394
|
+
const take = (id) => {
|
|
395
|
+
for (const c of chapters) {
|
|
396
|
+
const at = c.scenes.findIndex((s) => s.id === id);
|
|
397
|
+
if (at >= 0) return c.scenes.splice(at, 1)[0];
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
const before = (list, i) => list.slice(0, i).map((x) => x.id).reverse();
|
|
401
|
+
for (const id of order(b)) if (!inOurs.has(id)) take(id);
|
|
402
|
+
const moved = movedIn(order(b), order(o));
|
|
403
|
+
for (const c of o.chapters) {
|
|
404
|
+
c.scenes.forEach((scene, i) => {
|
|
405
|
+
const id = scene.id;
|
|
406
|
+
const added = !inBase.has(id);
|
|
407
|
+
const elsewhere = inBase.get(id) !== c.id;
|
|
408
|
+
if (!added && !moved.has(id) && !elsewhere) return;
|
|
409
|
+
const was = take(id);
|
|
410
|
+
if (!was && !added) return;
|
|
411
|
+
let chapter = chapters.find((x) => x.id === c.id);
|
|
412
|
+
if (!chapter) {
|
|
413
|
+
chapter = { ...fieldsOf(c), id: c.id, scenes: [] };
|
|
414
|
+
putAfter(chapters, before(o.chapters, o.chapters.indexOf(c)), chapter);
|
|
415
|
+
}
|
|
416
|
+
putAfter(chapter.scenes, before(c.scenes, i), was ?? scene);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
const movedChapters = movedIn(
|
|
420
|
+
b.chapters.map((c) => c.id),
|
|
421
|
+
o.chapters.map((c) => c.id)
|
|
422
|
+
);
|
|
423
|
+
o.chapters.forEach((c, i) => {
|
|
424
|
+
const at = chapters.findIndex((x) => x.id === c.id);
|
|
425
|
+
if (!movedChapters.has(c.id) || at < 0) return;
|
|
426
|
+
putAfter(chapters, before(o.chapters, i), chapters.splice(at, 1)[0]);
|
|
427
|
+
});
|
|
428
|
+
const result = merged(
|
|
429
|
+
{ ...b, chapters: null },
|
|
430
|
+
{ ...o, chapters: null },
|
|
431
|
+
{ ...t, chapters: null }
|
|
432
|
+
);
|
|
433
|
+
result.chapters = chapters.filter((c) => c.scenes.length > 0).map((c) => {
|
|
434
|
+
const keys = (deck) => {
|
|
435
|
+
const found = deck.chapters.find((x) => x.id === c.id);
|
|
436
|
+
return found && fieldsOf(found);
|
|
437
|
+
};
|
|
438
|
+
const fields = fieldsOf(c);
|
|
439
|
+
const head = merged(keys(b), keys(o), keys(t) ?? fields) ?? fields;
|
|
440
|
+
return {
|
|
441
|
+
...head,
|
|
442
|
+
scenes: c.scenes.map(
|
|
443
|
+
(s) => merged(
|
|
444
|
+
sceneIn(b, s.id),
|
|
445
|
+
sceneIn(o, s.id),
|
|
446
|
+
sceneIn(t, s.id) ?? s
|
|
447
|
+
) ?? s
|
|
448
|
+
)
|
|
449
|
+
};
|
|
450
|
+
});
|
|
451
|
+
const ordered = {};
|
|
452
|
+
for (const key of [...Object.keys(t), ...Object.keys(result)])
|
|
453
|
+
if (key in result && !(key in ordered)) ordered[key] = result[key];
|
|
454
|
+
if (lined !== void 0) {
|
|
455
|
+
const read = deckOf(lined);
|
|
456
|
+
if (read && same(read, ordered)) return lined;
|
|
457
|
+
}
|
|
458
|
+
const indent = /\n([ \t]+)"/.exec(theirs)?.[1] ?? "";
|
|
459
|
+
const text = indent ? JSON.stringify(ordered, null, indent) : JSON.stringify(ordered);
|
|
460
|
+
return theirs.endsWith("\n") ? `${text}
|
|
461
|
+
` : text;
|
|
462
|
+
}
|
|
309
463
|
|
|
310
464
|
// ../deck/src/tar.ts
|
|
311
465
|
init_define_TOBOS_PRESENT_TYPES();
|
|
@@ -357,6 +511,6 @@ export {
|
|
|
357
511
|
parseDeckJson,
|
|
358
512
|
parseMediaJson,
|
|
359
513
|
mediaTypeOf,
|
|
360
|
-
|
|
514
|
+
mergeFile,
|
|
361
515
|
unpackTar
|
|
362
516
|
};
|
package/dist/cli.js
CHANGED
|
@@ -4,10 +4,10 @@ const require = __tobosRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
formatProblems,
|
|
6
6
|
mediaTypeOf,
|
|
7
|
-
|
|
7
|
+
mergeFile,
|
|
8
8
|
parseMediaJson,
|
|
9
9
|
unpackTar
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-OXZ76F2K.js";
|
|
11
11
|
import {
|
|
12
12
|
ASK_THE_PERSON,
|
|
13
13
|
CliError,
|
|
@@ -256,7 +256,7 @@ function settings() {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
// src/api.ts
|
|
259
|
-
var VERSION = true ? "0.4.
|
|
259
|
+
var VERSION = true ? "0.4.44" : "dev";
|
|
260
260
|
function newer(a, b) {
|
|
261
261
|
const parse = (v) => /^\d+\.\d+\.\d+/.test(v) ? v.split(".").map((n) => parseInt(n)) : null;
|
|
262
262
|
const x = parse(a);
|
|
@@ -492,7 +492,7 @@ async function pullInto(root, deck, server, base, { note, clone = false }) {
|
|
|
492
492
|
const theirs = s === void 0 ? void 0 : await bytesOf(path, s);
|
|
493
493
|
const older = b === void 0 ? new Uint8Array() : await fileAt(deck, server, base.rev, path);
|
|
494
494
|
const texts = [older, ours, theirs].every((bytes) => bytes && isUtf8(bytes));
|
|
495
|
-
const merged = texts ?
|
|
495
|
+
const merged = texts ? mergeFile(path, textOf(older), textOf(ours), textOf(theirs)) : void 0;
|
|
496
496
|
if (merged !== void 0) write2(file2, Buffer.from(merged));
|
|
497
497
|
else if (texts) {
|
|
498
498
|
write2(file2, Buffer.from(marked(textOf(ours), textOf(theirs))));
|
|
@@ -990,16 +990,38 @@ Read AGENTS.md there first. Preview: ${info.url}`
|
|
|
990
990
|
clone: !found.base
|
|
991
991
|
});
|
|
992
992
|
await writeFormatGuide(found.root, base.server);
|
|
993
|
+
const page = pulled.rev === base.rev ? [] : await pageChanges(out, base.deck, base.server, base.rev, pulled.rev);
|
|
993
994
|
out.result(
|
|
994
|
-
{ id: base.deck, ...pulled },
|
|
995
|
+
{ id: base.deck, ...pulled, page },
|
|
995
996
|
() => [
|
|
996
997
|
`In step with the server (${pulled.rev?.slice(0, 7) ?? "no version yet"}): ${plural(pulled.changed.length, "file")} changed.`,
|
|
998
|
+
saidPage(page),
|
|
997
999
|
pulled.conflicts.length ? `${plural(pulled.conflicts.length, "conflict")}, between <<<<<<< and >>>>>>> in each: resolve them, then push.
|
|
998
1000
|
${pulled.conflicts.join("\n")}` : ""
|
|
999
1001
|
].filter(Boolean).join("\n")
|
|
1000
1002
|
);
|
|
1001
1003
|
if (pulled.conflicts.length) process.exitCode = EXIT.conflict;
|
|
1002
1004
|
}
|
|
1005
|
+
async function pageChanges(out, deck, server, since, until = null) {
|
|
1006
|
+
if (!since) return [];
|
|
1007
|
+
const range = `since=${encodeURIComponent(since)}${until ? `&until=${encodeURIComponent(until)}` : ""}`;
|
|
1008
|
+
try {
|
|
1009
|
+
const { pushes } = await api(`/api/decks/${deck}?${range}`, { server });
|
|
1010
|
+
return pushes.filter((p) => p.door === "browser").map((p) => ({ message: p.message ?? "Changed", author: p.author }));
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
out.note(
|
|
1013
|
+
`Couldn't ask what changed on the deck's page since ${since.slice(0, 7)}: its versions say. (${error.message})`,
|
|
1014
|
+
true
|
|
1015
|
+
);
|
|
1016
|
+
return [];
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
var saidPage = (changes) => changes.length ? [
|
|
1020
|
+
"Changed on the deck's page meanwhile:",
|
|
1021
|
+
...changes.map((c) => ` ${c.message}${c.author ? ` (${c.author})` : ""}`),
|
|
1022
|
+
// As the page's messages say it (arrangedMessage): “Renamed “…” to …”, or after a “; ”.
|
|
1023
|
+
changes.some((c) => /(^|; )renamed “/i.test(c.message)) ? "A scene renamed there keeps its slide's own heading: change that to match." : ""
|
|
1024
|
+
].filter(Boolean).join("\n") : "";
|
|
1003
1025
|
async function pullCopy(out, info, dir2) {
|
|
1004
1026
|
const { server } = settings();
|
|
1005
1027
|
out.note(`pulling ${info.title} into ${dir2}`);
|
|
@@ -1053,7 +1075,7 @@ async function check(out, args) {
|
|
|
1053
1075
|
);
|
|
1054
1076
|
const problems = [...written.problems];
|
|
1055
1077
|
if (args.values.types) {
|
|
1056
|
-
const { checkTypes } = await import("./types-
|
|
1078
|
+
const { checkTypes } = await import("./types-SSMTB62V.js");
|
|
1057
1079
|
problems.push(...await checkTypes(copy.root, (m) => out.note(m)));
|
|
1058
1080
|
}
|
|
1059
1081
|
const { errors, warnings } = problemSummary(problems);
|
|
@@ -1070,7 +1092,8 @@ async function check(out, args) {
|
|
|
1070
1092
|
}
|
|
1071
1093
|
async function pushCopy(out, copy, message) {
|
|
1072
1094
|
const changes = changesOf(copy);
|
|
1073
|
-
if (changes.length === 0)
|
|
1095
|
+
if (changes.length === 0)
|
|
1096
|
+
return { pushed: false, rev: copy.base.rev, uploaded: [], page: [] };
|
|
1074
1097
|
noteSizes(
|
|
1075
1098
|
out,
|
|
1076
1099
|
copy.root,
|
|
@@ -1097,16 +1120,22 @@ async function pushCopy(out, copy, message) {
|
|
|
1097
1120
|
pushed: true,
|
|
1098
1121
|
rev: written.rev,
|
|
1099
1122
|
uploaded: written.uploaded,
|
|
1100
|
-
problems: written.problems
|
|
1123
|
+
problems: written.problems,
|
|
1124
|
+
// What the page changed that this push merged in, which the copy has now.
|
|
1125
|
+
page: await pageChanges(out, copy.base.deck, copy.base.server, copy.base.rev, written.rev)
|
|
1101
1126
|
};
|
|
1102
1127
|
}
|
|
1103
1128
|
async function push(out, args) {
|
|
1104
1129
|
const copy = requireCopy();
|
|
1105
|
-
const
|
|
1130
|
+
const pushed = await pushCopy(out, copy, args.values.message);
|
|
1131
|
+
const result = pushed.pushed ? pushed : { ...pushed, page: await pageChanges(out, copy.base.deck, copy.base.server, copy.base.rev) };
|
|
1106
1132
|
const url = `${copy.base.server}/${copy.base.deck}`;
|
|
1107
1133
|
out.result(
|
|
1108
1134
|
{ ...result, url },
|
|
1109
|
-
() =>
|
|
1135
|
+
() => [
|
|
1136
|
+
result.pushed ? `\u2713 Pushed ${result.rev?.slice(0, 7)}${result.uploaded.length ? ` with ${plural(result.uploaded.length, "media file")}` : ""}. Live at ${url}` : result.page.length ? `Nothing to push, but the deck's page changed since this copy's version: run \`tobos pull\`. Live at ${url}` : `Nothing to push: the copy has no changes of its own. Live at ${url}`,
|
|
1137
|
+
saidPage(result.page)
|
|
1138
|
+
].filter(Boolean).join("\n")
|
|
1110
1139
|
);
|
|
1111
1140
|
}
|
|
1112
1141
|
async function pushIfChanged(out, id, message) {
|