Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

tools: a film name is required (usage + known films); an unknown name or a path exits clearly, no esbuild trace; verify-export takes the file itself

Alex Greenshpuncad447c9a2ab
diff --git a/skills/anidoodle/engine/tools/build-page.mjs b/skills/anidoodle/engine/tools/build-page.mjs
index cd772be..8c5189f 100644
--- a/skills/anidoodle/engine/tools/build-page.mjs
+++ b/skills/anidoodle/engine/tools/build-page.mjs
@@ -5,6 +5,7 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
import { createHash } from "node:crypto";
import { extname, join, relative, resolve } from "node:path";
import { overlay, resolveOverlay } from "./overlay.mjs";
+import { requireFilm } from "./names.mjs";
// BAKE KEYS (see Env.bake and hosts/page.ts). Every module that exports `const X: Film` is tagged
// in the bundle with its own path, and each tagged module gets a hash of its WHOLE import closure
@@ -43,6 +44,7 @@ const MIME = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png",
export const buildPage = async ({ entry, out, title, plugins: extra = [] }) => {
const plugins = [...extra, overlay]; // extra first: a caller's shim (snap --only) outranks the overlay
if (!existsSync(entry)) entry = resolveOverlay("./" + entry, process.cwd()) ?? entry; // e.g. the example's own host page
+ if (!existsSync(entry) && title) requireFilm(title, "build", "a film name: src/hosts/page-<film>.ts"); // a clear exit with the known films, not an esbuild trace
const main = await build({ entryPoints: [entry], bundle: true, format: "iife", target: "es2020", minify: true, write: false, legalComments: "none", metafile: true, plugins: [...plugins, tagFilms] });
const js = main.outputFiles[0].text;
// read the manifest out of the film module itself, so the page and the film can never disagree
@@ -58,4 +60,4 @@ export const buildPage = async ({ entry, out, title, plugins: extra = [] }) => {
mkdirSync(join(out, ".."), { recursive: true }); writeFileSync(out, html);
return { out, bytes: html.length, meta: film.meta, assets: Object.keys(film.assets.images) };
};
-if (import.meta.url === `file://${process.argv[1]}`) { const title = process.argv[2] ?? "fixtures"; const r = await buildPage({ entry: `src/hosts/page-${title}.ts`, out: `dist/${title}.html`, title }); console.log(`built ${r.out} (${(r.bytes / 1024).toFixed(0)} KB, self-contained)`); }
+if (import.meta.url === `file://${process.argv[1]}`) { const title = requireFilm(process.argv[2], "build-page", "node tools/build-page.mjs <film>"); const r = await buildPage({ entry: `src/hosts/page-${title}.ts`, out: `dist/${title}.html`, title }); console.log(`built ${r.out} (${(r.bytes / 1024).toFixed(0)} KB, self-contained)`); }
diff --git a/skills/anidoodle/engine/tools/emit.mjs b/skills/anidoodle/engine/tools/emit.mjs
index ec4dd10..b8aa7c6 100644
--- a/skills/anidoodle/engine/tools/emit.mjs
+++ b/skills/anidoodle/engine/tools/emit.mjs
@@ -20,13 +20,14 @@ import { readFileSync, statSync } from "node:fs";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { buildPage } from "./build-page.mjs";
+import { requireFilm } from "./names.mjs";
import { pageChecks, probe } from "./adapters/html-player.mjs";
const VAL = new Set(["out", "frames", "scale"]);
const pos = [], opt = {};
for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }
const die = (m) => { console.error(`emit: ${m}`); process.exit(1); };
-const film = pos[0] ?? die("usage: node tools/emit.mjs <film> [--out out/x.html] [--frames 24]");
+const film = requireFilm(pos[0], "emit", "node tools/emit.mjs <film> [--out out/x.html] [--frames 24]");
const kebab = film.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
const out = resolve(opt.out ?? `out/${kebab}.html`);
const N = Math.max(4, +(opt.frames ?? 24)), SCALE = +(opt.scale ?? 1);
diff --git a/skills/anidoodle/engine/tools/gate.mjs b/skills/anidoodle/engine/tools/gate.mjs
index 98902cf..fdc6b9a 100644
--- a/skills/anidoodle/engine/tools/gate.mjs
+++ b/skills/anidoodle/engine/tools/gate.mjs
@@ -15,13 +15,13 @@ import { createHash } from "node:crypto";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { readdirSync } from "node:fs";
-import { defaultOutput } from "./names.mjs";
+import { defaultOutput, requireFilm } from "./names.mjs";
import { changedArea } from "./motion.mjs";
const VAL = new Set(["adapter", "mp4", "samples", "scale", "workers"]);
const pos = [], opt = {};
for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }
-const film = pos[0] ?? "mechanicalLepidoptera";
+const film = opt["self-test"] ? null : requireFilm(pos[0], "gate", "node tools/gate.mjs <film> [--mp4 out/<film>.mp4] [--adapter html-player] [--samples 12] [--scale 1]\n node tools/gate.mjs --self-test");
const adapterName = opt.adapter ?? "html-player";
const SAMPLES = Math.max(4, +(opt.samples ?? 12)), SCALE = +(opt.scale ?? 1);
const TMP = resolve(".tmp/gate"); mkdirSync(TMP, { recursive: true });
diff --git a/skills/anidoodle/engine/tools/names.mjs b/skills/anidoodle/engine/tools/names.mjs
index c71f98f..2d3a5c7 100644
--- a/skills/anidoodle/engine/tools/names.mjs
+++ b/skills/anidoodle/engine/tools/names.mjs
@@ -1 +1,21 @@
+// Names shared by the tools: where a film's MP4 lands by default, and which films exist.
+import { existsSync, readdirSync } from "node:fs";
+import { join } from "node:path";
+import { ROOTS } from "./overlay.mjs";
+
export const defaultOutput = (film) => `out/${film}.mp4`;
+
+/** Every film this project can build: one host page, src/hosts/page-<film>.ts (the worked example's too). */
+export const knownFilms = () => [...new Set([join(process.cwd(), "src"), ...ROOTS].flatMap((r) => { const d = join(r, "hosts"); return existsSync(d) ? readdirSync(d).filter((f) => /^page-.+\.ts$/.test(f)).map((f) => f.slice(5, -3)) : []; }))].sort();
+const hostOf = (film) => [join(process.cwd(), "src"), ...ROOTS].map((r) => join(r, "hosts", `page-${film}.ts`)).find((f) => existsSync(f));
+
+/** The film named on the command line, or a clear exit: the usage when none is given, the known films when it is not one. */
+export const requireFilm = (film, tool, usage) => {
+ const list = () => { const k = knownFilms(); return `known films (${k.length}): ${k.join(", ")}`; };
+ if (!film || film.startsWith("--")) { console.error(`usage: ${usage}\n${list()}`); process.exit(2); }
+ if (!/^[A-Za-z_$][\w$]*$/.test(film) || !hostOf(film)) {
+ const path = /[\\/.]/.test(film) ? `: '${film}' looks like a file path; ${tool} takes a film name (the module src/canvas-core/<film>.ts with its host page src/hosts/page-<film>.ts)` : `: no host page src/hosts/page-${film}.ts`;
+ console.error(`${tool}: unknown film '${film}'${path}\n${list()}`); process.exit(2);
+ }
+ return film;
+};
diff --git a/skills/anidoodle/engine/tools/render.mjs b/skills/anidoodle/engine/tools/render.mjs
index fc6990f..cee62da 100644
--- a/skills/anidoodle/engine/tools/render.mjs
+++ b/skills/anidoodle/engine/tools/render.mjs
@@ -1,4 +1,4 @@
-// node tools/render.mjs [film] [--scale 1] [--workers 4] [--out out/x.mp4|.gif|.webm|.apng] [--gif-fps 15] [--width 640]
+// node tools/render.mjs <film> [--scale 1] [--workers 4] [--out out/x.mp4|.gif|.webm|.apng] [--gif-fps 15] [--width 640]
// [--blur N] [--from F] [--to F]
// --blur N motion blur (N an integer >= 1): every output frame is the average of N subframes over
// a one-frame shutter, integrated in linear light and weighted by alpha inside the page.
@@ -30,12 +30,12 @@ import { join, resolve } from "node:path";
import { buildPage } from "./build-page.mjs";
import { detect } from "./detect.mjs";
import * as playwright from "./adapters/playwright.mjs";
-import { defaultOutput } from "./names.mjs";
+import { defaultOutput, requireFilm } from "./names.mjs";
import { float32Wav } from "./audio.mjs";
import { firstFrameBlank } from "./thumb.mjs";
const arg = (k, d) => { const i = process.argv.indexOf(`--${k}`); return i > 0 ? process.argv[i + 1] : d; };
-const film = process.argv[2] && !process.argv[2].startsWith("--") ? process.argv[2] : "fixtures";
+const film = requireFilm(process.argv[2], "render", "node tools/render.mjs <film> [--scale 1] [--out out/x.mp4|.gif|.webm|.apng] [--from F] [--to F] [--poster-frame N] [--blur N]");
const BLUR = Number(arg("blur", 1));
if (!Number.isInteger(BLUR) || BLUR < 1) { console.error(`--blur wants a whole number of subframes >= 1, got '${arg("blur")}'`); process.exit(2); }
const scale = Number(arg("scale", 1)), fmt = (arg("out", "").match(/\.(gif|webm|apng)$/i)?.[1] ?? "mp4").toLowerCase(), workers = Number(arg("workers", Math.max(1, Math.min(4, Math.floor(cpus().length / 2)))));
diff --git a/skills/anidoodle/engine/tools/still.mjs b/skills/anidoodle/engine/tools/still.mjs
index 89df523..6b4e67a 100644
--- a/skills/anidoodle/engine/tools/still.mjs
+++ b/skills/anidoodle/engine/tools/still.mjs
@@ -15,6 +15,7 @@ import { spawnSync } from "node:child_process";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { buildPage } from "./build-page.mjs";
+import { requireFilm } from "./names.mjs";
import { detect } from "./detect.mjs";
import * as playwright from "./adapters/playwright.mjs";
@@ -22,7 +23,7 @@ const VAL = new Set(["shot", "out", "scale", "frame", "frames", "sheet", "sheet-
const pos = [], opt = {};
for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }
const die = (m) => { console.error(`still: ${m}`); process.exit(1); };
-const film = pos[0] ?? die("usage: node tools/still.mjs <film> [--shot <id>] [--frame N | --frames a,b,c] [--out out/x.png] [--scale 1] [--sheet out/sheet.jpg]");
+const film = requireFilm(pos[0], "still", "node tools/still.mjs <film> [--shot <id>] [--frame N | --frames a,b,c] [--out out/x.png] [--scale 1] [--sheet out/sheet.jpg]");
const scale = Number(opt.scale ?? 1);
if (!(scale > 0)) die(`--scale wants a number > 0, got '${opt.scale}'`);
if (opt.frame !== undefined && opt.frames !== undefined) die("give --frame N or --frames a,b,c, not both");
diff --git a/skills/anidoodle/engine/tools/verify-export.mjs b/skills/anidoodle/engine/tools/verify-export.mjs
index 8c46e2a..b9a77a4 100644
--- a/skills/anidoodle/engine/tools/verify-export.mjs
+++ b/skills/anidoodle/engine/tools/verify-export.mjs
@@ -5,6 +5,7 @@
// colour to assert, and a one-shot film has no seam to hide.
//
// node tools/verify-export.mjs <film> [--file out/x.mp4] [--adapter html-player]
+// node tools/verify-export.mjs out/<film>.mp4 [...] the file itself: the film is its name (out/<film>[.<from>-<to>].<ext>)
// [--width W] expected pixel width of a .gif/.webm/.apng made with render --width
// (default: the film's own; height follows the aspect). Not for .mp4:
// render always writes the MP4 at the film's size (x --scale), so
@@ -21,14 +22,21 @@
// as long as the picture, and not silent. Everything else is asked for explicitly.
import { execFileSync, spawnSync } from "node:child_process";
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
-import { resolve } from "node:path";
-import { defaultOutput } from "./names.mjs";
+import { basename, resolve } from "node:path";
+import { defaultOutput, requireFilm } from "./names.mjs";
import { firstFrameBlank } from "./thumb.mjs";
const VAL = new Set(["file", "adapter", "width", "first-frame", "tol", "fidelity-psnr", "scale", "frame"]);
const pos = [], opt = {};
for (let i = 2; i < process.argv.length; i++) { const a = process.argv[i]; if (a.startsWith("--")) opt[a.slice(2)] = VAL.has(a.slice(2)) ? process.argv[++i] : true; else pos.push(a); }
-const film = pos[0] ?? "fixtures";
+// a file path names its film: out/<film>.mp4 (or a range render's out/<film>.<from>-<to>.mp4)
+const USAGE = "node tools/verify-export.mjs <film> [--file out/<film>.mp4] [--first-frame #rrggbb] [--loop] [--fidelity-psnr N] [--frame N] [--delivery]\n node tools/verify-export.mjs out/<film>.mp4 [...]";
+if (pos[0] && /\.(mp4|gif|webm|apng|png)$/i.test(pos[0])) {
+ if (opt.file) { console.error(`verify-export: give the file once: '${pos[0]}' or --file ${opt.file}`); process.exit(2); }
+ if (!existsSync(pos[0])) { console.error(`verify-export: no file '${pos[0]}'`); process.exit(2); }
+ opt.file = pos[0]; pos[0] = basename(pos[0]).split(".")[0];
+}
+const film = requireFilm(pos[0], "verify-export", USAGE);
const adapterName = opt.adapter ?? "html-player";
const SCALE = +(opt.scale ?? 1);
const TMP = resolve(".tmp/verify"); mkdirSync(TMP, { recursive: true });
diff --git a/skills/anidoodle/engine/tools/verify-frame-adapter.mjs b/skills/anidoodle/engine/tools/verify-frame-adapter.mjs
index 7c9683d..2846e92 100644
--- a/skills/anidoodle/engine/tools/verify-frame-adapter.mjs
+++ b/skills/anidoodle/engine/tools/verify-frame-adapter.mjs
@@ -11,15 +11,16 @@
// If the engine is ever installed, this stays useful: it isolates a page-side fault from an
// engine-side one, which is the difference between an hour and a day.
//
-// node tools/verify-frame-adapter.mjs [film]
+// node tools/verify-frame-adapter.mjs <film>
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { buildPage } from "./build-page.mjs";
+import { requireFilm } from "./names.mjs";
import { FRAME_ADAPTER, ENGINE, INSTALL, probe } from "./adapters/hyperframes.mjs";
import { detect } from "./detect.mjs";
-const film = process.argv[2] ?? "mechanicalLepidoptera";
+const film = requireFilm(process.argv[2], "verify-frame-adapter", "node tools/verify-frame-adapter.mjs <film>");
const dir = resolve(".tmp/hyperframes", film); mkdirSync(dir, { recursive: true });
const out = join(dir, `${film}.html`);
const built = await buildPage({ entry: `src/hosts/page-${film}.ts`, out, title: film });