// --------------------------------------------------------------------------- // What Create (/create, plans/umtool-redesign.md P5) scaffolds, by KIND -- here // because a kind id is a literal only lib/projects/ and components/projects/ // may write (e2e/projects.spec.ts enforces it). The page asks for "the kind a // video from a recording is" and never learns its name. // // video-recording a report video whose `from` is / or a share URL // video-report a report video whose `from` is a sweep report (.md) on disk // song a song // // And the sweep reports on disk the "from a sweep report" form offers: every // project of the sweep-report kind (a cited report, not yet a video), with // its report's path and title. // --------------------------------------------------------------------------- import { readdir, readFile } from "node:fs/promises"; import path from "node:path"; import { kindById } from "./kinds.mjs"; const REPORT_VIDEO = "report-video"; const SONG = "song"; const SWEEP = "sweep-report"; /** The kind each scaffolding make writes. */ export const MAKE_KIND = { "video-recording": REPORT_VIDEO, "video-report": REPORT_VIDEO, song: SONG }; /** The kind a montage from a phrase search is (the phrase finder's Create montage). */ export const MONTAGE_KIND = REPORT_VIDEO; /** * The kind a make scaffolds, with what its form asks for (the registry's * `scaffold`), or null when that kind cannot be scaffolded here. * @param {string} make * @returns {{ id: string, label: string, scaffold: { fields: string[], brands?: { id: string, label: string }[] } } | null} */ export function makeKind(make) { const id = MAKE_KIND[make]; const k = id ? kindById(id) : null; if (!k?.scaffold) return null; return { id: k.id, label: k.label, scaffold: k.scaffold }; } const SWEEP_RE = /(^|[-_])sweep([-_]report)?\.md$|^sweep-report\.md$/i; /** * The sweep reports a video can be made from: each sweep-report project's * report file, newest first. * @param {{ id: string, dir: string, kind: string }[]} refs the project walk * @returns {Promise<{ project: string, path: string, title: string }[]>} */ export async function sweepReports(refs) { const out = []; for (const p of refs) { if (p.kind !== SWEEP) continue; const names = await readdir(/* turbopackIgnore: true */ p.dir).catch(() => []); const name = names.find((n) => SWEEP_RE.test(n)); if (!name) continue; const file = path.join(/* turbopackIgnore: true */ p.dir, name); const text = await readFile(/* turbopackIgnore: true */ file, "utf8").catch(() => ""); const title = text.match(/^#\s+(.+)$/m)?.[1]?.trim() ?? p.id; out.push({ project: p.id, path: file, title }); } return out; } /** The three scaffolding makes' kinds, as Create's page wants them. */ export function makeKinds() { return { recording: makeKind("video-recording"), report: makeKind("video-report"), song: makeKind("song") }; }