@tobos/cli 0.4.20 → 0.4.22

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.
@@ -55091,6 +55091,87 @@ function sha256(data2) {
55091
55091
  return createHash("sha256").update(data2).digest("hex");
55092
55092
  }
55093
55093
 
55094
+ // ../deck/src/share.ts
55095
+ init_define_TOBOS_PRESENT_TYPES();
55096
+ init_define_TOBOS_SKILL();
55097
+ init_define_TOBOS_TOOLCHAIN();
55098
+ var DECK_PREFIX = "@deck/";
55099
+ var MASTER_PREFIX = `${DECK_PREFIX}master/`;
55100
+ function sharedManifest(manifest) {
55101
+ const { uses, ...rest2 } = manifest;
55102
+ const chapters = manifest.chapters.map((chapter) => ({
55103
+ ...chapter,
55104
+ scenes: chapter.scenes.filter((scene) => !scene.activity).map((scene) => {
55105
+ const shown = { ...scene };
55106
+ delete shown.note;
55107
+ return shown;
55108
+ })
55109
+ })).filter((chapter) => chapter.scenes.length > 0);
55110
+ if (!uses) {
55111
+ const left = new Set(
55112
+ manifest.chapters.flatMap((c) => c.scenes.filter((s) => s.activity).map((s) => s.module))
55113
+ );
55114
+ return {
55115
+ ...rest2,
55116
+ imports: Object.fromEntries(
55117
+ Object.entries(manifest.imports).filter(([specifier]) => !left.has(specifier))
55118
+ ),
55119
+ chapters
55120
+ };
55121
+ }
55122
+ const { reached, media } = walk2(
55123
+ manifest.media,
55124
+ uses,
55125
+ chapters.flatMap((c) => c.scenes.map((s) => s.module))
55126
+ );
55127
+ return {
55128
+ ...rest2,
55129
+ // The packages the server bundled stay: they are npm's, not the deck's.
55130
+ imports: Object.fromEntries(
55131
+ Object.entries(manifest.imports).filter(
55132
+ ([specifier]) => !specifier.startsWith(DECK_PREFIX) || reached.has(specifier)
55133
+ )
55134
+ ),
55135
+ media: Object.fromEntries(Object.entries(manifest.media).filter(([name]) => media.has(name))),
55136
+ chapters
55137
+ };
55138
+ }
55139
+ function mediaInUse(manifest) {
55140
+ const { uses } = manifest;
55141
+ if (!uses) return manifest.media;
55142
+ const roots = [
55143
+ ...manifest.chapters.flatMap((c) => c.scenes.map((s) => s.module)),
55144
+ ...Object.keys(uses.modules).filter((specifier) => specifier.startsWith(MASTER_PREFIX))
55145
+ ];
55146
+ const { media } = walk2(manifest.media, uses, roots);
55147
+ return Object.fromEntries(
55148
+ Object.entries(manifest.media).filter(
55149
+ ([name]) => media.has(name) || name.startsWith("master/")
55150
+ )
55151
+ );
55152
+ }
55153
+ function walk2(all, uses, roots) {
55154
+ const reached = /* @__PURE__ */ new Set();
55155
+ const media = new Set(uses.styles);
55156
+ const patterns = /* @__PURE__ */ new Set();
55157
+ const queue = [...roots];
55158
+ while (queue.length > 0) {
55159
+ const specifier = queue.pop();
55160
+ if (reached.has(specifier)) continue;
55161
+ reached.add(specifier);
55162
+ const used = Object.hasOwn(uses.modules, specifier) ? uses.modules[specifier] : void 0;
55163
+ queue.push(...used?.imports ?? []);
55164
+ for (const name of used?.media ?? []) media.add(name);
55165
+ for (const pattern of used?.patterns ?? []) patterns.add(pattern);
55166
+ }
55167
+ const named = Object.keys(all).filter((name) => !media.has(name));
55168
+ for (const name of mediaMatching(named, patterns)) media.add(name);
55169
+ return { reached, media };
55170
+ }
55171
+ function servesModule(manifest, path) {
55172
+ return Object.values(manifest.imports).includes(path) || (manifest.styles ?? []).includes(path);
55173
+ }
55174
+
55094
55175
  // ../deck/src/strip-types.ts
