abse/boostxl-uln2003

This code defines a React component that models a through-hole or surface-mount LED with specified pin labels, footprint, silkscreen, and 3D CAD model for PCB layout.

Version
1.0.5
License
unset
Stars
0

scripts/render-snapshots.mjs

import { mkdirSync, readFileSync, writeFileSync } from "node:fs"
import { dirname, join } from "node:path"
import { fileURLToPath } from "node:url"
import {
  convertCircuitJsonToPcbSvg,
  convertCircuitJsonToSchematicSvg,
  convertCircuitJsonToStackedSchematicSheetsSvg,
} from "circuit-to-svg"
import { Resvg } from "@resvg/resvg-js"

const root = join(dirname(fileURLToPath(import.meta.url)), "..")
const circuit = JSON.parse(readFileSync(join(root, "dist/index/circuit.json"), "utf8"))
const outputDir = join(root, "__snapshots__")

mkdirSync(outputDir, { recursive: true })
const schematicSvg = convertCircuitJsonToStackedSchematicSheetsSvg(circuit)
const pcbSvg = convertCircuitJsonToPcbSvg(circuit)

writeFileSync(join(outputDir, "index.circuit-schematic.snap.svg"), schematicSvg)
writeFileSync(join(outputDir, "index.circuit-pcb.snap.svg"), pcbSvg)
writeFileSync(join(outputDir, "index.circuit-schematic.snap.png"), new Resvg(schematicSvg, { fitTo: { mode: "width", value: 1800 } }).render().asPng())
writeFileSync(join(outputDir, "index.circuit-pcb.snap.png"), new Resvg(pcbSvg, { fitTo: { mode: "width", value: 1800 } }).render().asPng())

const sheets = circuit
  .filter((element) => element.type === "schematic_sheet")
  .sort((a, b) => a.sheet_index - b.sheet_index)

for (const sheet of sheets) {
  const sheetSvg = convertCircuitJsonToSchematicSvg(circuit, {
    schematicSheetId: sheet.schematic_sheet_id,
  })
  const basename = `index.circuit-schematic-sheet-${sheet.sheet_index}`
  writeFileSync(join(outputDir, `${basename}.snap.svg`), sheetSvg)
  writeFileSync(join(outputDir, `${basename}.snap.png`), new Resvg(sheetSvg, { fitTo: { mode: "width", value: 1800 } }).render().asPng())
}

console.log("Rendered stacked, per-sheet, and PCB snapshots from reviewed dist/index/circuit.json")