AnasSarkiz/ble-pedometer

This code defines and configures various electronic hardware components such as surface-mount resistors, crystals, diodes, transistors, connectors, and switches with their physical footprints, schematic symbols, and 3D CAD models for PCB assembly.

Version
1.0.7
License
unset
Stars
0

lib/export-manufacturing-review.ts

import { mkdir, mkdtemp } from "node:fs/promises"
import { createHash } from "node:crypto"
import { Circuit } from "tscircuit"
import Board from "../index.circuit"
import { getManufacturingReview } from "./get-manufacturing-review"

export async function exportManufacturingReview() {
  // Render through the public core API to retain its typed, unchanged output.
  // The source still uses the same auto_local autorouter and fabrication rules.
  const circuit = new Circuit()
  circuit.add(Board())
  await circuit.renderUntilSettled()
  const circuitJson = circuit.getCircuitJson()
  const review = await getManufacturingReview(circuitJson)
  await mkdir("dist", { recursive: true })
  const outputDirectory = await mkdtemp("dist/manufacturing-review-")
  const circuitJsonText = JSON.stringify(circuitJson, null, 2)
  await Bun.write(`${outputDirectory}/circuit.json`, circuitJsonText)
  for (const [fileName, contents] of Object.entries(review.files)) {
    await Bun.write(`${outputDirectory}/${fileName}`, contents)
  }
  await Bun.write(`${outputDirectory}/review.json`, JSON.stringify({
    releasedForManufacturing: false,
    circuitJsonSha256: createHash("sha256").update(circuitJsonText).digest("hex"),
    fittedPartCount: review.bomRows.length,
    orientationReviewRequired: review.orientationReviewRequired,
    requiredSignoff: ["Independent shorts and silkscreen checks on this circuit.json", "JLCPCB placement/orientation and CAM review", "Battery, RF and first-article qualification"],
  }, null, 2))
  console.log(`Review files: ${outputDirectory}`)
  console.log(`50 fitted parts; through-board drills only. ${review.orientationReviewRequired.length} placements require supplier orientation review. NOT released for ordering.`)
}