mohan-bee/infrared-battle-tag

A compact board featuring an ATtiny1616 microcontroller, tactile switch, and MMBT2222A transistor, with VCC/GND power and the switch connected to the MCU’s PA4 input.

Version
1.0.2
License
unset
Stars
0

evidence/repair-kicad-export.ts

import { CircuitJsonToKicadSchConverter } from "circuit-json-to-kicad"
import JSZip from "jszip"

// CLI 0.1.2095 writes only getOutputString(), dropping child schematic files.
// Keep the PCB/models, but replace the entire schematic hierarchy together.
const json = await Bun.file("dist/index/circuit.json").json()
const converter = new CircuitJsonToKicadSchConverter(json)
converter.runUntilFinished()
const zip = await JSZip.loadAsync(await Bun.file("dist/index/infrared-battle-tag.kicad.zip").arrayBuffer())
for (const file of converter.getOutputFiles({ schematicFilename: "circuit.kicad_sch" })) {
  zip.file(file.filename, file.content)
  console.log(`Included ${file.filename}: ${file.content.length} bytes`)
}
for (const [name, file] of Object.entries(zip.files)) {
  if (!name.endsWith(".kicad_sch")) continue
  const contents = await file.async("string")
  for (const match of contents.matchAll(/\(property "Sheetfile" "([^"]+)"/g)) {
    if (!zip.file(match[1])) throw new Error(`Missing child schematic: ${match[1]}`)
  }
}
const child = await zip.file("main.kicad_sch")!.async("string")
for (const ref of ["U1", "U2", "Q1", "SW1", "SW2", "J1", "J2", "LED1"]) {
  if (!child.includes(`"Reference" "${ref}"`)) throw new Error(`Missing ${ref} in child schematic`)
}
await Bun.write("infrared-battle-tag.kicad.zip", await zip.generateAsync({ type: "uint8array", compression: "DEFLATE" }))
console.log("All child schematic references resolve; required components are present.")