ShiboSoftwareDev/i-wan

This code defines a PCB and schematic for a microcontroller development board, incorporating various surface-mount components (resistors, capacitors, headers, connectors, crystals, and an IC), with detailed footprints, electrical nets, and routing instructions.

Version
1.0.10
License
unset
Stars
0

scripts/make-check-shorts-repros.mjs

import { mkdirSync, readFileSync, writeFileSync } from "node:fs"
import { resolve } from "node:path"

const inputPath = resolve(process.argv[2] ?? "dist/index/circuit.json")
const outputDir = resolve(process.argv[3] ?? "checks/check-shorts/repros")
const circuit = JSON.parse(readFileSync(inputPath, "utf8"))

const mapLayerToTwoLayerBoard = (element, selectedLayer) => {
  const mapped = structuredClone(element)
  const mapLayer = (layer) => layer === selectedLayer ? "top" : "bottom"

  if (mapped.type === "pcb_board") mapped.num_layers = 2
  if (typeof mapped.layer === "string") mapped.layer = mapLayer(mapped.layer)
  if (Array.isArray(mapped.layers)) {
    mapped.layers = [...new Set(mapped.layers.map(mapLayer))]
  }
  if (typeof mapped.from_layer === "string") mapped.from_layer = mapLayer(mapped.from_layer)
  if (typeof mapped.to_layer === "string") mapped.to_layer = mapLayer(mapped.to_layer)
  if (mapped.type === "pcb_trace") {
    mapped.route = mapped.route.map((point) => {
      const mappedPoint = { ...point }
      if (typeof mappedPoint.layer === "string") mappedPoint.layer = mapLayer(mappedPoint.layer)
      if (typeof mappedPoint.from_layer === "string") mappedPoint.from_layer = mapLayer(mappedPoint.from_layer)
      if (typeof mappedPoint.to_layer === "string") mappedPoint.to_layer = mapLayer(mappedPoint.to_layer)
      return mappedPoint
    })
  }
  return mapped
}

mkdirSync(outputDir, { recursive: true })
writeFileSync(
  resolve(outputDir, "no-copper-pours.circuit.json"),
  JSON.stringify(circuit.filter((element) => element.type !== "pcb_copper_pour")),
)

for (const layer of ["inner1", "inner2"]) {
  writeFileSync(
    resolve(outputDir, `${layer}-as-top.circuit.json`),
    JSON.stringify(circuit.map((element) => mapLayerToTwoLayerBoard(element, layer))),
  )
}

console.log(`Wrote check-shorts isolation repros to ${outputDir}`)