mohan-bee/four-gang-wifi-switch-layout
A tscircuit package created by mohan-bee.
- Version
- 0.0.9
- License
- unset
- Stars
- 0
capture.ts
PCB
Schematic
import { CircuitRunner } from "@tscircuit/eval"
import { readFile, writeFile } from "node:fs/promises"
import { createHash } from "node:crypto"
import { resolve } from "node:path"
const name=process.argv[2]
if(!["controller","relay"].includes(name)) throw new Error("Select a board")
const project=import.meta.dir
const folder=`${project}/proof/${name}`
const {default:Board}=await import(`${project}/${name}.circuit.tsx`)
const runner=new CircuitRunner()
const phaseEvents:unknown[]=[],phaseInputs:unknown[]=[]
runner.on("autorouting:start",event=>{phaseInputs.push(structuredClone(event))})
runner.on("autorouting:end",event=>{
phaseEvents.push(structuredClone(event))
console.log(JSON.stringify({phase:event.phaseName,router:event.autorouterName,cache:event.cacheStatus,traces:event.simpleRouteJson.traces.length}))
})
try {
await runner.executeComponent(Board)
await runner.renderUntilSettled()
const circuit=await runner.getCircuitJson()
const errors=circuit.filter(e=>e.type.includes("error"))
const raw=JSON.stringify(circuit,null,2)+"\n"
for(const path of [`${folder}/circuit.json`,`${project}/${name}.circuit.json`,`${project}/dist/${name}/circuit.json`]) await writeFile(path,raw)
await writeFile(`${folder}/phase-events.json`,JSON.stringify(phaseEvents,null,2)+"\n")
await writeFile(`${folder}/phase-inputs.json`,JSON.stringify(phaseInputs,null,2)+"\n")
if(errors.length) throw new Error(JSON.stringify(errors.slice(0,3)))
const files=[`${name}.circuit.tsx`,"default-capacity.ts"]
const sha256={}
for(const file of files) sha256[file]=createHash("sha256").update(await readFile(`${project}/${file}`)).digest("hex")
await writeFile(`${folder}/provenance.json`,JSON.stringify({
engine:"@tscircuit/capacity-autorouter",version:"0.0.1027",solver:"AutoroutingPipelineSolver9_PreloadedTraceGraph",fresh_routing:true,whole_phase_routing:true,
relay_mains_policy:"Preserve default capacity high-density paths; bypass trace simplification where preserveHighDensityPaths is enabled in source; later checks retained.",
pcbTracePaths_imports:0,manual_board_trace_paths:0,
source_sha256:sha256,circuit_sha256:createHash("sha256").update(raw).digest("hex"),
phases:phaseEvents.length,
},null,2)+"\n")
console.log(`${name}: fresh routing captured; ${circuit.filter(e=>e.type==="pcb_trace").length} traces`)
}finally{await runner.kill()}