imrishabh18/pcbgolf

This code defines detailed PCB footprints for various electronic components (such as resistors, capacitors, connectors, ICs, LEDs, and via/hole patterns), as well as associated metadata (pin mappings, CAD models, labels) for a circuit design, enabling precise rendering and integration into a PCB layout in a React-based schematic editor.

Version
1.4.1
License
unset
Stars
0

scripts/dev.ts

import {mkdir} from 'node:fs/promises'
import {resolve} from 'node:path'
const root=resolve(import.meta.dir,'..')
const workerPath=resolve(root,'node_modules/tscircuit/dist/webworker.min.js')
const browserPath=resolve(root,'node_modules/tscircuit/dist/browser.min.js')
const originalWorker=await Bun.file(workerPath).text()
const originalBrowser=await Bun.file(browserPath).text()
const encodedWorker=Buffer.from(originalWorker).toString('base64')
if (originalBrowser.split(encodedWorker).length!==2) throw new Error('Unexpected tscircuit bundle: embedded worker must match exactly once')
for (const name of ['runAllRoutingChecks','runAllPlacementChecks']) {
 if (!originalWorker.includes(`function ${name}(`)) throw new Error(`Unsupported evaluation worker: ${name} binding missing`)
}
const build=await Bun.build({entrypoints:[resolve(root,'scripts/browser-drc.ts')],target:'browser',format:'iife',minify:true})
if (!build.success) throw new Error('Unable to bundle the installed DRC checks: '+build.logs.map(String).join('\n'))
// The shipped runframe contains its own evaluation worker. Replace only that
// worker's routing/placement checker bindings with this project's installed,
// regression-tested checks. UI, rendering, netlist checks and source evaluation
// remain the official tscircuit implementation. No error filtering is performed.
// The shipped loader uses atob, so appended JavaScript must be ASCII-safe.
const checksCode=(await build.outputs[0].text()).replace(/[^\x00-\x7f]/g, c=>'\\u'+c.charCodeAt(0).toString(16).padStart(4,'0'))
const worker=originalWorker+'\n'+checksCode+`\nrunAllRoutingChecks=globalThis.__pcbgolfDrcChecks.runAllRoutingChecks;
runAllPlacementChecks=globalThis.__pcbgolfDrcChecks.runAllPlacementChecks;
delete globalThis.__pcbgolfDrcChecks;\n`
// Validate the exact byte-string decoded by the browser's atob loader.
new Bun.Transpiler({loader:'js',target:'browser'}).transformSync(Buffer.from(worker).toString('latin1'))
const browser=originalBrowser.replace(encodedWorker,Buffer.from(worker).toString('base64'))
const bundlePath=resolve(root,'.tscircuit/drc-browser.min.js')
await mkdir(resolve(root,'.tscircuit'),{recursive:true})
await Bun.write(bundlePath,browser)
console.log('Using the project DRC checks in the standard tscircuit browser worker')
if (!process.argv.includes('--prepare-only')) {
 const child=Bun.spawn(['bun',resolve(root,'node_modules/tscircuit/cli.mjs'),'dev',...process.argv.slice(2)],{
  cwd:root,env:{...process.env,RUNFRAME_STANDALONE_FILE_PATH:bundlePath},stdin:'inherit',stdout:'inherit',stderr:'inherit'
 })
 process.exit(await child.exited)
}