@bangerpage/cli 0.1.2 → 0.2.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/args.d.ts CHANGED
@@ -6,3 +6,5 @@ export declare function parseArgsStrict<const T extends NonNullable<ParseArgsCon
6
6
  };
7
7
  /** The deck file from the positionals; with none, `index.html` in the working directory. */
8
8
  export declare function deckFile(positionals: string[], usage: string): string;
9
+ /** Rejects a `--lang` that is empty or `all` together with a single `--out` file (exit 2). */
10
+ export declare function checkLangOption(lang: string | undefined, out: string | undefined): void;
package/dist/bin.js CHANGED
@@ -61,6 +61,10 @@ function deckFile(positionals, usage) {
61
61
  if (positionals.length > 1) throw new CliError(2, usage);
62
62
  return positionals[0] ?? "index.html";
63
63
  }
64
+ function checkLangOption(lang, out) {
65
+ if (lang === "") throw new CliError(2, "--lang needs a language or all");
66
+ if (lang === "all" && out !== void 0) throw new CliError(2, "--lang all cannot be used with --out");
67
+ }
64
68
 
65
69
  // src/platform/browser-login.ts
66
70
  import { spawn } from "node:child_process";
@@ -337,6 +341,9 @@ async function runLogout(argv, deps = {}) {
337
341
  return 0;
338
342
  }
339
343
 
344
+ // src/commands/check.ts
345
+ import { parse as parse2 } from "parse5";
346
+
340
347
  // src/capture.ts
341
348
  import { readdir, rm } from "node:fs/promises";
342
349
  import { join as join4 } from "node:path";
@@ -643,6 +650,9 @@ async function clearStopFiles(dir) {
643
650
  }
644
651
  return removed;
645
652
  }
