abse/smartwatch-flex-top-only
Three-panel flex smartwatch with two parallel R3.9 bends, all components flat-top, low-profile JST connector harnesses, split heartbeat optical windows and screw-retained PCB mounting. Modeled 39 × 50.5 × 14.5mm prototype; 100% routing, zero native DRC and shorts. Hardware qualification pending.
- Version
- 0.2.20
- License
- unset
- Stars
- 0
scripts/cloud-preview-cache.mjs
import fs from 'node:fs'
import crypto from 'node:crypto'
const physicalTypes=new Set(['pcb_board','pcb_bend','pcb_component','pcb_smtpad','pcb_trace','pcb_via','pcb_plated_hole','pcb_copper_pour','pcb_keepout','pcb_stiffener','pcb_cutout','cad_component'])
export const sha=b=>crypto.createHash('sha256').update(b).digest('hex')
function clean(value){
if(Array.isArray(value))return value.map(clean)
if(value&&typeof value==='object')return Object.fromEntries(Object.keys(value).sort().filter(k=>!k.endsWith('_id')).map(k=>[k,clean(value[k])]))
if(typeof value==='number')return Math.round(value*1e9)/1e9
return value
}
export function geometrySha(circuit){
return sha(JSON.stringify(circuit.filter(e=>physicalTypes.has(e.type)).map(e=>JSON.stringify(clean(e))).sort()))
}
export function cachePreviews(verify=false){
const manifest=JSON.parse(fs.readFileSync('mechanical/site-previews/manifest.json','utf8'))
for(const [name,entry] of Object.entries(manifest.entries)){
const png=fs.readFileSync(`mechanical/site-previews/${name}.png`)
if(sha(png)!==entry.pngSha256)throw Error(`Changed ${name} preview image`)
if(verify){
const circuit=JSON.parse(fs.readFileSync(`dist/${name}/circuit.json`,'utf8'))
if(circuit.some(e=>e.type.includes('error')))throw Error(`Native error in ${name}`)
if(geometrySha(circuit)!==entry.physicalGeometrySha256)throw Error(`Stale preview geometry for ${name}; regenerate snapshots`)
}else{
fs.mkdirSync(`dist/${name}`,{recursive:true})
fs.writeFileSync(`dist/${name}/3d.png`,png)
}
}
const count=Object.keys(manifest.entries).length
console.log(verify?`All ${count} preview snapshots match freshly compiled PCB and CAD geometry`:`Loaded ${count} verified CAD snapshots for site thumbnails`)
}