ShiboSoftwareDev/mspm0g3507-gameboy-handheld

An AO3400A N-channel MOSFET for power switching and an AP2112K-3.3TRG1 LDO regulator providing a regulated 3.3 V output, both in compact SMD packages.

Version
1.2.1
License
unset
Stars
0

scripts/export-schematic.mjs

import { readFile, writeFile } from "node:fs/promises"
import {
  convertCircuitJsonToAssemblySvg,
  convertCircuitJsonToPcbSvg,
  convertCircuitJsonToStackedSchematicSheetsSvg,
} from "circuit-to-svg"

const circuitJsonPath = new URL("../dist/index/circuit.json", import.meta.url)
const schematicSvgPath = new URL(
  "../outputs/MSPM0G3507_GAMEBOY_Schematic.svg",
  import.meta.url,
)
const pcbSvgPath = new URL(
  "../outputs/MSPM0G3507_GAMEBOY_PCB.svg",
  import.meta.url,
)
const assemblySvgPath = new URL(
  "../outputs/MSPM0G3507_GAMEBOY_Assembly.svg",
  import.meta.url,
)

const circuitJson = JSON.parse(await readFile(circuitJsonPath, "utf8"))
const schematicSvg = convertCircuitJsonToStackedSchematicSheetsSvg(circuitJson, {
  width: 1600,
  height: 1000,
  includeVersion: true,
  showErrorsInTextOverlay: true,
  sheetLabelHeight: 32,
  sheetGap: 24,
})

await writeFile(schematicSvgPath, schematicSvg)
await writeFile(
  pcbSvgPath,
  convertCircuitJsonToPcbSvg(circuitJson, {
    width: 1600,
    height: 700,
    matchBoardAspectRatio: true,
    includeVersion: true,
    shouldDrawErrors: true,
    shouldDrawWarnings: true,
    showErrorsInTextOverlay: true,
    showSolderMask: true,
  }),
)
const assemblySvg = convertCircuitJsonToAssemblySvg(circuitJson, {
    width: 1600,
    height: 700,
    includeVersion: true,
    showErrorsInTextOverlay: true,
  })
  .replace(/<[^>]*(?:NaN|undefined)[^>]*\/>/g, "")
  .replace(/font-size="([\d.]+)px"/g, (_, size) =>
    `font-size="${Math.min(Number(size), 12).toFixed(1)}px"`)

await writeFile(assemblySvgPath, assemblySvg)
console.log(`Exported ${schematicSvgPath.pathname}`)
console.log(`Exported ${pcbSvgPath.pathname}`)
console.log(`Exported ${assemblySvgPath.pathname}`)