653
+ function pageQuery(lang) {
654
+ return lang === void 0 ? "mode=export" : `mode=export&lang=${encodeURIComponent(lang)}`;
655
+ }
646
656
  var defaultOnWarning = (message) => {
647
657
  process.stderr.write(`warning: ${message}
648
658
  `);
@@ -678,7 +688,7 @@ async function withCapture(file, opts, fn) {
678
688
  page.on("response", (response) => {
679
689
  if (response.status() >= 400) failedRequests.push(`${response.url()} (${response.status()})`);
680
690
  });
681
- await page.goto(server.urlFor("mode=export#stop=0&step=last"), { waitUntil: "commit" });
691
+ await page.goto(server.urlFor(`${pageQuery(opts.lang)}#stop=0&step=last`), { waitUntil: "commit" });
682
692
  const timeoutMs = opts.runtimeTimeoutMs ?? RUNTIME_LOAD_TIMEOUT_MS;
683
693
  const loaded = await page.evaluate(
684
694
  (ms) => Promise.race([
@@ -704,10 +714,16 @@ async function withCapture(file, opts, fn) {
704
714
  const path = await page.evaluate(
705
715
  () => document.querySelector("bang-root").getPath()
706
716
  );
717
+ const { languages, language } = await page.evaluate(() => {
718
+ const root = document.querySelector("bang-root");
719
+ return { languages: root.getLanguages?.() ?? [], language: root.getLanguage?.() ?? "" };
720
+ });
707
721
  const session = {
708
722
  page,
709
723
  path,
710
724
  title: await page.title(),
725
+ languages,
726
+ language,
711
727
  async goto(ref) {
712
728
  const report = await page.evaluate(async ({ stop, step }) => {
713
729
  const root = document.querySelector("bang-root");
@@ -729,26 +745,89 @@ async function withCapture(file, opts, fn) {
729
745
  function formatReadyFailure(failure) {
730
746
  return `ready failed: ${failure.tag} ${failure.selector}: ${failure.reason}`;
731
747
  }
748
+ function assertLanguage(session, lang) {
749
+ if (session.languages.length === 0) throw new CliError(2, "this deck has no languages; remove --lang");
750
+ if (session.language.toLowerCase() !== lang.toLowerCase()) {
751
+ throw new CliError(2, `--lang ${lang} is not one of the deck's languages (${session.languages.join(", ")})`);
752
+ }
753
+ }
754
+ async function forEachLanguage(file, lang, opts, fn) {
755
+ const all = lang === "all";
756
+ const results = [];
757
+ const languages = await withCapture(file, { ...opts, lang: all ? void 0 : lang }, async (session) => {
758
+ if (lang !== void 0 && !all) assertLanguage(session, lang);
759
+ const run = { language: session.language, tag: all && session.languages.length > 0 ? `[${session.language}] ` : "", index: 0 };
760
+ results.push(await fn(session, run));
761
+ return session.languages;
762
+ });
763
+ if (all) {
764
+ for (let index = 1; index < languages.length; index++) {
765
+ await withCapture(file, { ...opts, lang: languages[index], runtimeVersionCheck: false }, async (session) => {
766
+ results.push(await fn(session, { language: session.language, tag: `[${session.language}] `, index }));
767
+ });
768
+ }
769
+ }
770
+ return results;
771
+ }
732
772
 
733
773
  // src/commands/check.ts
734
774
  var USAGE = "usage: banger check [file] [--json]";
775
+ function hasLanguages(html) {
776
+ const visit = (node) => {
777
+ for (const child of node.childNodes) {
778
+ if (!("tagName" in child)) continue;
779
+ const element = child;
780
+ if (element.tagName === "bang-root") {
781
+ return (element.attrs.find((a) => a.name === "languages")?.value ?? "").trim() !== "";
782
+ }
783
+ if (visit(element)) return true;
784
+ }
785
+ return false;
786
+ };
787
+ return visit(parse2(html));
788
+ }
789
+ function oldRuntimeWarning(html) {
790
+ const version2 = findRuntimeScript(html, CORE_PACKAGE)?.version;
791
+ const match = version2 ? /^(\d+)\.(\d+)\.(\d+)/.exec(version2) : null;
792
+ if (!match || Number(match[1]) !== 0 || Number(match[2]) >= 2) return null;
793
+ return `the deck pins ${CORE_PACKAGE}@${version2} but uses languages; that runtime shows every language at once, so pin ${CORE_PACKAGE}@0.2.0 or later`;
794
+ }
735
795
  async function checkDeck(file) {
736
796
  const warnings = [];
737
797
  const failed = /* @__PURE__ */ new Set();
738
- const pinned = runtimeVersionWarning(readInput(file), CORE_PACKAGE, coreVersion())?.message;
798
+ const html = readInput(file);
799
+ const pinned = runtimeVersionWarning(html, CORE_PACKAGE, coreVersion())?.message;
800
+ const oldRuntime = pinned !== void 0 && hasLanguages(html) ? oldRuntimeWarning(html) : null;
801
+ let tag = "";
739
802
  const onWarning = (message) => {
740
- if (message === pinned) process.stderr.write(`note: ${message}
803
+ if (message === pinned) {
804
+ if (oldRuntime) warnings.push(oldRuntime);
805
+ else process.stderr.write(`note: ${message}
741
806
  `);
742
- else warnings.push(message);
807
+ } else warnings.push(`${tag}${message}`);
743
808
  };
744
- const stops = await withCapture(file, { onWarning }, async (session) => {
809
+ let firstSteps = [];
810
+ let firstLanguage = "";
811
+ const stops = await forEachLanguage(file, "all", { onWarning }, async (session, run) => {
812
+ tag = run.tag;
745
813
  for (const ref of expandStates(session.path, "last")) {
746
814
  const report = await session.goto(ref);
747
- for (const failure of report.failed) failed.add(formatReadyFailure(failure));
815
+ for (const failure of report.failed) failed.add(`${run.tag}${formatReadyFailure(failure)}`);
816
+ }
817
+ const steps = session.path.map((stop) => stop.steps);
818
+ if (run.index === 0) {
819
+ firstSteps = steps;
820
+ firstLanguage = run.language;
821
+ } else {
822
+ steps.forEach((n, index) => {
823
+ if (n !== firstSteps[index]) {
824
+ warnings.push(`${run.tag}stop ${index} has ${n} steps (${firstLanguage}: ${firstSteps[index]})`);
825
+ }
826
+ });
748
827
  }
749
828
  return session.path.length;
750
829
  });
751
- return { ok: warnings.length === 0 && failed.size === 0, stops, warnings, failed: [...failed] };
830
+ return { ok: warnings.length === 0 && failed.size === 0, stops: stops[0], warnings, failed: [...failed] };
752
831
  }
753
832
  async function runCheck(argv) {
754
833
  if (argv.includes("--help")) {
@@ -780,41 +859,41 @@ async function runCheck(argv) {
780
859
  import { mkdir, writeFile } from "node:fs/promises";
781
860
  import { basename as basename2, dirname as dirname4, extname as extname2, resolve as resolve2 } from "node:path";
782
861
  import { PDFDocument } from "@cantoo/pdf-lib";
783
- async function exportPdf(file, opts = {}) {
784
- const out = resolve2(opts.out ?? resolve2(dirname4(file), `${basename2(file, extname2(file))}.pdf`));
785
- const failures = /* @__PURE__ */ new Map();
786
- const pages = [];
787
- const title = await withCapture(
788
- file,
789
- { launchers: opts.launchers, onWarning: opts.onWarning },
790
- async (session) => {
791
- for (const ref of expandStates(session.path, opts.steps ?? "last")) {
792
- const report = await session.goto(ref);
793
- for (const failure of report.failed) failures.set(formatReadyFailure(failure), failure);
794
- pages.push(
795
- await session.page.pdf({ width: "1920px", height: "1080px", printBackground: true, pageRanges: "1" })
796
- );
797
- }
798
- return session.title;
862
+ function defaultPdfPath(file, language) {
863
+ const base = basename2(file, extname2(file));
864
+ return resolve2(dirname4(file), language ? `${base}.${language}.pdf` : `${base}.pdf`);
865
+ }
866
+ async function exportPdfs(file, opts = {}) {
867
+ const outcomes = [];
868
+ await forEachLanguage(file, opts.lang, { launchers: opts.launchers, onWarning: opts.onWarning }, async (session, run) => {
869
+ const failures = /* @__PURE__ */ new Map();
870
+ const pages = [];
871
+ for (const ref of expandStates(session.path, opts.steps ?? "last")) {
872
+ const report = await session.goto(ref);
873
+ for (const failure of report.failed) failures.set(formatReadyFailure(failure), failure);
874
+ pages.push(await session.page.pdf({ width: "1920px", height: "1080px", printBackground: true, pageRanges: "1" }));
799
875
  }
800
- );
801
- if (failures.size > 0) {
802
- throw new CliError(1, `export failed; nothing was written
803
- ${[...failures.keys()].join("\n")}`);
804
- }
805
- const merged = await PDFDocument.create();
806
- for (const page of pages) {
807
- const doc = await PDFDocument.load(page);
808
- for (const copied of await merged.copyPages(doc, doc.getPageIndices())) merged.addPage(copied);
809
- }
810
- merged.setTitle(title);
811
- await mkdir(dirname4(out), { recursive: true });
812
- await writeFile(out, await merged.save());
813
- return out;
876
+ if (failures.size > 0) {
877
+ outcomes.push({ language: run.language, failures: [...failures.keys()] });
878
+ return;
879
+ }
880
+ const merged = await PDFDocument.create();
881
+ for (const page of pages) {
882
+ const doc = await PDFDocument.load(page);
883
+ for (const copied of await merged.copyPages(doc, doc.getPageIndices())) merged.addPage(copied);
884
+ }
885
+ merged.setTitle(session.title);
886
+ if (run.language !== "") merged.setLanguage(run.language);
887
+ const out = opts.out ? resolve2(opts.out) : defaultPdfPath(file, opts.lang !== void 0 && run.language !== "" ? run.language : void 0);
888
+ await mkdir(dirname4(out), { recursive: true });
889
+ await writeFile(out, await merged.save());
890
+ outcomes.push({ language: run.language, path: out, failures: [] });
891
+ });
892
+ return outcomes;
814
893
  }
815
894
 
816
895
  // src/commands/export.ts
817
- var USAGE2 = "usage: banger export [file] --pdf [--out path] [--steps last|all]";
896
+ var USAGE2 = "usage: banger export [file] --pdf [--out path] [--steps last|all] [--lang <language>|all]";
818
897
  async function runExport(argv) {
819
898
  if (argv.includes("--help")) {
820
899
  process.stdout.write(`${USAGE2}
@@ -824,7 +903,8 @@ async function runExport(argv) {
824
903
  const { values, positionals } = parseArgsStrict(argv, {
825
904
  pdf: { type: "boolean" },
826
905
  out: { type: "string" },
827
- steps: { type: "string" }
906
+ steps: { type: "string" },
907
+ lang: { type: "string" }
828
908
  });
829
909
  const file = deckFile(positionals, USAGE2);
830
910
  if (!values.pdf) throw new CliError(2, `choose exactly one export format
@@ -832,9 +912,25 @@ ${USAGE2}`);
832
912
  if (values.steps !== void 0 && values.steps !== "last" && values.steps !== "all") {
833
913
  throw new CliError(2, `invalid --steps: ${values.steps} (expected last or all)`);
834
914
  }
835
- const out = await exportPdf(file, { out: values.out, steps: values.steps });
836
- process.stdout.write(`${out}
915
+ checkLangOption(values.lang, values.out);
916
+ const outcomes = await exportPdfs(file, {
917
+ lang: values.lang,
918
+ out: values.out,
919
+ steps: values.steps
920
+ });
921
+ for (const outcome of outcomes) if (outcome.path) process.stdout.write(`${outcome.path}
837
922
  `);
923
+ const failed = outcomes.filter((outcome) => outcome.failures.length > 0);
924
+ if (failed.length > 0) {
925
+ throw new CliError(
926
+ 1,
927
+ failed.map(({ language, failures }) => {
928
+ const named = language !== "";
929
+ const head = named ? `export failed for ${language}; nothing was written for it` : "export failed; nothing was written";
930
+ return [head, ...failures.map((f) => named ? `[${language}] ${f}` : f)].join("\n");
931
+ }).join("\n")
932
+ );
933
+ }
838
934
  return 0;
839
935
  }
840
936
 
@@ -1110,14 +1206,26 @@ function runSkill(argv) {
1110
1206
  const dest = values.dir !== void 0 ? resolve5(values.dir) : values.project ? resolve5(".claude", "skills", "banger") : join7(homedir2(), ".claude", "skills", "banger");
1111
1207
  const outcome = installSkill({ source: bundledSkill(), dest, version: cliVersion(), force: values.force });
1112
1208
  process.stdout.write(`${outcome}: ${dest}
1113
- `);
1209
+
1210
+ ${NEXT_STEPS}`);
1114
1211
  return 0;
1115
1212
  }
1213
+ var NEXT_STEPS = `With the skill, your AI agent can:
1214
+ - plan the flow of stops with you and write the talk as one HTML file
1215
+ - show it on your machine, find problems and fix them
1216
+ - export it to PDF and pick a theme
1217
+
1218
+ Start by asking, for example:
1219
+ "Make a 10-minute talk about <topic> with Banger. Let's agree on the flow of stops first."
1220
+
1221
+ To see the talk, run \`banger preview\` in the talk's folder.
1222
+ More: https://banger.page/start
1223
+ `;
1116
1224
 
1117
1225
  // src/commands/snap.ts
1118
1226
  import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
1119
1227
  import { dirname as dirname5, join as join8 } from "node:path";
1120
- var USAGE7 = "usage: banger snap [file] [--stop N] [--step M|last] [--steps last|all] [--out path] [--out-dir dir] [--scale 1|2]";
1228
+ var USAGE7 = "usage: banger snap [file] [--stop N] [--step M|last] [--steps last|all] [--out path] [--out-dir dir] [--scale 1|2] [--lang <language>|all]";
1121
1229
  function parseCount(name, value) {
1122
1230
  if (!/^\d+$/.test(value)) throw new CliError(2, `invalid --${name}: ${value}`);
1123
1231
  return Number(value);
@@ -1134,7 +1242,8 @@ async function runSnap(argv) {
1134
1242
  steps: { type: "string" },
1135
1243
  out: { type: "string" },
1136
1244
  "out-dir": { type: "string" },
1137
- scale: { type: "string" }
1245
+ scale: { type: "string" },
1246
+ lang: { type: "string" }
1138
1247
  });
1139
1248
  const file = deckFile(positionals, USAGE7);
1140
1249
  if (values.scale !== void 0 && values.scale !== "1" && values.scale !== "2") {
@@ -1151,8 +1260,9 @@ async function runSnap(argv) {
1151
1260
  const stop = values.stop === void 0 ? void 0 : parseCount("stop", values.stop);
1152
1261
  const stepArg = values.step === void 0 || values.step === "last" ? "last" : parseCount("step", values.step);
1153
1262
  const outDir = values["out-dir"] ?? "snap";
1263
+ checkLangOption(values.lang, values.out);
1154
1264
  const failures = /* @__PURE__ */ new Set();
1155
- await withCapture(file, { scale }, async (session) => {
1265
+ await forEachLanguage(file, values.lang, { scale }, async (session, run) => {
1156
1266
  let only;
1157
1267
  if (stop !== void 0) {
1158
1268
  const info = session.path[stop];
@@ -1163,12 +1273,13 @@ async function runSnap(argv) {
1163
1273
  }
1164
1274
  const states = expandStates(session.path, selection, only);
1165
1275
  const single = only !== void 0;
1166
- if (!single) await clearStopFiles(outDir);
1276
+ const dir = run.tag !== "" ? join8(outDir, run.language) : outDir;
1277
+ if (!single) await clearStopFiles(dir);
1167
1278
  for (const ref of states) {
1168
1279
  const report = await session.goto(ref);
1169
- for (const failure of report.failed) failures.add(formatReadyFailure(failure));
1280
+ for (const failure of report.failed) failures.add(`${run.tag}${formatReadyFailure(failure)}`);
1170
1281
  const png = await captureState(session, ref);
1171
- const target = single && values.out || join8(outDir, stopFileName(ref.stop, ref.step));
1282
+ const target = single && values.out || join8(dir, stopFileName(ref.stop, ref.step));
1172
1283
  await mkdir2(dirname5(target), { recursive: true });
1173
1284
  await writeFile2(target, png);
1174
1285
  }
@@ -1265,13 +1376,13 @@ function updateCacheFile(env = process.env) {
1265
1376
  function enabled(env, isTTY) {
1266
1377
  return isTTY && !env.CI && !env.BANGER_NO_UPDATE_CHECK && !env.NO_UPDATE_NOTIFIER;
1267
1378
  }
1268
- function parse2(version2) {
1379
+ function parse3(version2) {
1269
1380
  const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version2);
1270
1381
  return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : void 0;
1271
1382
  }
1272
1383
  function isNewer(latest, current) {
1273
- const a = parse2(latest);
1274
- const b = parse2(current);
1384
+ const a = parse3(latest);
1385
+ const b = parse3(current);
1275
1386
  if (!a || !b) return false;
1276
1387
  for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i];
1277
1388
  return false;
@@ -1317,10 +1428,10 @@ commands:
1317
1428
  init [dir] [--force] start a deck: write index.html from the starter
1318
1429
  preview [file] [--port N] preview with live reload
1319
1430
  snap [file] [--stop N] [--step M|last] [--steps last|all] [--out path] [--out-dir dir] [--scale 1|2]
1320
- render states as 1920x1080 PNGs
1431
+ [--lang <language>|all] render states as 1920x1080 PNGs
1321
1432
  check [file] [--json] render every stop and list the problems the runtime finds;
1322
1433
  exits 1 when there is any
1323
- export [file] --pdf [--out path] [--steps last|all]
1434
+ export [file] --pdf [--out path] [--steps last|all] [--lang <language>|all]
1324
1435
  write a PDF, one page per stop
1325
1436
  theme init [file] [--from <preset>] [--force]
1326
1437
  write a theme.json from a bundled preset
@@ -1338,6 +1449,8 @@ commands:
1338
1449
  later runs update the same deck
1339
1450
 
1340
1451
  [file] defaults to index.html in the working directory.
1452
+ --lang picks one of the deck's languages (default: the first); all writes every language
1453
+ (snap/<language>/, deck.<language>.pdf). check always covers every language.
1341
1454
 
1342
1455
  In a terminal, banger checks npm for a newer release once a day and prints a notice.
1343
1456
  Set BANGER_NO_UPDATE_CHECK=1 to turn it off; it is also off when CI is set.