@beff/aula-cli 0.4.3 → 0.5.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 (53) hide show
  1. package/dist/src/aula-render.core.wasm +0 -0
  2. package/dist/src/{chunk-7KT36JRP.js → chunk-2NMVSQG4.js} +83 -93
  3. package/dist/src/{chunk-46KT47TH.js → chunk-5VYKT646.js} +1 -1
  4. package/dist/src/chunk-A5QHTZKT.js +6 -0
  5. package/dist/src/{chunk-CIFP475T.js → chunk-DQ2NGXNI.js} +6 -321
  6. package/dist/src/chunk-EQ3DVZV5.js +15 -0
  7. package/dist/src/chunk-IKKANHTF.js +94 -0
  8. package/dist/src/chunk-JDXHKYLZ.js +369 -0
  9. package/dist/src/chunk-JVCECTG2.js +77 -0
  10. package/dist/src/{chunk-BT3Z5CJI.js → chunk-YBHISJLN.js} +70 -31
  11. package/dist/src/cli.js +12 -7
  12. package/dist/src/{commands-QCUCX2GF.js → commands-34YCDSR5.js} +8 -5
  13. package/dist/src/{problems-7BVC64RO.js → problems-U4QXN6RO.js} +4 -2
  14. package/dist/src/project-WS7P5VIH.js +12 -0
  15. package/dist/src/render-child.js +284 -9
  16. package/dist/src/{run-5WC5WRZ2.js → run-7PM6EPND.js} +45 -9
  17. package/dist/src/{server-GK3EWFX3.js → server-YQYW4FT4.js} +6 -5
  18. package/dist/src/site-SVNNSF72.js +139 -0
  19. package/dist/web/app/assets/__vite-browser-external-CJXyzDbj.js +1 -0
  20. package/dist/web/app/assets/aula-voice-worker-Ca14p_J5.js +52 -0
  21. package/dist/web/app/assets/{aula.core5-Bnq4-bLp.wasm → aula.core5-BsYwXoy8.wasm} +0 -0
  22. package/dist/web/app/assets/{ebd381c3 → b274e91c}/aula-method.js +1 -1
  23. package/dist/web/app/assets/b274e91c/aula.js +1 -0
  24. package/dist/web/app/assets/{ebd381c3 → b274e91c}/build-worker.js +2 -2
  25. package/dist/web/app/assets/b274e91c/index.js +52 -0
  26. package/dist/web/app/assets/{index-C_rGCAZR.css → index-BXxc0ZmT.css} +1 -1
  27. package/dist/web/app/assets/protocol-BejjzB3o.js +15 -0
  28. package/dist/web/app/assets/src-BA-sYAmS.js +25 -0
  29. package/dist/web/app/index.html +4 -4
  30. package/dist/web/site/assets/27f0d05e/aula-method.js +1 -0
  31. package/dist/web/site/assets/27f0d05e/aula.js +1 -0
  32. package/dist/web/site/assets/27f0d05e/build-worker.js +696 -0
  33. package/dist/web/site/assets/27f0d05e/index.js +52 -0
  34. package/dist/web/site/assets/__vite-browser-external-BtQTJ51O.js +1 -0
  35. package/dist/web/site/assets/__vite-browser-external-CHF7v6EZ.js +1 -0
  36. package/dist/web/site/assets/aula-voice-worker-CaLJBS98.js +54 -0
  37. package/dist/web/site/assets/aula.core-BtiPQSZi.wasm +0 -0
  38. package/dist/web/site/assets/aula.core5-BsYwXoy8.wasm +0 -0
  39. package/dist/web/site/assets/esbuild-BaXVPFT2.wasm +0 -0
  40. package/dist/web/site/assets/index-Dn5gqwRn.css +2 -0
  41. package/dist/web/site/assets/protocol-fozbK8HD.js +15 -0
  42. package/dist/web/site/assets/rolldown-runtime-BLXQ4ufn.js +1 -0
  43. package/dist/web/site/assets/src-BXUc4CQF.js +25 -0
  44. package/dist/web/site/index.html +39 -0
  45. package/package.json +2 -2
  46. package/dist/src/chunk-GFCJYE75.js +0 -42
  47. package/dist/src/project-NWT5MDQI.js +0 -11
  48. package/dist/web/app/assets/__vite-browser-external-BVodma7T.js +0 -1
  49. package/dist/web/app/assets/aula-voice-worker-D9iPLcHQ.js +0 -52
  50. package/dist/web/app/assets/ebd381c3/aula.js +0 -1
  51. package/dist/web/app/assets/ebd381c3/index.js +0 -52
  52. package/dist/web/app/assets/protocol-B46WpNW5.js +0 -15
  53. package/dist/web/app/assets/src-nkkXaLup.js +0 -25
