lines.mjs
31 lines · scripts/lines.mjs at 1482e84
1import { spawn } from "node:child_process";
2import { dirname, join } from "node:path";
3import { fileURLToPath } from "node:url";
5const argv = process.argv.slice(2);
6if (!argv.length || argv.includes("--help") || argv.includes("-h")) {
7 console.log(`Check that every texture line in a figure ends on something.
9 node lines.mjs <file.html | url> [--out marks.png] [--tolerance 1] [--select css] [--wait 1500] [drive.mjs flags]
11Every open subpath of every .iso-line (seams, grooves, ribs, rule lines, ticks, needles) must end on another stroke,
12a dot or an outline within the tolerance (viewBox px), or under a fill painted after it. A short straight mark (a tick)
13needs one rooted end. Outlines, creases, bevels and tube edges are the kit's own and are not checked. Lines drawn with
14fadeLineSvg ramp out and pass; lineSvg(d, { free: true | "start" | "end" }) marks an end that is meant to stop (a needle
15tip, rule lines standing for printed text). Exits 1 if any end floats; --out writes the card with each one ringed.`);
16 process.exit(argv.length ? 0 : 1);
17}
18const take = (flag, fallback) => {
19 const at = argv.indexOf(flag);
20 if (at < 0) return fallback;
21 const value = argv[at + 1];
22 argv.splice(at, 2);
23 return value;
24};
25const out = take("--out", null);
26const tolerance = Number(take("--tolerance", 1));
27const select = take("--select", null);
28const wait = Number(take("--wait", 1500));
29const actions = JSON.stringify([["wait", wait], ["lines", out, select, { tolerance }]]);
30const child = spawn(process.execPath, [join(dirname(fileURLToPath(import.meta.url)), "drive.mjs"), argv[0], actions, ...argv.slice(1)], { stdio: "inherit" });
31child.on("exit", (code) => process.exit(code ?? 1));