55095
55176
  init_define_TOBOS_PRESENT_TYPES();
55096
55177
  init_define_TOBOS_SKILL();
@@ -55111,7 +55192,7 @@ function stripTypes(source2) {
55111
55192
  }
55112
55193
 
55113
55194
  // ../deck/src/build.ts
55114
- var DECK_PREFIX = "@deck/";
55195
+ var DECK_PREFIX2 = "@deck/";
55115
55196
  var SOURCE = /\.(svelte|ts|js|mjs|json)$/;
55116
55197
  var RUNTIME_PACKAGES = /* @__PURE__ */ new Set(["svelte", "gsap", "@tobos/present"]);
55117
55198
  var BuildCache = class {
@@ -55425,7 +55506,7 @@ function emitModules(compiled) {
55425
55506
  for (const entry of file.imports) {
55426
55507
  const spec = entry.specifier;
55427
55508
  if (!spec.startsWith("./") && !spec.startsWith("../")) continue;
55428
- const replacement = DECK_PREFIX + resolvePath(path, spec);
55509
+ const replacement = DECK_PREFIX2 + resolvePath(path, spec);
55429
55510
  const quoted = entry.dynamic && /^['"`]/.test(file.code.slice(entry.start, entry.start + 1));
55430
55511
  code += file.code.slice(last, entry.start) + (quoted ? JSON.stringify(replacement) : replacement);
55431
55512
  last = entry.end;
@@ -55433,7 +55514,7 @@ function emitModules(compiled) {
55433
55514
  code += file.code.slice(last);
55434
55515
  const name = `m/${sha256(code).slice(0, 20)}.js`;
55435
55516
  modules.set(name, code);
55436
- imports2[DECK_PREFIX + path] = name;
55517
+ imports2[DECK_PREFIX2 + path] = name;
55437
55518
  }
55438
55519
  return {
55439
55520
  modules,
@@ -55463,11 +55544,11 @@ function modulesUses(compiled, mediaOf) {
55463
55544
  const imports2 = /* @__PURE__ */ new Set();
55464
55545
  for (const { specifier } of file.imports)
55465
55546
  if (specifier?.startsWith("./") || specifier?.startsWith("../"))
55466
- imports2.add(DECK_PREFIX + resolvePath(path, specifier));
55547
+ imports2.add(DECK_PREFIX2 + resolvePath(path, specifier));
55467
55548
  const names = /* @__PURE__ */ new Set();
55468
55549
  const patterns = /* @__PURE__ */ new Set();
55469
55550
  for (const ref2 of mediaOf.get(path) ?? []) (ref2.pattern ? patterns : names).add(ref2.name);
55470
- modules[DECK_PREFIX + path] = {
55551
+ modules[DECK_PREFIX2 + path] = {
55471
55552
  ...imports2.size ? { imports: [...imports2].sort() } : {},
55472
55553
  ...names.size ? { media: [...names].sort() } : {},
55473
55554
  ...patterns.size ? { patterns: [...patterns].sort() } : {}
@@ -55476,23 +55557,19 @@ function modulesUses(compiled, mediaOf) {
55476
55557
  return modules;
55477
55558
  }
55478
55559
  var sizeText = (bytes) => bytes < 1e6 ? `${Math.ceil(bytes / 1e3)} KB` : `${+(bytes / 1e6).toFixed(1)} MB`;
55479
- function unusedMedia(media, uses) {
55480
- const used = new Set(uses.styles);
55481
- const patterns = /* @__PURE__ */ new Set();
55482
- for (const { media: names, patterns: more } of Object.values(uses.modules)) {
55483
- for (const name of names ?? []) used.add(name);
55484
- for (const pattern of more ?? []) patterns.add(pattern);
55485
- }
55486
- const named = Object.keys(media).filter((name) => !used.has(name) && !name.startsWith("master/"));
55487
- const matched = new Set(mediaMatching(named, patterns));
55488
- const unused = named.filter((name) => !matched.has(name));
55560
+ var KEPT_MEDIA_DAYS = 7;
55561
+ function unusedMedia(manifest) {
55562
+ const { media } = manifest;
55563
+ const used = mediaInUse(manifest);
55564
+ const unused = Object.keys(media).filter((name) => !Object.hasOwn(used, name));
55489
55565
  if (unused.length === 0) return void 0;
55490
55566
  const bytes = unused.reduce((sum, name) => sum + media[name].size, 0);
55491
55567
  const shown = unused.length > 10 ? [...unused.slice(0, 10), `${unused.length - 10} more`] : unused;
55568
+ const one = unused.length === 1;
55492
55569
  return {
55493
55570
  file: "media.json",
55494
55571
  rule: "media",
55495
- message: `media.json lists ${unused.length === 1 ? "1 file" : `${unused.length} files`} no scene or master uses (${sizeText(bytes)}): ${and(shown)}. Remove ${unused.length === 1 ? "it" : "them"} from media/ and media.json to free their room.`,
55572
+ message: `media.json lists ${one ? "1 file" : `${unused.length} files`} no slide shows (${sizeText(bytes)}): ${and(shown)}. ${one ? "It doesn't" : "They don't"} count toward the plan, and the server keeps ${one ? "it" : "them"} for ${KEPT_MEDIA_DAYS} days: to show ${one ? "it" : "one"} after that, drop it again, or push it from media/.`,
55496
55573
  severity: "warning"
55497
55574
  };
55498
55575
  }
@@ -55590,8 +55667,6 @@ async function buildDeck(tree, options = {}) {
55590
55667
  modules: modulesUses(graph.compiled, mediaOf),
55591
55668
  styles: stylesheet?.media ?? []
55592
55669
  };
55593
- const unused = unusedMedia(media, uses);
55594
- if (unused) problems.push(unused);
55595
55670
  const chapters = deck.chapters.map((chapter) => ({
55596
55671
  id: chapter.id,
55597
55672
  title: chapter.title,
@@ -55602,11 +55677,13 @@ async function buildDeck(tree, options = {}) {
55602
55677
  id: scene.id,
55603
55678
  title: scene.title,
55604
55679
  beats: (analysis?.beats ?? []).map((b) => b.id),
55605
- module: DECK_PREFIX + file,
55680
+ module: DECK_PREFIX2 + file,
55606
55681
  ...analysis?.activity ? { activity: analysis.activity.activity } : {}
55607
55682
  };
55608
55683
  })
55609
55684
  }));
55685
+ const unused = unusedMedia({ chapters, media, uses });
55686
+ if (unused) problems.push(unused);
55610
55687
  for (const [key2, file] of graph.fresh) options.cache?.set(key2, file);
55611
55688
  return {
55612
55689
  problems,
@@ -55668,64 +55745,6 @@ async function masterOf(tree) {
55668
55745
  return { files, media, dependencies: await masterDependencies(tree) };
55669
55746
  }
55670
55747
 
55671
- // ../deck/src/share.ts
55672
- init_define_TOBOS_PRESENT_TYPES();
55673
- init_define_TOBOS_SKILL();
55674
- init_define_TOBOS_TOOLCHAIN();
55675
- var DECK_PREFIX2 = "@deck/";
55676
- function sharedManifest(manifest) {
55677
- const { uses, ...rest2 } = manifest;
55678
- const chapters = manifest.chapters.map((chapter) => ({
55679
- ...chapter,
55680
- scenes: chapter.scenes.filter((scene) => !scene.activity).map((scene) => {
55681
- const shown = { ...scene };
55682
- delete shown.note;
55683
- return shown;
55684
- })
55685
- })).filter((chapter) => chapter.scenes.length > 0);
55686
- if (!uses) {
55687
- const left = new Set(
55688
- manifest.chapters.flatMap((c) => c.scenes.filter((s) => s.activity).map((s) => s.module))
55689
- );
55690
- return {
55691
- ...rest2,
55692
- imports: Object.fromEntries(
55693
- Object.entries(manifest.imports).filter(([specifier]) => !left.has(specifier))
55694
- ),
55695
- chapters
55696
- };
55697
- }
55698
- const reached = /* @__PURE__ */ new Set();
55699
- const media = new Set(uses.styles);
55700
- const patterns = /* @__PURE__ */ new Set();
55701
- const queue = chapters.flatMap((c) => c.scenes.map((s) => s.module));
55702
- while (queue.length > 0) {
55703
- const specifier = queue.pop();
55704
- if (reached.has(specifier)) continue;
55705
- reached.add(specifier);
55706
- const used = Object.hasOwn(uses.modules, specifier) ? uses.modules[specifier] : void 0;
55707
- queue.push(...used?.imports ?? []);
55708
- for (const name of used?.media ?? []) media.add(name);
55709
- for (const pattern of used?.patterns ?? []) patterns.add(pattern);
55710
- }
55711
- const named = Object.keys(manifest.media).filter((name) => !media.has(name));
55712
- for (const name of mediaMatching(named, patterns)) media.add(name);
55713
- return {
55714
- ...rest2,
55715
- // The packages the server bundled stay: they are npm's, not the deck's.
55716
- imports: Object.fromEntries(
55717
- Object.entries(manifest.imports).filter(
55718
- ([specifier]) => !specifier.startsWith(DECK_PREFIX2) || reached.has(specifier)
55719
- )
55720
- ),
55721
- media: Object.fromEntries(Object.entries(manifest.media).filter(([name]) => media.has(name))),
55722
- chapters
55723
- };
55724
- }
55725
- function servesModule(manifest, path) {
55726
- return Object.values(manifest.imports).includes(path) || (manifest.styles ?? []).includes(path);
55727
- }
55728
-
55729
55748
  // ../deck/src/format-problems.ts
55730
55749
  init_define_TOBOS_PRESENT_TYPES();
55731
55750
  init_define_TOBOS_SKILL();
@@ -55792,10 +55811,12 @@ export {
55792
55811
  parseMediaJson,
55793
55812
  formatMediaJson,
55794
55813
  sha256,
55814
+ sharedManifest,
55815
+ mediaInUse,
55816
+ servesModule,
55795
55817
  createCache,
55818
+ KEPT_MEDIA_DAYS,
55796
55819
  buildDeck,
55797
55820
  masterOf,
55798
- sharedManifest,
55799
- servesModule,
55800
55821
  mediaTypeOf
55801
55822
  };
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  formatMediaJson,
6
6
  formatProblems,
7
7
  mediaTypeOf
8
- } from "./chunk-L3I6AVL4.js";
8
+ } from "./chunk-6VC3QOQM.js";
9
9
  import {
10
10
  ASK_THE_PERSON,
11
11
  CliError,
@@ -89,7 +89,7 @@ function settings() {
89
89
  }
90
90
 
91
91
  // src/api.ts
92
- var VERSION = true ? "0.4.20" : "dev";
92
+ var VERSION = true ? "0.4.22" : "dev";
93
93
  function newer(a, b) {
94
94
  const parse = (v) => /^\d+\.\d+\.\d+/.test(v) ? v.split(".").map((n) => parseInt(n)) : null;
95
95
  const x = parse(a);
@@ -424,20 +424,22 @@ async function syncMediaJson(root) {
424
424
  async function uploadMedia(root, media, server, deck, note) {
425
425
  const hashes = [...new Set(Object.values(media).map((m) => m.hash))];
426
426
  if (hashes.length === 0) return [];
427
- const { missing } = await api("/api/media/missing", {
428
- body: { hashes },
429
- server
430
- });
427
+ const { missing, elsewhere = 0 } = await api(
428
+ "/api/media/missing",
429
+ { body: { hashes, deck }, server }
430
+ );
431
+ const sizes = Object.fromEntries(Object.values(media).map((m) => [m.hash, m.size]));
432
+ const shows = Object.values(sizes).reduce((sum, size) => sum + size, 0) - elsewhere;
431
433
  const uploaded = [];
432
434
  for (const hash of missing) {
433
435
  const [name, entry] = Object.entries(media).find(([, m]) => m.hash === hash);
434
436
  const path = mediaFile(root, name);
435
437
  if (!existsSync2(path))
436
438
  throw new CliError(
437
- `media/${name} is in media.json but not on this machine, and the server doesn't have it.`
439
+ `media/${name} is on a slide but not on this machine, and the server doesn't have it: put it in media/, then push again.`
438
440
  );
439
441
  note(`uploading media/${name} (${Math.round(entry.size / 1e3)} kB)`);
440
- const response = await request(`/api/media/${hash}?deck=${deck}`, {
442
+ const response = await request(`/api/media/${hash}?deck=${deck}&shows=${shows}`, {
441
443
  method: "PUT",
442
444
  body: Readable.toWeb(createReadStream(path)),
443
445
  contentType: entry.type,
@@ -730,7 +732,7 @@ async function pushedFiles(root) {
730
732
  }
731
733
  }
732
734
  async function runCheck(dir2) {
733
- const { buildDeck } = await import("./src-HNFV4MW7.js");
735
+ const { buildDeck } = await import("./src-ZEUJHNUL.js");
734
736
  const started = performance.now();
735
737
  const files = await pushedFiles(dir2.root);
736
738
  const result = await buildDeck(directoryTree(dir2.root, files));
@@ -791,7 +793,7 @@ async function check(out, args) {
791
793
  await syncMediaJson(deck.root);
792
794
  const result = await runCheck(deck);
793
795
  if (args.values.types) {
794
- const { checkTypes } = await import("./types-NZUVJ337.js");
796
+ const { checkTypes } = await import("./types-WUAQW4MO.js");
795
797
  const sent = result.files && new Set(result.files);
796
798
  result.problems.push(
797
799
  ...(await checkTypes(deck.root, (m) => out.note(m))).filter((p) => sent?.has(p.file) ?? true)
@@ -818,11 +820,13 @@ async function pushWorkingCopy(out, deck, message) {
818
820
  const result = await runCheck(deck);
819
821
  const { errors, warnings } = problemSummary(result.problems);
820
822
  if (errors > 0) return { ok: false, errors, warnings, problems: result.problems };
821
- for (const [name, entry] of Object.entries(media)) {
823
+ const { mediaInUse } = await import("./src-ZEUJHNUL.js");
824
+ const shown = result.manifest ? mediaInUse(result.manifest) : media;
825
+ for (const [name, entry] of Object.entries(shown)) {
822
826
  const note = sizeNote(name, entry.size);
823
827
  if (note) out.note(note, true);
824
828
  }
825
- const uploaded = await uploadMedia(root, media, server, deck.id, (m) => out.note(m));
829
+ const uploaded = await uploadMedia(root, shown, server, deck.id, (m) => out.note(m));
826
830
  await gitOk(["add", "-A"], { cwd: root });
827
831
  const committed = (await gitOk(["diff", "--cached", "--name-only"], { cwd: root })).split("\n").filter(Boolean);
828
832
  for (const file2 of committed) out.note(` ${file2}`);
@@ -3,6 +3,7 @@ import { createRequire as __tobosRequire } from 'node:module';
3
3
  const require = __tobosRequire(import.meta.url);
4
4
  import {
5
5
  ID,
6
+ KEPT_MEDIA_DAYS,
6
7
  TEXT_MAX,
7
8
  activitiesOf,
8
9
  buildDeck,
@@ -11,6 +12,7 @@ import {
11
12
  formatProblems,
12
13
  isSafePath,
13
14
  masterOf,
15
+ mediaInUse,
14
16
  mediaTypeOf,
15
17
  memoryTree,
16
18
  openActivity,
@@ -20,10 +22,11 @@ import {
20
22
  servesModule,
21
23
  sha256,
22
24
  sharedManifest
23
- } from "./chunk-L3I6AVL4.js";
25
+ } from "./chunk-6VC3QOQM.js";
24
26
  import "./chunk-O52ON2LV.js";
25
27
  export {
26
28
  ID,
29
+ KEPT_MEDIA_DAYS,
27
30
  TEXT_MAX,
28
31
  activitiesOf,
29
32
  buildDeck,
@@ -32,6 +35,7 @@ export {
32
35
  formatProblems,
33
36
  isSafePath,
34
37
  masterOf,
38
+ mediaInUse,
35
39
  mediaTypeOf,
36
40
  memoryTree,
37
41
  openActivity,
@@ -3,7 +3,7 @@ import { createRequire as __tobosRequire } from 'node:module';
3
3
  const require = __tobosRequire(import.meta.url);
4
4
  import {
5
5
  parseDeckJson
6
- } from "./chunk-L3I6AVL4.js";
6
+ } from "./chunk-6VC3QOQM.js";
7
7
  import {
8
8
  CliError
9
9
  } from "./chunk-4CLH25WE.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tobos/cli",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
4
4
  "description": "The command line of Tobos: https://tobos.ai",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-ALv2",