Binary file
@@ -1,29 +1,3 @@
1
- // ../aula-project/src/diagnostics.ts
2
- import { diagnosticOf } from "@beff/aula/run";
3
- function error(message, more = {}) {
4
- return { severity: "error", message, ...more, stack: [], related: [] };
5
- }
6
- var isError = (d) => d.severity === "error";
7
- var Problems = class extends Error {
8
- diagnostics;
9
- constructor(diagnostics) {
10
- super(diagnostics.map((d) => d.message).join("\n"));
11
- this.diagnostics = diagnostics;
12
- }
13
- };
14
- function wrongArgument(message, hint) {
15
- return new Problems([error(message, hint === void 0 ? {} : { hint })]);
16
- }
17
- function diagnosticsOf(e, host2) {
18
- return e instanceof Problems ? e.diagnostics : [diagnosticOf(e, "", host2)];
19
- }
20
-
21
- // ../aula-project/src/node.ts
22
- import path from "node:path";
23
- import { pathToFileURL } from "node:url";
24
- import { isProjectDefinition } from "@beff/aula";
25
- import { definedAt, loadEngine, v8Frames } from "@beff/aula/run";
26
-
27
1
  // ../../node_modules/.pnpm/@beff+client@1.0.1/node_modules/@beff/client/dist/esm/openapi-pp.js
