// A PROJECT's OWN CHARACTERS beside a manifest, read for the on-screen anonymising pass (post-anon.mjs) -- by the // build (build-video.mjs) and by the chrome composer (compose-chrome.mjs), which reads the manifest itself. // // Plain ESM. import { readFile } from "node:fs/promises"; import path from "node:path"; import { PROJECT_CHARACTERS_FILE, validateProjectCharacters } from "./cast.mjs"; /** * The project's own characters (cast.mjs PROJECT_CHARACTERS_FILE) beside a manifest, for the anonymising pass: null * with none. A file that does not parse or is refused STOPS the build -- read as none, an anonymous character would * be drawn under the name it must not show. */ export async function readProjectCharactersFor(manifestDir) { const file = path.join(manifestDir, ...PROJECT_CHARACTERS_FILE.split("/")); let text; try { text = await readFile(file, "utf8"); } catch (e) { if (e?.code === "ENOENT") return null; throw new Error(`${PROJECT_CHARACTERS_FILE} cannot be read (${e?.message ?? e}): an anonymous character could be drawn under its own name -- fix it first`); } let doc; try { doc = JSON.parse(text); } catch (e) { throw new Error(`${PROJECT_CHARACTERS_FILE} is not JSON (${e instanceof Error ? e.message : e}): an anonymous character could be drawn under its own name -- fix it first (umtool cast project
undo)`); } const errors = validateProjectCharacters(doc, PROJECT_CHARACTERS_FILE); if (errors.length) throw new Error(`${PROJECT_CHARACTERS_FILE} is refused (${errors.join("; ")}): an anonymous character could be drawn under its own name -- fix it first (umtool cast project
undo)`);
return doc;
}
/**
* THE PROJECT's ANONYMOUS SET (post-anon.mjs anonymousHandles), the ONE place the build, the chrome composer, the lint
* and the previews take it from: this video's characters beside `manifestDir`, over the WHOLE project manifest on disk
* (`video.manifest.json`: every variant, before rulings, windows or `--only`) and `whole` -- the manifest being drawn as
* its file holds it (a take's render manifest, a lint's scratch copy: its patch's entries count too). Throws when the
* characters cannot be read or the anonymity cannot be resolved.
*
* @param {string} manifestDir
* @param {any} [whole]
* @returns {Promise<{ doc: any, set: Map