Download backend/scripts/check-embeds.ts from HuggingFaceSwarms/scaling-swarms: direct link, hf CLI and curl.
- Browser
- Download file 2.72 kB
-
https://huggingface.co/spaces/HuggingFaceSwarms/scaling-swarms/resolve/main/backend/scripts/check-embeds.ts
- Command line
-
hf download hf://spaces/HuggingFaceSwarms/scaling-swarms/backend/scripts/check-embeds.ts
-
curl -L -o check-embeds.ts https://huggingface.co/spaces/HuggingFaceSwarms/scaling-swarms/resolve/main/backend/scripts/check-embeds.ts
2.72 kB
| // Render the editor's embeds exactly as readers get them and report what is | |
| // broken or hard to read (see embed-check/check.ts). | |
| // | |
| // npm run check:embeds # every built-in embed | |
| // npm run check:embeds -- memory-bar banner # filter by name | |
| // npm run check:embeds -- --file chart.html [--banner] | |
| // npm run check:embeds -- --widths 360,760 --out .embed-check | |
| // | |
| // Exit code 1 when any embed fails. Screenshots land in <out>/<name>/. | |
| import { readFile } from "node:fs/promises"; | |
| import { basename, dirname, resolve } from "node:path"; | |
| import { backendDir, checkOne, launchBrowser, reportStatus } from "./embed-check/check.js"; | |
| import { BUILTIN_EMBEDS, type EmbedEntry } from "./embed-check/registry.js"; | |
| interface Options { | |
| names: string[]; | |
| files: string[]; | |
| banner: boolean; | |
| widths: number[]; | |
| out: string; | |
| } | |
| function parseArgs(argv: string[]): Options { | |
| const opts: Options = { names: [], files: [], banner: false, widths: [360, 760], out: ".embed-check" }; | |
| for (let i = 0; i < argv.length; i++) { | |
| const a = argv[i]; | |
| if (a === "--file") opts.files.push(argv[++i]); | |
| else if (a === "--banner") opts.banner = true; | |
| else if (a === "--widths") opts.widths = argv[++i].split(",").map(Number).filter(Boolean); | |
| else if (a === "--out") opts.out = argv[++i]; | |
| else opts.names.push(a); | |
| } | |
| return opts; | |
| } | |
| const opts = parseArgs(process.argv.slice(2)); | |
| let entries: EmbedEntry[] = BUILTIN_EMBEDS; | |
| if (opts.files.length) { | |
| entries = await Promise.all(opts.files.map(async (f) => ({ | |
| name: basename(f).replace(/\.html$/, ""), | |
| html: await readFile(resolve(process.cwd(), f), "utf8"), | |
| banner: opts.banner, | |
| }))); | |
| } else if (opts.names.length) { | |
| entries = BUILTIN_EMBEDS.filter((e) => opts.names.some((n) => e.name.includes(n))); | |
| if (!entries.length) { | |
| console.error(`No built-in embed matches ${opts.names.join(", ")}. Known: ${BUILTIN_EMBEDS.map((e) => e.name).join(", ")}`); | |
| process.exit(2); | |
| } | |
| } | |
| const browser = await launchBrowser(); | |
| let failed = 0; | |
| try { | |
| for (const entry of entries) { | |
| const r = await checkOne(browser, entry, opts); | |
| if (r.fails.length) failed++; | |
| console.log(`\n${reportStatus(r)} ${r.name}${entry.banner ? " (banner)" : ""}`); | |
| r.fails.forEach((f) => console.log(` x ${f}`)); | |
| r.warns.forEach((w) => console.log(` ! ${w}`)); | |
| console.log(` screenshots: ${relativeOut(r.shots[0])}`); | |
| } | |
| } finally { | |
| await browser.close(); | |
| } | |
| console.log(`\n${entries.length - failed}/${entries.length} embed(s) without failures.`); | |
| process.exit(failed ? 1 : 0); | |
| function relativeOut(p: string | undefined): string { | |
| return p ? dirname(p).replace(`${backendDir}/`, "") : ""; | |
| } | |