Devesh36/facet-four

FACET Four: a USB-C macro controller with four angled keys, a volume encoder, blue LEDs, an OLED and a fitted enclosure. Includes assembled, exploded and routed PCB views. Hardware prototype; firmware required.

Version
0.1.3
License
unset
Stars
0

scripts/validate.ts

import {readFileSync} from 'node:fs'
import {runAllChecks} from '@tscircuit/checks'
import * as circuitJson from 'circuit-json'
import {nets} from '../index.circuit'
let failed=false
for(const entry of ['index','assembly','exploded']){
 const c=JSON.parse(readFileSync(`dist/${entry}/circuit.json`,'utf8'))
 const emitted=c.filter((e:any)=>e.type.endsWith('_error'))
 const warnings=c.filter((e:any)=>e.type.endsWith('_warning'))
 const checked=await runAllChecks(c)
 const errors=checked.filter(e=>e.type.endsWith('_error'))
 const schema=c.flatMap((e:any,i:number)=>{const schema=(circuitJson as Record<string,any>)[e.type] ?? circuitJson.any_circuit_element;const r=schema.safeParse(e);return r.success?[]:[{index:i,type:e.type,issues:r.error.issues}]})
 const missing:string[]=[]
 for(const [name,pins] of Object.entries(nets)){
  const net=c.find((e:any)=>e.type==='source_net'&&e.name===name)
  for(const pin of pins){
   const [ref,p]=pin.split('.')
   const component=c.find((e:any)=>e.type==='source_component'&&e.name===ref)
   const port=c.find((e:any)=>e.type==='source_port'&&e.source_component_id===component?.source_component_id&&(e.name===p||e.port_hints?.includes(p)))
   if(!net||!port||!c.some((e:any)=>e.type==='source_trace'&&e.connected_source_net_ids?.includes(net.source_net_id)&&e.connected_source_port_ids?.includes(port.source_port_id)))missing.push(`${pin} -> ${name}`)
  }
 }
 console.log(JSON.stringify({entry,components:c.filter((e:any)=>e.type==='source_component').length,traces:c.filter((e:any)=>e.type==='pcb_trace').length,emitted,independentErrors:errors,schemaErrorCount:schema.length,schemaErrors:schema.map((e:any)=>({type:e.type,fields:e.issues.map((i:any)=>i.path.join("."))})),missingConnections:missing,warnings},null,2))
 failed ||= !!(emitted.length||errors.length||schema.length||missing.length)
}
process.exitCode=failed?1:0