28
2
  var removeNullUnionBranch = (definition) => {
29
3
  if (typeof definition === "boolean") {
@@ -93,24 +67,24 @@ var joinWithDot = (it) => {
93
67
  }
94
68
  return acc;
95
69
  };
96
- var printPath = (parentPath, path2) => {
97
- const mergedPath = [...parentPath, ...path2];
70
+ var printPath = (parentPath, path) => {
71
+ const mergedPath = [...parentPath, ...path];
98
72
  return mergedPath.length > 0 ? `(${joinWithDot(mergedPath)})` : "";
99
73
  };
100
74
  var joinFilteredStrings = (it) => {
101
75
  return it.filter((it2) => it2.length > 0).join(" ");
102
76
  };
103
77
  var printRegularError = (err, parentPath, showReceived) => {
104
- const path2 = printPath(parentPath, err.path);
78
+ const path = printPath(parentPath, err.path);
105
79
  const msg = [err.message, showReceived ? `received: ${prettyPrintValue(err.received)}` : ""].filter((it) => it.length > 0).join(", ");
106
- return joinFilteredStrings([path2, msg]);
80
+ return joinFilteredStrings([path, msg]);
107
81
  };
108
82
  var printUnionError = (err, parentPath) => {
109
- const path2 = printPath(parentPath, err.path);
83
+ const path = printPath(parentPath, err.path);
110
84
  const printedErrors = printErrorsPart(err.errors, [], false);
111
85
  const innerMessages = printedErrors.length > 5 ? printedErrors.slice(0, 5).join(" OR ") + " and more..." : printedErrors.join(" | ");
112
86
  const msg = [`Failed to decode one of (${innerMessages})`, `received: ${prettyPrintValue(err.received)}`].filter((it) => it.length > 0).join(", ");
113
- return joinFilteredStrings([path2, msg]);
87
+ return joinFilteredStrings([path, msg]);
114
88
  };
115
89
  var printErrorsPart = (it, parentPath, showReceived) => {
116
90
  return it.map((err) => {
@@ -1039,9 +1013,9 @@ var Parsers = parser_default.buildParsers();
1039
1013
 
1040
1014
  // ../aula-bundle/src/index.ts
1041
1015
  var SOURCE_PREFIX = "tree:";
1042
- function dirname(path2) {
1043
- const at = path2.lastIndexOf("/");
1044
- return at < 0 ? "" : path2.slice(0, at);
1016
+ function dirname(path) {
1017
+ const at = path.lastIndexOf("/");
1018
+ return at < 0 ? "" : path.slice(0, at);
1045
1019
  }
1046
1020
  function join(from, relative) {
1047
1021
  const parts = from === "" ? [] : from.split("/");
@@ -1061,7 +1035,7 @@ var LOADERS = /* @__PURE__ */ new Map([
1061
1035
  ["mjs", "js"],
1062
1036
  ["json", "json"]
1063
1037
  ]);
1064
- var loaderOf = (path2) => LOADERS.get(path2.slice(path2.lastIndexOf(".") + 1)) ?? "ts";
1038
+ var loaderOf = (path) => LOADERS.get(path.slice(path.lastIndexOf(".") + 1)) ?? "ts";
1065
1039
  function treePlugin(tree, imports) {
1066
1040
  return {
1067
1041
  name: "aula-tree",
@@ -1077,12 +1051,12 @@ function treePlugin(tree, imports) {
1077
1051
  errors: [{ text: `cannot find the package "${args.path}" in node_modules or the workspace packages` }]
1078
1052
  };
1079
1053
  }
1080
- const path2 = join(dirname(args.importer), args.path);
1081
- if (path2 === null) return { errors: [{ text: `"${args.path}" is outside the folder you opened` }] };
1082
- for (const candidate of [path2, `${path2}.ts`, `${path2}/index.ts`]) {
1054
+ const path = join(dirname(args.importer), args.path);
1055
+ if (path === null) return { errors: [{ text: `"${args.path}" is outside the folder you opened` }] };
1056
+ for (const candidate of [path, `${path}.ts`, `${path}/index.ts`]) {
1083
1057
  if (await tree.read(candidate) !== null) return { path: candidate, namespace: "tree" };
1084
1058
  }
1085
- return { errors: [{ text: `cannot find "${args.path}" (${path2})` }] };
1059
+ return { errors: [{ text: `cannot find "${args.path}" (${path})` }] };
1086
1060
  });
1087
1061
  build.onLoad({ filter: /.*/, namespace: "tree" }, async (args) => {
1088
1062
  const contents = await tree.read(args.path);
@@ -1208,57 +1182,76 @@ async function resolvePackage(tree, specifier, importer) {
1208
1182
  }
1209
1183
  var ORDER = /^(\d+)-/;
1210
1184
  var projectName = (folder) => folder.replace(ORDER, "");
1211
-
1212
- // ../aula-project/src/node.ts
1213
- var PROJECT_MODULE = "index.ts";
1214
- var GLUE = [
1215
- `${path.dirname(new URL(import.meta.resolve("@beff/aula")).pathname)}/`,
1216
- new URL(import.meta.url).pathname
1217
- ];
1218
- function host(capabilities, root, glue = []) {
1219
- const all = [...GLUE, ...glue];
1220
- return {
1221
- frames: v8Frames,
1222
- name: (file) => file.startsWith("/") && !file.includes("/node_modules/") && !all.some((g) => file.startsWith(g)) ? path.relative(root, file) : void 0,
1223
- exists: (file) => capabilities.fs.existsSync(path.resolve(root, file))
1224
- };
1185
+ function sectionHeading(folder) {
1186
+ const words = projectName(folder).replaceAll("-", " ");
1187
+ return words.charAt(0).toUpperCase() + words.slice(1);
1225
1188
  }
1226
- function propertyOf(e, key) {
1227
- return typeof e === "object" && e !== null ? Reflect.get(e, key) : void 0;
1189
+ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
1190
+ function folderOrder(a, b) {
1191
+ const x = ORDER.exec(a)?.[1];
1192
+ const y = ORDER.exec(b)?.[1];
1193
+ if (x === void 0 || y === void 0) {
1194
+ if (x !== y) return x === void 0 ? 1 : -1;
1195
+ } else {
1196
+ const [m, n] = [x.replace(/^0+/, ""), y.replace(/^0+/, "")];
1197
+ const by = m.length - n.length || compare(m, n);
1198
+ if (by !== 0) return by;
1199
+ }
1200
+ return compare(projectName(a), projectName(b)) || compare(a, b);
1228
1201
  }
1229
- async function loadProject(capabilities, load, root, folder) {
1230
- const file = path.join(folder, PROJECT_MODULE);
1231
- if (!capabilities.fs.existsSync(file)) {
1232
- throw wrongArgument(
1233
- `${path.relative(root, folder) || "."} has no ${PROJECT_MODULE}`,
1234
- `give the project folder: the folder with ${PROJECT_MODULE}`
1235
- );
1202
+ async function subfolders(tree, folder) {
1203
+ const names = await tree.list(folder);
1204
+ return names.filter((name) => name !== "node_modules" && !name.startsWith(".")).toSorted(folderOrder);
1205
+ }
1206
+ var exists = async (tree, path) => await tree.read(path) !== null;
1207
+ async function projectModules(tree, root) {
1208
+ if (await exists(tree, "index.ts"))
1209
+ return { _tag: "Right", right: [{ module: "index.ts", name: projectName(root) }] };
1210
+ const found = [];
1211
+ for (const folder of await subfolders(tree, "")) {
1212
+ if (await exists(tree, `${folder}/index.ts`)) {
1213
+ found.push({ module: `${folder}/index.ts`, name: projectName(folder) });
1214
+ continue;
1215
+ }
1216
+ for (const inner of await subfolders(tree, folder)) {
1217
+ const module = `${folder}/${inner}/index.ts`;
1218
+ if (await exists(tree, module)) found.push({ module, name: projectName(inner), section: sectionHeading(folder) });
1219
+ }
1220
+ }
1221
+ const errors = [];
1222
+ found.forEach((project, i) => {
1223
+ const first = found.findIndex((other) => other.name === project.name);
1224
+ if (first === i) return;
1225
+ const folders = [found[first], project].map((p) => (p?.module ?? "").slice(0, -"/index.ts".length));
1226
+ errors.push({
1227
+ severity: "error",
1228
+ message: `two projects have the name ${project.name}: ${folders.join(" and ")}`,
1229
+ hint: "the name of a project is its folder name without the order prefix: rename one of the folders",
1230
+ stack: [],
1231
+ related: []
1232
+ });
1233
+ });
1234
+ return errors.length > 0 ? { _tag: "Left", left: errors } : { _tag: "Right", right: found };
1235
+ }
1236
+
1237
+ // ../aula-project/src/diagnostics.ts
1238
+ import { diagnosticOf } from "@beff/aula/run";
1239
+ function error(message, more = {}) {
1240
+ return { severity: "error", message, ...more, stack: [], related: [] };
1241
+ }
1242
+ var isError = (d) => d.severity === "error";
1243
+ var Problems = class extends Error {
1244
+ diagnostics;
1245
+ constructor(diagnostics) {
1246
+ super(diagnostics.map((d) => d.message).join("\n"));
1247
+ this.diagnostics = diagnostics;
1236
1248
  }
1237
- await loadEngine();
1238
- const module = await load(pathToFileURL(file).href);
1239
- const exported = propertyOf(module, "default");
1240
- if (!isProjectDefinition(exported)) {
1241
- const rel = path.relative(root, file);
1242
- throw new Problems([
1243
- error(`the default export of ${rel} is not made by defineProject`, {
1244
- location: { file: rel, line: 1, col: 0 },
1245
- hint: "write `export default defineProject({ title, theme, chapters: [ \u2026 ] })`"
1246
- })
1247
- ]);
1248
- }
1249
- return exported;
1249
+ };
1250
+ function wrongArgument(message, hint) {
1251
+ return new Problems([error(message, hint === void 0 ? {} : { hint })]);
1250
1252
  }
1251
- var folderOf = (project) => path.dirname(definedAt(project).file);
1252
- var nameOf = (project) => projectName(path.basename(folderOf(project)));
1253
- async function withSource(capabilities, root, d) {
1254
- if (d.source !== void 0 || d.location === void 0) return d;
1255
- const file = path.resolve(root, d.location.file);
1256
- if (!capabilities.fs.existsSync(file)) return d;
1257
- const text = await capabilities.fs.readFile(file, "utf8");
1258
- const lines = text.split("\n");
1259
- if (lines.at(-1) === "") lines.pop();
1260
- const line = lines[d.location.line - 1];
1261
- return line === void 0 || d.location.line < 1 ? d : { ...d, source: line.replace(/\r$/, "") };
1253
+ function diagnosticsOf(e, host) {
1254
+ return e instanceof Problems ? e.diagnostics : [diagnosticOf(e, "", host)];
1262
1255
  }
1263
1256
 
1264
1257
  export {
@@ -1269,14 +1262,11 @@ export {
1269
1262
  buildParsers,
1270
1263
  Parsers,
1271
1264
  bundle,
1265
+ projectName,
1266
+ projectModules,
1272
1267
  error,
1273
1268
  isError,
1274
1269
  Problems,
1275
1270
  wrongArgument,
1276
- diagnosticsOf,
1277
- host,
1278
- loadProject,
1279
- folderOf,
1280
- nameOf,
1281
- withSource
1271
+ diagnosticsOf
1282
1272
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  host,
3
3
  loadProject
4
- } from "./chunk-7KT36JRP.js";
4
+ } from "./chunk-JVCECTG2.js";
5
5
 
6
6
  // src/project.ts
7
7
  function exists(capabilities, file) {
@@ -0,0 +1,6 @@
1
+ // src/package.ts
2
+ var PACKAGE = new URL("../", import.meta.url);
3
+
4
+ export {
5
+ PACKAGE
6
+ };
@@ -1,56 +1,8 @@
1
1
  import {
2
- VIDEO,
3
- assemble,
4
- ffmpeg
5
- } from "./chunk-GFCJYE75.js";
6
- import {
7
- chapterIndexes,
8
- checkProject,
9
- clipPlan,
10
- clock,
11
- exportCheck,
12
- movesMarkdown,
13
- narrationAt,
14
- noteLine,
15
- notesLine,
16
- pictureGroups,
17
- pictureStills,
18
- previewJobs,
19
- previewTargets,
20
- printDiagnostics,
21
- scriptView,
22
- targetChapters,
23
- timelineView,
24
- wordNotes
25
- } from "./chunk-BT3Z5CJI.js";
26
- import {
27
- narrateScript,
28
- scriptAudio,
29
- wav
30
- } from "./chunk-S74JLCZK.js";
31
- import {
32
- host
33
- } from "./chunk-46KT47TH.js";
34
- import {
35
- ObjectRuntype,
36
- OptionalFieldRuntype,
37
2
  Parsers,
38
3
  Problems,
39
- RefRuntype,
40
- TypeofRuntype,
41
- buildParsers,
42
- bundle,
43
- folderOf,
44
- isError,
45
- nameOf,
46
- wrongArgument
47
- } from "./chunk-7KT36JRP.js";
48
-
49
- // src/commands.ts
50
- import path2 from "node:path";
51
- import { renderChapter } from "@beff/aula";
52
- import { chapterNames } from "@beff/aula/run";
53
- import { narrationScript } from "@beff/aula/text";
4
+ bundle
5
+ } from "./chunk-2NMVSQG4.js";
54
6
 
55
7
  // ../../node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/index.mjs
56
8
  import { createRequire } from "module";
@@ -813,53 +765,6 @@ function zipBytes(entries) {
813
765
  return zipSync(sorted, { mtime: "2000-01-01T12:00:00Z" });
814
766
  }
815
767
 
816
- // src/narrate.ts
817
- function narrate(capabilities, chapters) {
818
- return narrateScript(
819
- (words) => capabilities.narrator.speak(words),
820
- chapters,
821
- (spoken, count, cue) => {
822
- capabilities.log.out(`[${String(spoken)}/${String(count)}] Narrating: ${cue.text.slice(0, 70)}`);
823
- }
824
- );
825
- }
826
-
827
- // generated/parser.js
828
- var RequiredStringFormats = [];
829
- var RequiredNumberFormats = [];
830
- var namedRuntypes = {};
831
- var stringFormatters = {};
832
- var numberFormatters = {};
833
- var direct_hoist_0 = new RefRuntype(void 0, "TokensLine", namedRuntypes);
834
- var direct_hoist_1 = new TypeofRuntype(void 0, "string");
835
- var direct_hoist_2 = new ObjectRuntype({
836
- "description": "One input line of `aula tokens`: a text, and an optional id that the output line repeats."
837
- }, {
838
- "id": new OptionalFieldRuntype(direct_hoist_1),
839
- "text": direct_hoist_1
840
- }, []);
841
- Object.assign(namedRuntypes, {
842
- "TokensLine": direct_hoist_2
843
- });
844
- var buildParsersInput = {
845
- "TokensLine": direct_hoist_0
846
- };
847
- var parser_default = {
848
- buildParsers: (args) => buildParsers(
849
- {
850
- parsers: buildParsersInput,
851
- stringFormatters,
852
- numberFormatters,
853
- requiredStringFormats: RequiredStringFormats,
854
- requiredNumberFormats: RequiredNumberFormats
855
- },
856
- args
857
- )
858
- };
859
-
860
- // src/parsers.ts
861
- var Parsers2 = parser_default.buildParsers();
862
-
863
768
  // src/project-zip.ts
864
769
  import path from "node:path";
865
770
  function diskTree(capabilities, root) {
@@ -894,229 +799,9 @@ async function projectFiles(capabilities, esbuild, root, folder) {
894
799
  return files;
895
800
  }
896
801
 
897
- // src/commands.ts
898
- async function withHeavy(capabilities, f) {
899
- const release = await capabilities.locks.heavy();
900
- try {
901
- return await f();
902
- } finally {
903
- await release();
904
- }
905
- }
906
- async function withWork(capabilities, f) {
907
- const work = await capabilities.fs.mkdtemp(path2.join(capabilities.env.temp, "aula-"));
908
- try {
909
- return await f(work);
910
- } finally {
911
- await capabilities.fs.rm(work, { recursive: true, force: true });
912
- }
913
- }
914
- async function parallel(items, limit, task) {
915
- let next = 0;
916
- const worker = async () => {
917
- for (let item = items[next++]; item !== void 0; item = items[next++]) await task(item);
918
- };
919
- await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
920
- }
921
- async function drawChapter(capabilities, root, project, index, narration, lottie) {
922
- const built = renderChapter(project, index, { host: host(capabilities, root), narration });
923
- if (!built.ok || built.value === void 0) {
924
- return { ok: false, findings: built.diagnostics, frames: 0, waits: [], narration };
925
- }
926
- await capabilities.fs.writeFile(lottie, built.value.lottie, "utf8");
927
- const { frames, waits } = built.value;
928
- return { ok: true, findings: built.diagnostics, frames, waits, narration: built.value.narration };
929
- }
930
- var rowLine = (project, r) => `${nameOf(project)}: ${String(r.errors)} errors, ${String(r.warnings)} warnings, ${String(r.open)} open moves`;
931
- async function printChecked(capabilities, root, project, checked) {
932
- await printDiagnostics(capabilities, root, checked.findings);
933
- printCounts(capabilities, project, checked);
934
- }
935
- function printCounts(capabilities, project, checked) {
936
- const { errors, warnings } = checked.others;
937
- if (errors + warnings > 0)
938
- capabilities.log.out(`other chapters: ${String(errors)} errors, ${String(warnings)} warnings`);
939
- capabilities.log.out(rowLine(project, checked));
940
- }
941
- async function check(capabilities, root, project, only, json = false) {
942
- const chapters = chapterIndexes(project, only);
943
- const checked = checkProject(project, host(capabilities, root), chapters);
944
- const notes = wordNotes(narrationScript(project, checked.texts), chapters);
945
- if (json) {
946
- const { findings, others, errors, warnings, open } = checked;
947
- const result = { name: nameOf(project), errors, warnings, openMoves: open, others, findings, notes };
948
- capabilities.log.out(JSON.stringify(result, null, 2));
949
- return errors === 0;
950
- }
951
- await printDiagnostics(capabilities, root, checked.findings);
952
- for (const note of notes) capabilities.log.out(noteLine(note));
953
- if (notes.length > 0) capabilities.log.out(notesLine(notes));
954
- printCounts(capabilities, project, checked);
955
- return checked.errors === 0;
956
- }
957
- async function script(capabilities, root, project) {
958
- capabilities.log.write(scriptView(project, host(capabilities, root)));
959
- return true;
960
- }
961
- async function timeline(capabilities, root, project, only) {
962
- capabilities.log.write(await timelineView(project, host(capabilities, root), capabilities.narrator, only));
963
- return true;
964
- }
965
- async function preview(capabilities, root, project, folder, given) {
966
- const targets = previewTargets(project, given);
967
- const checked = checkProject(project, host(capabilities, root), targetChapters(targets, given));
968
- await printChecked(capabilities, root, project, checked);
969
- if (checked.errors > 0) return false;
970
- const all = checked.texts;
971
- const n = await clock(capabilities.narrator, narrationScript(project, all));
972
- const jobs = previewJobs(targets, all).map((job) => ({
973
- ...job,
974
- out: path2.join(folder, job.base),
975
- written: []
976
- }));
977
- return withWork(capabilities, async (work) => {
978
- for (const job of jobs) await capabilities.fs.rm(job.out, { recursive: true, force: true });
979
- const stopped = [];
980
- const waits = [];
981
- await withHeavy(
982
- capabilities,
983
- () => parallel(jobs, capabilities.env.parallelism, async (job) => {
984
- const lottie = path2.join(work, `${job.base}.json`);
985
- const drawn = await drawChapter(capabilities, root, project, job.index, narrationAt(n, job.index), lottie);
986
- if (!drawn.ok) {
987
- stopped.push(...drawn.findings);
988
- return;
989
- }
990
- waits.push(...drawn.findings.filter((d) => !isError(d)));
991
- const { out } = job;
992
- const { window, stills } = pictureStills(drawn.narration, job, drawn.frames);
993
- const sheets = await capabilities.render.pictures({ lottie, out, groups: pictureGroups(window, stills) });
994
- await capabilities.fs.mkdir(out, { recursive: true });
995
- await capabilities.fs.writeFile(path2.join(out, "moves.md"), movesMarkdown(stills));
996
- job.written.push(path2.join(out, "moves.md"), ...sheets);
997
- })
998
- );
999
- if (stopped.length) {
1000
- await printDiagnostics(capabilities, root, stopped);
1001
- return false;
1002
- }
1003
- await printDiagnostics(capabilities, root, waits);
1004
- for (const line of jobs.flatMap((job) => job.written)) capabilities.log.out(line);
1005
- return true;
1006
- });
1007
- }
1008
- async function exportVideo(capabilities, root, project, file) {
1009
- if (!file.endsWith(".mp4")) throw wrongArgument(`the video path must end in .mp4: ${file}`);
1010
- const names = chapterNames(project);
1011
- const checked = exportCheck(project, host(capabilities, root));
1012
- await printChecked(capabilities, root, project, checked);
1013
- if (checked.errors > 0) {
1014
- capabilities.log.out(`export ${nameOf(project)}: stopped at check: fix the errors above`);
1015
- return false;
1016
- }
1017
- await ffmpeg(capabilities, ["-version"]);
1018
- return withWork(capabilities, async (work) => {
1019
- const audio = path2.join(work, "narration.wav");
1020
- const cues = narrationScript(project, checked.texts);
1021
- const narrated = await withHeavy(capabilities, () => narrate(capabilities, cues));
1022
- const lotties = names.map((name) => path2.join(work, `${name}.json`));
1023
- const drawn = [];
1024
- const problems = [];
1025
- let done = 0;
1026
- await withHeavy(
1027
- capabilities,
1028
- () => parallel(
1029
- names.map((_, index) => index),
1030
- capabilities.env.parallelism,
1031
- async (index) => {
1032
- const narration = narrated[index]?.narration;
1033
- if (narration === void 0) throw new Error(`no narration of chapter ${String(index)}`);
1034
- const chapter = await drawChapter(capabilities, root, project, index, narration, lotties[index] ?? "");
1035
- drawn[index] = chapter;
1036
- if (!chapter.ok) problems.push(...chapter.findings);
1037
- done += 1;
1038
- capabilities.log.out(
1039
- `[${String(done)}/${String(names.length)}] ${names[index] ?? ""}: ${chapter.ok ? "drawn" : "FAILED"}`
1040
- );
1041
- }
1042
- )
1043
- );
1044
- if (problems.length) {
1045
- await printDiagnostics(capabilities, root, problems);
1046
- return false;
1047
- }
1048
- const { samples, sampleRate } = scriptAudio(
1049
- narrated,
1050
- drawn.map((d) => d.waits)
1051
- );
1052
- await capabilities.fs.writeFile(audio, wav(samples, sampleRate));
1053
- capabilities.log.out(`Narrated ${(samples.length / sampleRate / 60).toFixed(1)} minutes`);
1054
- const plan = clipPlan(
1055
- drawn.map((d) => d.narration),
1056
- VIDEO.fps
1057
- );
1058
- const clips = names.map((name) => path2.join(work, `${name}.mp4`));
1059
- await withHeavy(
1060
- capabilities,
1061
- () => parallel(
1062
- names.map((_, index) => index),
1063
- capabilities.env.parallelism,
1064
- async (index) => {
1065
- const clip = plan.clips[index] ?? { from: 0, frames: 0 };
1066
- await capabilities.render.clip({ lottie: lotties[index] ?? "", out: clips[index] ?? "", ...clip });
1067
- }
1068
- )
1069
- );
1070
- await capabilities.fs.mkdir(path2.dirname(file), { recursive: true });
1071
- await assemble(capabilities, { work, clips, audio, seconds: plan.seconds, out: file });
1072
- capabilities.log.out(file);
1073
- return true;
1074
- });
1075
- }
1076
- async function bundle2(capabilities, project, file) {
1077
- if (!file.endsWith(".zip")) throw new Error(`the zip path must end in .zip: ${file}`);
1078
- const home = folderOf(project);
1079
- const root = path2.parse(home).root;
1080
- const folder = path2.relative(root, home).split(path2.sep).join("/");
1081
- const esbuild = await import("esbuild-wasm");
1082
- let files;
1083
- try {
1084
- files = await projectFiles(capabilities, esbuild, root, folder);
1085
- } finally {
1086
- await esbuild.stop();
1087
- }
1088
- const entries = /* @__PURE__ */ new Map();
1089
- for (const [at, from] of files)
1090
- entries.set(at, new Uint8Array(await capabilities.fs.readFile(path2.join(root, from))));
1091
- const zip = zipBytes(entries);
1092
- await capabilities.fs.mkdir(path2.dirname(file), { recursive: true });
1093
- await capabilities.fs.writeFile(file, zip);
1094
- capabilities.log.out(`${file}: ${String(files.size)} files, ${String(Math.ceil(zip.length / 1024))} kB`);
1095
- return true;
1096
- }
1097
- async function tokens(capabilities, tokensOf, lines) {
1098
- let number = 0;
1099
- for await (const line of lines) {
1100
- number += 1;
1101
- if (!line.trim()) continue;
1102
- const parsed = Parsers2.TokensLine.safeParse(JSON.parse(line));
1103
- if (!parsed.success) throw wrongArgument(`stdin line ${String(number)}: expected {"id"?: string, "text": string}`);
1104
- const { id, text } = parsed.data;
1105
- capabilities.log.out(JSON.stringify({ ...id === void 0 ? {} : { id }, batches: await tokensOf(text) }));
1106
- }
1107
- return true;
1108
- }
1109
- function tokensArgs(positional) {
1110
- if (positional.length > 0) throw wrongArgument("aula tokens takes no arguments", "run `aula help` for the usage");
1111
- }
1112
-
1113
802
  export {
1114
- check,
1115
- script,
1116
- timeline,
1117
- preview,
1118
- exportVideo,
1119
- bundle2 as bundle,
1120
- tokens,
1121
- tokensArgs
803
+ packageFiles,
804
+ zipBytes,
805
+ diskTree,
806
+ projectFiles
1122
807
  };
@@ -0,0 +1,15 @@
1
+ import {
2
+ withSource
3
+ } from "./chunk-JVCECTG2.js";
4
+
5
+ // src/problems.ts
6
+ import { loadEngine } from "@beff/aula/run";
7
+ import { renderDiagnostic } from "@beff/aula/text";
8
+ async function printDiagnostics(capabilities, root, diagnostics, print = (text) => capabilities.log.out(text)) {
9
+ await loadEngine();
10
+ for (const d of diagnostics) print(renderDiagnostic(await withSource(capabilities, root, d)));
11
+ }
12
+
13
+ export {
14
+ printDiagnostics
15
+ };