gokul/wireless-calculator

A USB‑C rechargeable battery-powered controller board with MCP73871 Li‑ion charging, TPS63070 buck‑boost and LDO power regulation, ATmega328P and ESP32‑S3 control, LCD/keypad user interface, status LEDs, and UART/programming connectors.

Version
0.0.1
License
ISC
Stars
0

scripts/render-review.ts

import fs from "node:fs/promises";
import {
  convertCircuitJsonToSchematicSvg,
  convertCircuitJsonToPcbSvg,
} from "circuit-to-svg";
import { Resvg } from "@resvg/resvg-js";

const circuit = JSON.parse(
  await fs.readFile(process.argv[2] ?? "dist/index/circuit.json", "utf8"),
);
const directory = "dist/review";
await fs.mkdir(directory, { recursive: true });
async function save(name: string, svg: string) {
  await fs.writeFile(`${directory}/${name}.svg`, svg);
  await fs.writeFile(
    `${directory}/${name}.png`,
    new Resvg(svg).render().asPng(),
  );
}
const sheets = circuit.filter(
  (element: { type: string }) => element.type === "schematic_sheet",
);
for (const [index, sheet] of sheets.entries()) {
  await save(
    `schematic-${String(index + 1).padStart(2, "0")}`,
    convertCircuitJsonToSchematicSvg(circuit, {
      schematicSheetId: sheet.schematic_sheet_id,
      width: 1600,
      height: 1000,
      shouldDrawErrors: true,
    }),
  );
}
for (const layer of ["top", "bottom"] as const) {
  await save(
    `pcb-${layer}`,
    convertCircuitJsonToPcbSvg(circuit, {
      layer,
      width: 1800,
      height: 3800,
      matchBoardAspectRatio: true,
      showPinNumbers: true,
      shouldDrawErrors: true,
    }),
  );
}
await fs.writeFile(`${directory}/sheets.json`, JSON.stringify(sheets, null, 2));
console.log(`Rendered ${sheets.length} schematic sheets and both PCB sides.`);