seveibar/pedometer

This hardware setup integrates a Type-C connector, battery, display, and RF antenna connected through a microcontroller, USB interface, charging and fuel gauge ICs, along with associated passive components, enabling power management, data communication, and signal processing.

Version
0.4.4
License
unset
Stars
1

scripts/validate.mjs

import fs from 'node:fs'
import crypto from 'node:crypto'
import {runAllChecks,checkTracesAreContiguous} from '@tscircuit/checks'
const path='dist/index/circuit.json'
const json=JSON.parse(fs.readFileSync(path,'utf8'))
const emitted=json.filter(e=>/error$/.test(e.type))
const rerun=[...await runAllChecks(json),...checkTracesAreContiguous(json)]
const errors=[...new Map([...emitted,...rerun.filter(e=>/error$/.test(e.type))].map(e=>[e.type+'|'+e.message,e])).values()]
const warnings=[...new Map([...json,...rerun].filter(e=>/warning$/.test(e.type)).map(e=>[e.type+'|'+e.message,e])).values()]
const counts=xs=>xs.reduce((a,e)=>(a[e.type]=(a[e.type]||0)+1,a),{})
const summary={timestamp:new Date().toISOString(),circuitSha256:crypto.createHash('sha256').update(fs.readFileSync(path)).digest('hex'),components:json.filter(e=>e.type==='pcb_component').length,traces:json.filter(e=>e.type==='pcb_trace').length,vias:json.filter(e=>e.type==='pcb_via').length,errorCounts:counts(errors),warningCounts:counts(warnings),errors,warnings}
fs.writeFileSync('validation.json',JSON.stringify(summary,null,2)+'\n')
console.log(JSON.stringify({...summary,errors:undefined,warnings:undefined},null,2))
process.exitCode=errors.length?1:0