AnasSarkiz/ble-pedometer
This code defines and configures various electronic hardware components such as surface-mount resistors, crystals, diodes, transistors, connectors, and switches with their physical footprints, schematic symbols, and 3D CAD models for PCB assembly.
- Version
- 1.0.7
- License
- unset
- Stars
- 0
scripts/check-silkscreen.ts
import { pcb_silkscreen_text, pcb_courtyard_outline, pcb_smtpad, pcb_via, pcb_hole, pcb_plated_hole } from "circuit-json"
import { z } from "zod"
import { getSilkscreenTextIssues } from "../lib/get-silkscreen-text-issues"
const inputPath = process.argv[2] ?? "dist/index/circuit.json"
// Validate every geometry record consumed by this dedicated text-clearance check.
// Schematic and supplier metadata belong to the separate source/build checks.
const envelope = z.array(z.object({ type: z.string() }).passthrough()).parse(await Bun.file(inputPath).json())
// Board-level text has no owning component in core's emitted Circuit JSON.
const boardOrFootprintText = pcb_silkscreen_text.extend({ pcb_component_id: z.string().nullable().optional() })
const geometrySchema = z.union([boardOrFootprintText, pcb_courtyard_outline, pcb_smtpad, pcb_via, pcb_hole, pcb_plated_hole])
const geometryTypes = new Set(["pcb_silkscreen_text", "pcb_courtyard_outline", "pcb_smtpad", "pcb_via", "pcb_hole", "pcb_plated_hole"])
const circuitJson = envelope.filter(element => geometryTypes.has(element.type)).map(element => {
const parsed = geometrySchema.safeParse(element)
if (!parsed.success) throw new Error(`Invalid ${element.type} geometry in ${inputPath}`)
return parsed.data
})
if (!circuitJson.some(element => element.type === "pcb_silkscreen_text") || !circuitJson.some(element => element.type === "pcb_smtpad")) throw new Error("Missing silkscreen or pad geometry")
const issues = getSilkscreenTextIssues(circuitJson)
if (issues.length) throw new Error(`Silkscreen text clearance failed:\n${issues.join("\n")}`)
console.log("Silkscreen text: no envelope collisions with labels, pads, drills or courtyards")