@beff/aula-cli 0.13.0 → 0.13.1

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.
Files changed (61) hide show
  1. package/README.md +2 -2
  2. package/dist/src/aula-render.core.wasm +0 -0
  3. package/dist/src/{aula-voice-tts-H2OQFQ5J.js → aula-voice-tts-FEFKNA2I.js} +1 -1
  4. package/dist/src/aula.js +2 -2
  5. package/dist/src/{chunk-UBVMGS2E.js → chunk-2BEUK7M7.js} +1 -1
  6. package/dist/src/{chunk-G44UMBPW.js → chunk-2VD3JPLV.js} +3 -5
  7. package/dist/src/chunk-4N5SDSCV.js +63 -0
  8. package/dist/src/{chunk-THZNJBUF.js → chunk-F37DXY3P.js} +95 -100
  9. package/dist/src/{chunk-S6IM5XXK.js → chunk-FGTN34N7.js} +3 -3
  10. package/dist/src/{chunk-D5N3QDDF.js → chunk-GQSFMINU.js} +3 -33
  11. package/dist/src/{chunk-XIVHJMET.js → chunk-N3YZ7K5L.js} +3 -3
  12. package/dist/src/{chunk-F5RPEFZR.js → chunk-T7S65ZHW.js} +4306 -1645
  13. package/dist/src/{chunk-4FWDTPLR.js → chunk-V3GJ4XSW.js} +118 -66
  14. package/dist/src/{chunk-WV2UYZND.js → chunk-VJAXVLXZ.js} +1 -1
  15. package/dist/src/{chunk-UQOXT6QN.js → chunk-Z7VLJSDG.js} +132 -35
  16. package/dist/src/cli.js +27 -74
  17. package/dist/src/{commands-PLST75CP.js → commands-ZTGXXVOO.js} +10 -9
  18. package/dist/src/generated/aula.core5.wasm +0 -0
  19. package/dist/src/generated/aula.js +4076 -1341
  20. package/dist/src/generated/interfaces/aula-engine-engine.d.ts +39 -0
  21. package/dist/src/problems-BDPV4IRL.js +17 -0
  22. package/dist/src/project-XHL7FN7B.js +16 -0
  23. package/dist/src/{run-NE5HOAXA.js → run-LZVKYMKT.js} +14 -11
  24. package/dist/src/{server-KXIU66BB.js → server-H7XOUJNL.js} +8 -8
  25. package/dist/src/{site-HUWODSZ3.js → site-7MLO35NA.js} +6 -6
  26. package/dist/src/{workspace-load-DOHFEZFR.js → workspace-load-OQXB2ZOC.js} +6 -6
  27. package/dist/web/app/assets/{62289de9 → 15e78332}/aula-method.js +1 -1
  28. package/dist/web/app/assets/{62289de9 → 15e78332}/aula.js +1 -1
  29. package/dist/web/app/assets/{62289de9 → 15e78332}/build-worker.js +2 -2
  30. package/dist/web/app/assets/15e78332/index.js +51 -0
  31. package/dist/web/app/assets/__vite-browser-external-CCI-9X_7.js +1 -0
  32. package/dist/web/app/assets/aula-voice-worker-bYZ7BKji.js +1 -0
  33. package/dist/web/app/assets/{aula.core5-CQ2oHbtB.wasm → aula.core5-CtBp7wFf.wasm} +0 -0
  34. package/dist/web/app/assets/protocol-j759xoXL.js +15 -0
  35. package/dist/web/app/assets/src-BjcN7H3T.js +6 -0
  36. package/dist/web/{site/assets/tex-mathjax-DrZV_cwB.js → app/assets/tex-mathjax-Bbh2jsAv.js} +1 -1
  37. package/dist/web/app/index.html +4 -4
  38. package/dist/web/site/assets/{82618540 → 671a8ee2}/aula-method.js +1 -1
  39. package/dist/web/site/assets/{82618540 → 671a8ee2}/aula.js +1 -1
  40. package/dist/web/site/assets/{82618540 → 671a8ee2}/build-worker.js +2 -2
  41. package/dist/web/site/assets/671a8ee2/index.js +51 -0
  42. package/dist/web/site/assets/__vite-browser-external-CrZYh5ba.js +1 -0
  43. package/dist/web/site/assets/aula-voice-worker-Doyh20uI.js +1 -0
  44. package/dist/web/site/assets/{aula.core5-CQ2oHbtB.wasm → aula.core5-CtBp7wFf.wasm} +0 -0
  45. package/dist/web/site/assets/protocol-ByKVs3Yn.js +15 -0
  46. package/dist/web/site/assets/src-BwnY0kQu.js +6 -0
  47. package/dist/web/{app/assets/tex-mathjax-eWNptbJg.js → site/assets/tex-mathjax-DKtiwFu-.js} +1 -1
  48. package/dist/web/site/index.html +4 -4
  49. package/package.json +1 -1
  50. package/dist/src/problems-EI4DOEZ4.js +0 -17
  51. package/dist/src/project-7EROVEUE.js +0 -16
  52. package/dist/web/app/assets/62289de9/index.js +0 -51
  53. package/dist/web/app/assets/__vite-browser-external-BHESVS8k.js +0 -1
  54. package/dist/web/app/assets/aula-voice-worker-CJpoa9h-.js +0 -1
  55. package/dist/web/app/assets/protocol-kcdbhuRm.js +0 -15
  56. package/dist/web/app/assets/src-DWqZcp-P.js +0 -6
  57. package/dist/web/site/assets/82618540/index.js +0 -51
  58. package/dist/web/site/assets/__vite-browser-external-DQubyTsZ.js +0 -1
  59. package/dist/web/site/assets/aula-voice-worker-BRrzyFz3.js +0 -1
  60. package/dist/web/site/assets/protocol-XMWr-E-D.js +0 -15
  61. package/dist/web/site/assets/src-DfPcHwz-.js +0 -6
