@bangerpage/cli 0.1.1 → 0.2.0-rc.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.
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,20 +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 stops = await withCapture(file, { onWarning: (message) => warnings.push(message) }, async (session) => {
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 = "";
802
+ const onWarning = (message) => {
803
+ if (message === pinned) {
804
+ if (oldRuntime) warnings.push(oldRuntime);
805
+ else process.stderr.write(`note: ${message}
806
+ `);
807
+ } else warnings.push(`${tag}${message}`);
808
+ };
809
+ let firstSteps = [];
810
+ let firstLanguage = "";
811
+ const stops = await forEachLanguage(file, "all", { onWarning }, async (session, run) => {
812
+ tag = run.tag;
739
813
  for (const ref of expandStates(session.path, "last")) {
740
814
  const report = await session.goto(ref);
741
- 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
+ });
742
827
  }
743
828
  return session.path.length;
744
829
  });
745
- 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] };
746
831
  }
747
832
  async function runCheck(argv) {
748
833
  if (argv.includes("--help")) {
@@ -774,41 +859,41 @@ async function runCheck(argv) {
774
859
  import { mkdir, writeFile } from "node:fs/promises";
775
860
  import { basename as basename2, dirname as dirname4, extname as extname2, resolve as resolve2 } from "node:path";
776
861
  import { PDFDocument } from "@cantoo/pdf-lib";
777
- async function exportPdf(file, opts = {}) {
778
- const out = resolve2(opts.out ?? resolve2(dirname4(file), `${basename2(file, extname2(file))}.pdf`));
779
- const failures = /* @__PURE__ */ new Map();
780
- const pages = [];
781
- const title = await withCapture(
782
- file,
783
- { launchers: opts.launchers, onWarning: opts.onWarning },
784
- async (session) => {
785
- for (const ref of expandStates(session.path, opts.steps ?? "last")) {
786
- const report = await session.goto(ref);
787
- for (const failure of report.failed) failures.set(formatReadyFailure(failure), failure);
788
- pages.push(
789
- await session.page.pdf({ width: "1920px", height: "1080px", printBackground: true, pageRanges: "1" })
790
- );
791
- }
792
- 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" }));
793
875
  }
794
- );
795
- if (failures.size > 0) {
796
- throw new CliError(1, `export failed; nothing was written
797
- ${[...failures.keys()].join("\n")}`);
798
- }
799
- const merged = await PDFDocument.create();
800
- for (const page of pages) {
801
- const doc = await PDFDocument.load(page);
802
- for (const copied of await merged.copyPages(doc, doc.getPageIndices())) merged.addPage(copied);
803
- }
804
- merged.setTitle(title);
805
- await mkdir(dirname4(out), { recursive: true });
806
- await writeFile(out, await merged.save());
807
- 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;
808
893
  }
809
894
 
810
895
  // src/commands/export.ts
811
- 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]";
812
897
  async function runExport(argv) {
813
898
  if (argv.includes("--help")) {
814
899
  process.stdout.write(`${USAGE2}
@@ -818,7 +903,8 @@ async function runExport(argv) {
818
903
  const { values, positionals } = parseArgsStrict(argv, {
819
904
  pdf: { type: "boolean" },
820
905
  out: { type: "string" },
821
- steps: { type: "string" }
906
+ steps: { type: "string" },
907
+ lang: { type: "string" }
822
908
  });
823
909
  const file = deckFile(positionals, USAGE2);
824
910
  if (!values.pdf) throw new CliError(2, `choose exactly one export format
@@ -826,9 +912,25 @@ ${USAGE2}`);
826
912
  if (values.steps !== void 0 && values.steps !== "last" && values.steps !== "all") {
827
913
  throw new CliError(2, `invalid --steps: ${values.steps} (expected last or all)`);
828
914
  }
829
- const out = await exportPdf(file, { out: values.out, steps: values.steps });
830
- 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}
831
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
+ }
832
934
  return 0;
833
935
  }
834
936
 
@@ -1104,14 +1206,26 @@ function runSkill(argv) {
1104
1206
  const dest = values.dir !== void 0 ? resolve5(values.dir) : values.project ? resolve5(".claude", "skills", "banger") : join7(homedir2(), ".claude", "skills", "banger");
1105
1207
  const outcome = installSkill({ source: bundledSkill(), dest, version: cliVersion(), force: values.force });
1106
1208
  process.stdout.write(`${outcome}: ${dest}
1107
- `);
1209
+
1210
+ ${NEXT_STEPS}`);
1108
1211
  return 0;
1109
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
+ `;
1110
1224
 
1111
1225
  // src/commands/snap.ts
1112
1226
  import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
1113
1227
  import { dirname as dirname5, join as join8 } from "node:path";
1114
- 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]";
1115
1229
  function parseCount(name, value) {
1116
1230
  if (!/^\d+$/.test(value)) throw new CliError(2, `invalid --${name}: ${value}`);
1117
1231
  return Number(value);
@@ -1128,7 +1242,8 @@ async function runSnap(argv) {
1128
1242
  steps: { type: "string" },
1129
1243
  out: { type: "string" },
1130
1244
  "out-dir": { type: "string" },
1131
- scale: { type: "string" }
1245
+ scale: { type: "string" },
1246
+ lang: { type: "string" }
1132
1247
  });
1133
1248
  const file = deckFile(positionals, USAGE7);
1134
1249
  if (values.scale !== void 0 && values.scale !== "1" && values.scale !== "2") {
@@ -1145,8 +1260,9 @@ async function runSnap(argv) {
1145
1260
  const stop = values.stop === void 0 ? void 0 : parseCount("stop", values.stop);
1146
1261
  const stepArg = values.step === void 0 || values.step === "last" ? "last" : parseCount("step", values.step);
1147
1262
  const outDir = values["out-dir"] ?? "snap";
1263
+ checkLangOption(values.lang, values.out);
1148
1264
  const failures = /* @__PURE__ */ new Set();
1149
- await withCapture(file, { scale }, async (session) => {
1265
+ await forEachLanguage(file, values.lang, { scale }, async (session, run) => {
1150
1266
  let only;
1151
1267
  if (stop !== void 0) {
1152
1268
  const info = session.path[stop];
@@ -1157,12 +1273,13 @@ async function runSnap(argv) {
1157
1273
  }
1158
1274
  const states = expandStates(session.path, selection, only);
1159
1275
  const single = only !== void 0;
1160
- if (!single) await clearStopFiles(outDir);
1276
+ const dir = run.tag !== "" ? join8(outDir, run.language) : outDir;
1277
+ if (!single) await clearStopFiles(dir);
1161
1278
  for (const ref of states) {
1162
1279
  const report = await session.goto(ref);
1163
- for (const failure of report.failed) failures.add(formatReadyFailure(failure));
1280
+ for (const failure of report.failed) failures.add(`${run.tag}${formatReadyFailure(failure)}`);
1164
1281
  const png = await captureState(session, ref);
1165
- 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));
1166
1283
  await mkdir2(dirname5(target), { recursive: true });
1167
1284
  await writeFile2(target, png);
1168
1285
  }
@@ -1259,13 +1376,13 @@ function updateCacheFile(env = process.env) {
1259
1376
  function enabled(env, isTTY) {
1260
1377
  return isTTY && !env.CI && !env.BANGER_NO_UPDATE_CHECK && !env.NO_UPDATE_NOTIFIER;
1261
1378
  }
1262
- function parse2(version2) {
1379
+ function parse3(version2) {
1263
1380
  const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version2);
1264
1381
  return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : void 0;
1265
1382
  }
1266
1383
  function isNewer(latest, current) {
1267
- const a = parse2(latest);
1268
- const b = parse2(current);
1384
+ const a = parse3(latest);
1385
+ const b = parse3(current);
1269
1386
  if (!a || !b) return false;
1270
1387
  for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i];
1271
1388
  return false;
@@ -1311,10 +1428,10 @@ commands:
1311
1428
  init [dir] [--force] start a deck: write index.html from the starter
1312
1429
  preview [file] [--port N] preview with live reload
1313
1430
  snap [file] [--stop N] [--step M|last] [--steps last|all] [--out path] [--out-dir dir] [--scale 1|2]
1314
- render states as 1920x1080 PNGs
1431
+ [--lang <language>|all] render states as 1920x1080 PNGs
1315
1432
  check [file] [--json] render every stop and list the problems the runtime finds;
1316
1433
  exits 1 when there is any
1317
- export [file] --pdf [--out path] [--steps last|all]
1434
+ export [file] --pdf [--out path] [--steps last|all] [--lang <language>|all]
1318
1435
  write a PDF, one page per stop
1319
1436
  theme init [file] [--from <preset>] [--force]
1320
1437
  write a theme.json from a bundled preset
@@ -1332,6 +1449,8 @@ commands:
1332
1449
  later runs update the same deck
1333
1450
 
1334
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.
1335
1454
 
1336
1455
  In a terminal, banger checks npm for a newer release once a day and prints a notice.
1337
1456
  Set BANGER_NO_UPDATE_CHECK=1 to turn it off; it is also off when CI is set.