// `archilyzer reports prepare ` — cut and copy the evidence media of a // site's published reports into `.export-index/sites//report-media/`, // before the site's build. The work is publish/reportMedia.ts's, the same the // editor's `reports-prepare` job runs; this file prints its log and its // problems. // // When nothing is missing it then exports the reports as files // (publish/reportExports.ts, `archilyzer reports export`). // // Exit 0 when every cited moment has its media and every export was written; // 1 when any problem is listed (the manifest is written either way, problems // included); 2 for a site that does not exist. import { formatReportMediaProblems, prepareReportMedia } from "../publish/reportMedia"; import { exportAfterPrepare, formatReportExportProblems, type ExportSiteReportsOptions } from "../publish/reportExports"; type Out = { log: (s: string) => void; error: (s: string) => void }; export async function main( opts: { siteId: string; signal?: AbortSignal; // Passed to the export at the end (tests inject the PDF printer and zip). exportOptions?: Partial>; }, out: Out = console, ): Promise { let index; try { index = await prepareReportMedia({ siteId: opts.siteId, signal: opts.signal, onLog: out.log }); } catch (err) { out.error(`reports prepare: ${(err as Error).message}`); return opts.signal?.aborted ? 1 : 2; } if (index.problems.length > 0) { out.error(`reports prepare ${opts.siteId}: ${index.problems.length} problem(s):`); for (const line of formatReportMediaProblems(index.problems)) out.error(` ${line}`); out.error("reports prepare: the reports were not exported (the evidence media is not complete)."); return 1; } let exported; try { exported = await exportAfterPrepare(index, { siteId: opts.siteId, signal: opts.signal, onLog: out.log, ...opts.exportOptions }); } catch (err) { out.error(`reports prepare: export: ${(err as Error).message}`); return 1; } if (!exported || exported.problems.length === 0) return 0; out.error(`reports prepare ${opts.siteId}: export: ${exported.problems.length} problem(s):`); for (const line of formatReportExportProblems(exported.problems)) out.error(` ${line}`); return 1; }