seveibar/nema17-rp2040-stepper-controller

A tscircuit package created by seveibar.

Version
0.3.1
License
unset
Stars
0

scripts/validate-usb-release.ts

import {readFileSync,writeFileSync,mkdirSync} from 'node:fs';
import {createHash} from 'node:crypto';
import {runAllChecks} from '@tscircuit/checks';
const file=process.argv[2]??'dist/index/circuit.json';
const raw=readFileSync(file,'utf8');const circuit=JSON.parse(raw);
const findings=await runAllChecks(structuredClone(circuit));
const embedded=circuit.filter((e:any)=>e.type.endsWith('_error'));
const errors=findings.filter((e:any)=>e.type.endsWith('_error'));
const warnings=findings.filter((e:any)=>e.type.endsWith('_warning'));
const counts=(items:any[])=>Object.fromEntries([...new Set(items.map(e=>e.type))].map(t=>[t,items.filter(e=>e.type===t).length]));
const report={file,sha256:createHash('sha256').update(raw).digest('hex'),embeddedErrors:embedded,checkErrors:errors,warnings,counts:{embedded:counts(embedded),errors:counts(errors),warnings:counts(warnings)},pcbTraces:circuit.filter((e:any)=>e.type==='pcb_trace').length};
mkdirSync('reports',{recursive:true});writeFileSync('reports/usb-release-validation.json',JSON.stringify(report,null,2));
console.log(JSON.stringify({pcbTraces:report.pcbTraces,counts:report.counts},null,2));
if(embedded.length||errors.length)process.exitCode=1;