// `umtool migrate` (release 39, the video-modules toolkit): a project's // manifest moved into the modules' homes -- the fact-check verdicts and tally // become the counter's named series (report-to-video modules/migrate.mjs) -- // through the one writer (manifest.mjs `migrateManifestFile`: the lock, the // token, an `auto-before-migrate` snapshot, refused on a problem the // renderer's validators would name). The cut renders as it did. // // umtool migrate [--dry-run] [--json] // // Plain ESM: the CLI runs under bare node. import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { manifestToken, migrateManifestFile } from "./manifest.mjs"; export const MIGRATE_USAGE = [ "usage: umtool migrate [--dry-run] [--json]", "", "Moves the manifest's settings into the video modules' homes (report-to-video/modules/migrate.mjs):", "the fact-check verdicts and tally become render.chrome.deck.counter's named series, a deck claim's", "tally names its series by id. The render is the same, frame for frame. --dry-run prints the moves", "and writes nothing; a manifest already migrated is left as it is.", ].join("\n"); /** * @param {string[]} args * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void }} [io] * @returns {Promise} */ export async function migrateCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s) } = {}) { const words = args.filter((a) => !a.startsWith("--")); const dryRun = args.includes("--dry-run"); const json = args.includes("--json"); if (!words[0] || args.includes("--help")) { err(MIGRATE_USAGE); return 2; } const r = await resolveProject(words[0], root); if (r.ambiguous) { err(`"${words[0]}" is the name of ${r.ambiguous.length} projects — pass its id`); return 1; } if (!r.project) { err(`no project matches "${words[0]}"`); return 1; } try { const token = await manifestToken(r.project.dir); const res = await migrateManifestFile(r.project.dir, { token, dryRun }); if (json) out(JSON.stringify({ project: r.project.id, dryRun, changes: res.changes, ...(res.token ? { token: res.token } : {}) })); else if (!res.changes.length) out(`${r.project.id}: nothing to migrate`); else { out(`${r.project.id}: ${dryRun ? "would migrate" : "migrated"}`); for (const c of res.changes) out(` ${c}`); } return 0; } catch (e) { const errors = /** @type {any} */ (e)?.errors; err(Array.isArray(errors) ? `refused:\n ${errors.join("\n ")}` : String(/** @type {any} */ (e)?.message ?? e)); return 1; } }