@@ -3,7 +3,46 @@ import {
3
3
  initG2p,
4
4
  lexiconEntries,
5
5
  loadEngine
6
- } from "./chunk-F5RPEFZR.js";
6
+ } from "./chunk-T7S65ZHW.js";
7
+
8
+ // ../aula-core/src/text.ts
9
+ function narrationScript(project, texts) {
10
+ const title = project.titleParts ?? [{ text: project.title }];
11
+ return engine.narrationScript([...title], lexiconEntries(project.lexicon ?? {}), [...texts]);
12
+ }
13
+ function chapterNarration(cues, spoken, sampleRate) {
14
+ return engine.chapterNarration([...cues], [...spoken], sampleRate);
15
+ }
16
+ function check(text) {
17
+ return engine.check(text);
18
+ }
19
+ function timeline(narration, text) {
20
+ return engine.timeline(narration, text);
21
+ }
22
+ function scriptBeats(narration, text) {
23
+ return engine.scriptBeats(narration, text);
24
+ }
25
+ function moveFrames(narration, text) {
26
+ return engine.moveFrames(narration, text);
27
+ }
28
+ function paragraphAt(text, line) {
29
+ return engine.paragraphAt(text, line);
30
+ }
31
+ function phonemize(text, lexicon = {}) {
32
+ return engine.phonemize(text, lexiconEntries(lexicon));
33
+ }
34
+ function phonemizeWithUnknowns(text, lexicon = {}) {
35
+ return engine.phonemizeWithUnknowns(text, lexiconEntries(lexicon));
36
+ }
37
+ function unclearWords(given) {
38
+ return engine.unclearWords([...given]);
39
+ }
40
+ function unclearWordsFrom(given, unknowns, alonePhonemes) {
41
+ return engine.unclearWordsFrom([...given], [...unknowns], [...alonePhonemes]);
42
+ }
43
+ function renderDiagnostic(d) {
44
+ return engine.renderDiagnostic(d);
45
+ }
7
46
 
8
47
  // ../aula-narration/src/align.ts
