imrishabh18/corne-keyboard

The code defines and renders two surface-mount chip components with SMT pads, silkscreen outlines, and 3D CAD models (OBJ and STEP) for PCB assembly.

Version
2.0.21
License
unset
Stars
1

scripts/patch-core-panel-pour.mjs

import fs from 'node:fs'
const base=new URL('../node_modules/@tscircuit/core/',import.meta.url)
const pkg=JSON.parse(fs.readFileSync(new URL('package.json',base),'utf8'))
if(pkg.version!=='0.0.1861')throw Error('Review the panel pour patch before upgrading core')
const file=new URL('dist/index.js',base)
let code=fs.readFileSync(file,'utf8')
const marker='/* corne-panel-pour-owning-board */'
if(!code.includes(marker)){
 const needle='  const circuitJson = db.toArray();\n  const pcbBoard = circuitJson.find((element) => element.type === "pcb_board");\n  let resolvedPcbBoardOutline'
 if(code.split(needle).length!==2)throw Error('Unexpected core bundle: refusing to patch')
 code=code.replace(needle,`  const circuitJson = db.toArray();
  ${marker}
  const owningBoard = subcircuit._getBoard();
  const pcbBoard = owningBoard?.pcb_board_id
    ? db.pcb_board.get(owningBoard.pcb_board_id)
    : circuitJson.find((element) => element.type === "pcb_board");
  let resolvedPcbBoardOutline`)
 fs.writeFileSync(new URL('dist/index.js.corne-patched',base),code)
 fs.renameSync(new URL('dist/index.js.corne-patched',base),file)
 console.log('Patched core copper pours to use their owning panel board')
}