imrishabh18/pedometer

This code defines and assembles a simple radio receiver hardware circuit using specific imported capacitors, inductors, RF connectors, and oscillator components with precise footprints and schematic attributes.

Version
1.1.3
License
unset
Stars
0

scripts/export-manufacturing.ts

import { createHash } from "node:crypto"
import { mkdir, readFile, writeFile } from "node:fs/promises"
import { convertCircuitJsonToGerberFiles } from "circuit-json-to-gerber"
import { prepareManufacturingCircuit } from "../manufacturing"

const source = await readFile("dist/index/circuit.json", "utf8")
const circuit = prepareManufacturingCircuit(JSON.parse(source))
const serialized = JSON.stringify(circuit, null, 2)
const files = convertCircuitJsonToGerberFiles(circuit)
const sha = (s:string) => createHash("sha256").update(s).digest("hex")
// Engineering-review outputs only. check:fabrication still controls release.
await mkdir("review/manufacturing", { recursive: true })
await writeFile("review/manufacturing/circuit.json", serialized)
for (const [name, content] of Object.entries(files)) await writeFile(`review/manufacturing/${name}`, content)
const drills = Object.entries(files).filter(([name]) => name.endsWith(".drl"))
const audit = {
  circuitSha256: sha(source), manufacturingCircuitSha256: sha(serialized),
  exporter: "circuit-json-to-gerber@0.0.104 (unpatched)",
  status: "engineering-review-only",
  drillFiles: drills.map(([name, content]) => ({ name,
    slotCount: [...content.matchAll(/^G85/gm)].length,
    hitCount: [...content.matchAll(/^X-?[\d.]+Y-?[\d.]+$/gm)].length,
    uniqueHitCount: new Set(content.match(/^X-?[\d.]+Y-?[\d.]+$/gm)).size,
  })),
  fileHashes: Object.fromEntries(Object.entries(files).map(([name, content]) => [name, sha(content)])),
}
if (drills.some(([name]) => name !== "drill-L1-L4.drl" && name !== "drill_npth.drl")) throw new Error("Unexpected blind/buried drill export")
if (audit.drillFiles.some(d => d.hitCount !== d.uniqueHitCount)) throw new Error("Duplicate drill hits")
await writeFile("review/drill-export-audit.json", JSON.stringify(audit, null, 2))
console.log(JSON.stringify(audit.drillFiles, null, 2))