9
48
  function roundHalfEven(value) {
@@ -157,17 +196,17 @@ async function tokenBatches(vocab, phonemize2, text) {
157
196
  }
158
197
  var STRESS = "\u02C8\u02CC";
159
198
  var isSound = (phoneme) => new RegExp("\\p{L}", "u").test(phoneme) && !STRESS.includes(phoneme);
160
- async function timesOfWords(phonemize2, words2, timings) {
199
+ async function timesOfWords(phonemize2, words, timings) {
161
200
  const read = [];
162
- for (const word of words2) read.push(Array.from(await phonemize2(word)).filter(isSound));
201
+ for (const word of words) read.push(Array.from(await phonemize2(word)).filter(isSound));
163
202
  const spoken = timings.filter((timing) => isSound(timing.phoneme));
164
203
  if (!spoken.length) {
165
- const text = JSON.stringify(words2.join(" "));
204
+ const text = JSON.stringify(words.join(" "));
166
205
  throw new Error(
167
206
  read.some((w) => w.length > 0) ? `the narrator gave no phoneme timings for ${text}` : `Nothing to say: ${text} has no spoken sounds`
168
207
  );
169
208
  }
170
- return alignWords(words2, spoken, read);
209
+ return alignWords(words, spoken, read);
171
210
  }
172
211
 
173
212
  // ../aula-narration/src/vocab.ts
@@ -288,23 +327,25 @@ var KOKORO_VOCAB = /* @__PURE__ */ new Map([
288
327
  ["\u2198", 173],
289
328
  ["\u1D7B", 177]
290
329
  ]);
330
+ var KOKORO_SYMBOLS = Array.from(KOKORO_VOCAB.keys()).join("");
331
+ var KOKORO_PHONEMES = KOKORO_SYMBOLS.replaceAll("$", "");
291
332
 
292
333
  // ../aula-narration/src/aula-voice.ts
293
- var AULA_VOICE_RELEASE = "v0.2.4";
334
+ var AULA_VOICE_RELEASE = "v0.2.5";
294
335
  var RELEASE_URL = `https://github.com/lucasavila00/aula-voice/releases/download/${AULA_VOICE_RELEASE}`;
295
336
  var AULA_VOICE_FILES = {
296
337
  model: {
297
338
  path: "model.f16-text-fp32.safetensors",
298
339
  bytes: 21484448,
299
- sha256: "77029d5db79eca7dfbd353b67f255024cc077a578cb893cc92c41fd2ba83cf7f"
340
+ sha256: "35a016e19acf9b67d52aacd8d156f97690aba7ee9aeaf2b5ee55f58c38c3cdd5"
300
341
  },
301
342
  config: {
302
343
  path: "config.json",
303
- bytes: 2215,
304
- sha256: "1fe25ebd9f94c7ebc0f5f4f7c1320c26fc535350c8e366e339a3ce88c18b1c81"
344
+ bytes: 2214,
345
+ sha256: "3102a3d2769ed4ab7b9dce6654a921cc84d4532aae9fb8c03932c3a206819889"
305
346
  }
306
347
  };
307
- var AULA_VOICE_WEIGHTS_SHA256 = "cdf77eccfdc734e7a4ee74708e9be9fb3b9d14b0134ce84e5794c27ef1c76706";
348
+ var AULA_VOICE_WEIGHTS_SHA256 = "aec149e146b62fc3091f4310aeb596ee88c87c583258d35a023b8bbc5c42b0e1";
308
349
  var AULA_VOICE_WEIGHTS = {
309
350
  path: `aula-voice-${AULA_VOICE_WEIGHTS_SHA256.slice(0, 12)}.avw`,
310
351
  bytes: 21474688,
@@ -327,10 +368,19 @@ function limited(audio) {
327
368
  const scale = PEAK / loudest;
328
369
  return audio.map((sample) => sample * scale);
329
370
  }
330
- async function layout(parts, words2, audio) {
331
- const text = words2.join(" ");
371
+ function cuePhonemesOf(words) {
372
+ const spoken = words.join(" ");
373
+ const { phonemes, unknowns } = phonemizeWithUnknowns(spoken);
374
+ return { spoken, phonemes, unknowns, alonePhonemes: words.map((word) => phonemize(word)) };
375
+ }
376
+ function throwNoSpoken(kind, text) {
377
+ if (kind === "no-phonemes") throw new Error(`Nothing to say: ${JSON.stringify(text)} has no phonemes`);
378
+ throw new Error(`Nothing to say: ${JSON.stringify(text)} has no spoken sounds`);
379
+ }
380
+ async function layout(parts, words, audio, collectCue) {
381
+ const text = words.join(" ");
332
382
  const batches = await batchesOf(parts.phonemize, text, MAX_TOKENS);
333
- if (!batches.length) throw new Error(`Nothing to say: ${JSON.stringify(text)} has no phonemes`);
383
+ if (!batches.length) return { _tag: "Left", left: "no-phonemes" };
334
384
  const tokenized = batches.map((batch) => {
335
385
  const { ids, known } = tokenize(KOKORO_VOCAB, batch);
336
386
  if (!ids.length) {
@@ -341,7 +391,7 @@ async function layout(parts, words2, audio) {
341
391
  return { batch, ids, known };
342
392
  });
343
393
  if (!tokenized.some(({ known }) => known.some(isSound))) {
344
- throw new Error(`Nothing to say: ${JSON.stringify(text)} has no spoken sounds`);
394
+ return { _tag: "Left", left: "no-spoken" };
345
395
  }
346
396
  const pieces = [];
347
397
  const timings = [];
@@ -364,54 +414,43 @@ async function layout(parts, words2, audio) {
364
414
  pieces.push({ audio: spoken.audio?.subarray(head, tail) ?? null, length: tail - head, pause });
365
415
  offset += tail - head + pause;
366
416
  }
367
- return { pieces, total: offset, words: await timesOfWords(parts.phonemize, words2, timings) };
417
+ return {
418
+ _tag: "Right",
419
+ right: {
420
+ pieces,
421
+ total: offset,
422
+ words: await timesOfWords(parts.phonemize, words, timings),
423
+ ...collectCue ? { cue: cuePhonemesOf(words) } : {}
424
+ }
425
+ };
368
426
  }
369
427
  async function speakAulaVoice(parts, given) {
370
- const { pieces, total, words: words2 } = await layout(parts, given, true);
428
+ const text = given.join(" ");
429
+ const laid = await layout(parts, given, true, false);
430
+ if (laid._tag === "Left") throwNoSpoken(laid.left, text);
431
+ const { pieces, total, words } = laid.right;
371
432
  const samples = new Float32Array(total);
372
433
  let offset = 0;
373
434
  for (const piece of pieces) {
374
435
  if (piece.audio) samples.set(piece.audio, offset);
375
436
  offset += piece.length + piece.pause;
376
437
  }
377
- return { samples: limited(samples), sampleRate: SAMPLE_RATE, words: words2 };
438
+ return { samples: limited(samples), sampleRate: SAMPLE_RATE, words };
439
+ }
440
+ async function tryTimeAulaVoice(parts, given) {
441
+ const laid = await layout(parts, given, false, true);
442
+ if (laid._tag === "Left") return laid;
443
+ const { total, words, cue } = laid.right;
444
+ return {
445
+ _tag: "Right",
446
+ right: { samples: total, sampleRate: SAMPLE_RATE, words, ...cue === void 0 ? {} : { cue } }
447
+ };
378
448
  }
379
449
  async function timeAulaVoice(parts, given) {
380
- const { total, words: words2 } = await layout(parts, given, false);
381
- return { samples: total, sampleRate: SAMPLE_RATE, words: words2 };
382
- }
383
-
384
- // ../aula-core/src/text.ts
385
- function narrationScript(project, texts) {
386
- const title = project.titleParts ?? [{ text: project.title }];
387
- return engine.narrationScript([...title], lexiconEntries(project.lexicon ?? {}), [...texts]);
388
- }
389
- function chapterNarration(cues, spoken, sampleRate) {
390
- return engine.chapterNarration([...cues], [...spoken], sampleRate);
391
- }
392
- function check(text) {
393
- return engine.check(text);
394
- }
395
- function timeline(narration, text) {
396
- return engine.timeline(narration, text);
397
- }
398
- function moveFrames(narration, text) {
399
- return engine.moveFrames(narration, text);
400
- }
401
- function words(text) {
402
- return engine.words(text);
403
- }
404
- function paragraphAt(text, line) {
405
- return engine.paragraphAt(text, line);
406
- }
407
- function phonemize(text, lexicon = {}) {
408
- return engine.phonemize(text, lexiconEntries(lexicon));
409
- }
410
- function unclearWords(given) {
411
- return engine.unclearWords([...given]);
412
- }
413
- function renderDiagnostic(d) {
414
- return engine.renderDiagnostic(d);
450
+ const text = given.join(" ");
451
+ const timed = await tryTimeAulaVoice(parts, given);
452
+ if (timed._tag === "Left") throwNoSpoken(timed.left, text);
453
+ return timed.right;
415
454
  }
416
455
 
417
456
  // ../aula-narration/src/avw.ts
@@ -640,15 +679,37 @@ function studentWeightFile(model, config) {
640
679
  }
641
680
 
642
681
  // ../aula-narration/src/phonemize.ts
643
- function britishPhonemizer(vocab) {
682
+ function lexiconKey(lexicon) {
683
+ return JSON.stringify(Object.entries(lexicon));
684
+ }
685
+ function britishPhonemizer(vocab, lexicon = {}) {
686
+ const cache = /* @__PURE__ */ new Map();
687
+ const lex = lexiconKey(lexicon);
644
688
  return async (text) => {
645
- await loadEngine();
646
- await initG2p();
647
- return Array.from(phonemize(text)).filter((phoneme) => vocab.has(phoneme)).join("").trim();
689
+ const key = `${lex}\0${text}`;
690
+ const hit = cache.get(key);
691
+ if (hit) return hit;
692
+ const pending = (async () => {
693
+ await loadEngine();
694
+ await initG2p();
695
+ return Array.from(phonemize(text, lexicon)).filter((phoneme) => vocab.has(phoneme)).join("").trim();
696
+ })();
697
+ cache.set(key, pending);
698
+ return pending;
648
699
  };
649
700
  }
650
701
 
651
702
  export {
703
+ narrationScript,
704
+ chapterNarration,
705
+ check,
706
+ timeline,
707
+ scriptBeats,
708
+ moveFrames,
709
+ paragraphAt,
710
+ unclearWords,
711
+ unclearWordsFrom,
712
+ renderDiagnostic,
652
713
  tokenBatches,
653
714
  KOKORO_VOCAB,
654
715
  AULA_VOICE_RELEASE,
@@ -657,17 +718,8 @@ export {
657
718
  SERVER_WEIGHTS_PATH,
658
719
  aulaVoiceUrl,
659
720
  speakAulaVoice,
721
+ tryTimeAulaVoice,
660
722
  timeAulaVoice,
661
723
  studentWeightFile,
662
- narrationScript,
663
- chapterNarration,
664
- check,
665
- timeline,
666
- moveFrames,
667
- words,
668
- paragraphAt,
669
- phonemize,
670
- unclearWords,
671
- renderDiagnostic,
672
724
  britishPhonemizer
673
725
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  diagnosticOf
3
- } from "./chunk-F5RPEFZR.js";
3
+ } from "./chunk-T7S65ZHW.js";
4
4
 
5
5
  // ../../node_modules/.pnpm/@beff+client@1.0.1/node_modules/@beff/client/dist/esm/openapi-pp.js
6
6
  var removeNullUnionBranch = (definition) => {
@@ -2,20 +2,28 @@ import {
2
2
  createNodeBundler,
3
3
  nodeTree
4
4
  } from "./chunk-THQ5Y74K.js";
5
+ import {
6
+ Capabilities
7
+ } from "./chunk-4N5SDSCV.js";
5
8
  import {
6
9
  VIDEO,
7
10
  assemble,
8
11
  ffmpeg,
9
12
  hasAudio
10
13
  } from "./chunk-F4XRXW6M.js";
14
+ import {
15
+ run,
16
+ status
17
+ } from "./chunk-4N4NUMKP.js";
11
18
  import {
12
19
  printDiagnostics
13
- } from "./chunk-S6IM5XXK.js";
20
+ } from "./chunk-FGTN34N7.js";
14
21
  import {
15
22
  chapterIndexes,
16
23
  checkProject,
17
24
  clipPlan,
18
25
  clock,
26
+ clockWithUnclear,
19
27
  draftSkipMessage,
20
28
  exportCheck,
21
29
  movesMarkdown,
@@ -35,18 +43,18 @@ import {
35
43
  timelineView,
36
44
  wav,
37
45
  wordNotes
38
- } from "./chunk-THZNJBUF.js";
46
+ } from "./chunk-F37DXY3P.js";
39
47
  import {
40
48
  narrationScript
41
- } from "./chunk-4FWDTPLR.js";
49
+ } from "./chunk-V3GJ4XSW.js";
42
50
  import {
43
51
  host,
44
52
  loadProject
45
- } from "./chunk-UBVMGS2E.js";
53
+ } from "./chunk-2BEUK7M7.js";
46
54
  import {
47
55
  folderOf,
48
56
  nameOf
49
- } from "./chunk-G44UMBPW.js";
57
+ } from "./chunk-2VD3JPLV.js";
50
58
  import {
51
59
  NO_PROJECT_MESSAGE,
52
60
  ObjectRuntype,
@@ -61,17 +69,18 @@ import {
61
69
  isError,
62
70
  projectModules,
63
71
  wrongArgument
64
- } from "./chunk-WV2UYZND.js";
72
+ } from "./chunk-VJAXVLXZ.js";
65
73
  import {
66
74
  manim_exports
67
- } from "./chunk-D5N3QDDF.js";
75
+ } from "./chunk-GQSFMINU.js";
68
76
  import {
69
77
  chapterNames,
70
78
  renderChapter
71
- } from "./chunk-F5RPEFZR.js";
79
+ } from "./chunk-T7S65ZHW.js";
72
80
 
73
81
  // src/commands.ts
74
82
  import path2 from "node:path";
83
+ import { fileURLToPath } from "node:url";
75
84
 
76
85
  // ../../node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/index.mjs
77
86
  import { createRequire } from "module";
@@ -915,6 +924,11 @@ async function projectFiles(capabilities, bundler, root, folder) {
915
924
  }
916
925
 
917
926
  // src/commands.ts
927
+ var CHECK_CLI = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "cli.ts" : "cli.js", import.meta.url));
928
+ function outputLines(text) {
929
+ if (text === "") return [];
930
+ return text.replace(/\n$/, "").split("\n");
931
+ }
918
932
  async function withWork(capabilities, f) {
919
933
  const work = await capabilities.fs.mkdtemp(path2.join(capabilities.env.temp, "aula-"));
920
934
  try {
@@ -975,11 +989,11 @@ function printCounts(capabilities, project, checked) {
975
989
  capabilities.log.out(`other chapters: ${String(errors)} errors, ${String(warnings)} warnings`);
976
990
  capabilities.log.out(rowLine(project, checked));
977
991
  }
978
- async function timeChapters(capabilities, root, project, texts, only) {
992
+ async function timeChapters(capabilities, root, project, cues, only) {
979
993
  const names = chapterNames(project);
980
994
  const indexes = (only ?? names.map((_, i2) => i2)).filter((i2) => i2 > 0);
981
- if (indexes.length === 0) return [];
982
- const n = await clock(capabilities.narrator, narrationScript(project, texts), only, names);
995
+ if (indexes.length === 0) return { warnings: [], unclear: cues.map((chapter) => chapter.map(() => [])) };
996
+ const { narrations: n, unclear } = await clockWithUnclear(capabilities.narrator, cues, only, names);
983
997
  const h = host(capabilities, root);
984
998
  const warnings = [];
985
999
  for (const index of indexes) {
@@ -990,15 +1004,16 @@ async function timeChapters(capabilities, root, project, texts, only) {
990
1004
  });
991
1005
  warnings.push(...drawn.diagnostics.filter((d) => !isError(d)));
992
1006
  }
993
- return warnings;
1007
+ return { warnings, unclear };
994
1008
  }
995
1009
  async function check(capabilities, root, project, only, json = false) {
996
1010
  const chapters = chapterIndexes(project, only);
997
1011
  const checked = checkProject(project, host(capabilities, root), chapters);
998
- const timing = checked.errors === 0 ? await timeChapters(capabilities, root, project, checked.texts, chapters) : [];
999
- const findings = [...checked.findings, ...timing];
1000
- const warnings = checked.warnings + timing.length;
1001
- const notes = wordNotes(narrationScript(project, checked.texts), chapters);
1012
+ const cues = narrationScript(project, checked.texts);
1013
+ const timed = checked.errors === 0 ? await timeChapters(capabilities, root, project, cues, chapters) : { warnings: [], unclear: null };
1014
+ const findings = [...checked.findings, ...timed.warnings];
1015
+ const warnings = checked.warnings + timed.warnings.length;
1016
+ const notes = wordNotes(cues, chapters, timed.unclear);
1002
1017
  if (json) {
1003
1018
  const { others, errors, open } = checked;
1004
1019
  const result = { name: nameOf(project), errors, warnings, openMoves: open, others, findings, notes };
@@ -1011,7 +1026,51 @@ async function check(capabilities, root, project, only, json = false) {
1011
1026
  printCounts(capabilities, project, { ...checked, findings, warnings });
1012
1027
  return checked.errors === 0;
1013
1028
  }
1014
- async function checkRoot(capabilities, cwd, folder, only, json = false, includeDrafts = false) {
1029
+ function checkElapsed(ms) {
1030
+ const seconds = Math.max(0, ms) / 1e3;
1031
+ if (seconds < 60) return `${seconds.toFixed(1)}s`;
1032
+ const minutes = Math.floor(seconds / 60);
1033
+ const rest = Math.round(seconds - minutes * 60);
1034
+ return `${minutes}m ${rest}s`;
1035
+ }
1036
+ function checkProgressLine(index, total, label) {
1037
+ return `checking ${String(index)}/${String(total)} ${label}`;
1038
+ }
1039
+ function checkSummaryLine(passed, failed, skipped, ms) {
1040
+ return `${String(passed)} passed, ${String(failed)} failed, ${String(skipped)} skipped, ${checkElapsed(ms)}`;
1041
+ }
1042
+ async function checkCaptured(capabilities, cwd, project, only, json) {
1043
+ const lines = [];
1044
+ const nested = Capabilities.extend(
1045
+ capabilities,
1046
+ Capabilities.create({
1047
+ log: {
1048
+ out: (line) => void lines.push(line),
1049
+ write: (text) => void lines.push(text),
1050
+ err: () => void 0
1051
+ }
1052
+ })
1053
+ );
1054
+ return { ok: await check(nested, cwd, project, only, json), lines, skipped: false };
1055
+ }
1056
+ async function checkInChild(capabilities, node, cwd, entry, json) {
1057
+ const args = [CHECK_CLI, "check", entry.projectFolder];
1058
+ if (json) args.push("--json");
1059
+ if (entry.project.draft) args.push("--include-drafts");
1060
+ const ran = await run(capabilities, node, args, { cwd });
1061
+ for (const line of outputLines(ran.stderr)) capabilities.log.err(line);
1062
+ const lines = outputLines(ran.stdout);
1063
+ if (ran.code !== 0 && lines.length === 0) {
1064
+ const detail = outputLines(ran.stderr);
1065
+ return {
1066
+ ok: false,
1067
+ lines: detail.length > 0 ? detail : [`error: check of ${entry.label} failed (${status(ran)})`],
1068
+ skipped: false
1069
+ };
1070
+ }
1071
+ return { ok: ran.code === 0, lines, skipped: false };
1072
+ }
1073
+ async function checkRoot(capabilities, cwd, folder, only, json = false, includeDrafts = false, node) {
1015
1074
  const tree = nodeTree(capabilities, folder);
1016
1075
  const listed = await projectModules(tree, path2.basename(folder));
1017
1076
  if (listed._tag === "Left") throw new Problems(listed.left);
@@ -1025,27 +1084,65 @@ async function checkRoot(capabilities, cwd, folder, only, json = false, includeD
1025
1084
  }
1026
1085
  const projects = [];
1027
1086
  for (const entry of loaded) {
1028
- if (entry.project.draft && !includeDrafts) {
1029
- capabilities.log.out(draftSkipMessage(entry.label));
1030
- } else {
1031
- projects.push(entry);
1032
- }
1033
- }
1034
- if (projects.length === 0) return true;
1035
- if (projects.length !== 1 && only.length > 0) {
1036
- throw wrongArgument(
1037
- "aula check takes chapters only when the folder gives one project",
1038
- "pass a project folder, or omit the chapters to check every listed project"
1039
- );
1087
+ if (!(entry.project.draft && !includeDrafts)) projects.push(entry);
1040
1088
  }
1041
- if (listed.right.length !== 1 && projects.length === 1 && only.length > 0) {
1042
- const entry = projects[0];
1043
- if (entry === void 0) throw new Error("checkRoot: missing project after draft filter");
1044
- entry.project = await loadProject(capabilities, cwd, entry.projectFolder, only);
1089
+ if (projects.length > 0) {
1090
+ if (projects.length !== 1 && only.length > 0) {
1091
+ throw wrongArgument(
1092
+ "aula check takes chapters only when the folder gives one project",
1093
+ "pass a project folder, or omit the chapters to check every listed project"
1094
+ );
1095
+ }
1096
+ if (listed.right.length !== 1 && projects.length === 1 && only.length > 0) {
1097
+ const entry = projects[0];
1098
+ if (entry === void 0) throw new Error("checkRoot: missing project after draft filter");
1099
+ entry.project = await loadProject(capabilities, cwd, entry.projectFolder, only);
1100
+ }
1045
1101
  }
1102
+ const progress = loaded.length > 1;
1103
+ const started = capabilities.clock.now();
1104
+ const slots = Array.from({ length: loaded.length });
1105
+ let nextPrint = 0;
1106
+ let passed = 0;
1107
+ let failed = 0;
1108
+ let skipped = 0;
1046
1109
  let ok = true;
1047
- for (const entry of projects) {
1048
- ok = await check(capabilities, cwd, entry.project, only, json) && ok;
1110
+ const flush = () => {
1111
+ while (nextPrint < loaded.length) {
1112
+ const slot = slots[nextPrint];
1113
+ if (slot === void 0) break;
1114
+ for (const line of slot.lines) capabilities.log.out(line);
1115
+ if (slot.skipped) skipped += 1;
1116
+ else if (slot.ok) passed += 1;
1117
+ else {
1118
+ failed += 1;
1119
+ ok = false;
1120
+ }
1121
+ nextPrint += 1;
1122
+ }
1123
+ };
1124
+ const jobs = loaded.map((entry, index) => ({ entry, index }));
1125
+ const limit = progress ? Math.max(1, capabilities.env.parallelism) : 1;
1126
+ const useChildren = progress && node !== void 0 && limit > 1;
1127
+ await parallel(jobs, limit, async ({ entry, index }) => {
1128
+ if (progress) capabilities.log.err(checkProgressLine(index + 1, loaded.length, entry.label));
1129
+ if (entry.project.draft && !includeDrafts) {
1130
+ slots[index] = { ok: true, lines: [draftSkipMessage(entry.label)], skipped: true };
1131
+ flush();
1132
+ return;
1133
+ }
1134
+ let slot;
1135
+ if (useChildren) {
1136
+ if (node === void 0) throw new Error("checkRoot: child checks need the node path");
1137
+ slot = await checkInChild(capabilities, node, cwd, entry, json);
1138
+ } else {
1139
+ slot = await checkCaptured(capabilities, cwd, entry.project, only, json);
1140
+ }
1141
+ slots[index] = slot;
1142
+ flush();
1143
+ });
1144
+ if (progress) {
1145
+ capabilities.log.err(checkSummaryLine(passed, failed, skipped, capabilities.clock.now() - started));
1049
1146
  }
1050
1147
  return ok;
1051
1148
  }