UNPKG

@typecad/typecad

Version:

🤖programmatically 💥create 🛰️hardware

1 lines 3.2 kB
import{execSync}from'node:child_process';function a6_0x264f(_0x2486c8,_0x264f3a){const _0x61b029=a6_0x2486();return a6_0x264f=function(_0x5d971d,_0x13dcd8){_0x5d971d=_0x5d971d-0x0;let _0x5617a4=_0x61b029[_0x5d971d];return _0x5617a4;},a6_0x264f(_0x2486c8,_0x264f3a);}import{promisify}from'node:util';import{is_flatpak,kicad_cli_path}from'./kicad';const execAsync=promisify(execSync);export async function executeKiCADCommand(_0x1bb0df,_0x1d67f1=[],_0x2be2ce={}){const _0x12ca89=buildKiCADCommand(_0x1bb0df,_0x1d67f1);function _0x2b5643(_0xe9026d,_0x2e8d9b){return a6_0x264f(_0xe9026d- -0x3ce,_0x2e8d9b);}try{if(_0x2be2ce['stdio']==='inherit')return execSync(_0x12ca89,{'cwd':_0x2be2ce['cwd'],'stdio':_0x2b5643(-0x3ce,-0x3c9),'timeout':_0x2be2ce[_0x2b5643(-0x3cd,-0x3d1)]}),'';else{const _0x59c03e=await execAsync(_0x12ca89,{'cwd':_0x2be2ce['cwd'],'timeout':_0x2be2ce['timeout'],'stdio':[_0x2b5643(-0x3cc,-0x3cc),'pipe','pipe']});return _0x59c03e[_0x2b5643(-0x3cb,-0x3cd)]['toString']();}}catch(_0x14ee2b){throw new Error('KiCAD\x20command\x20failed:\x20'+_0x12ca89+'\x0a'+_0x14ee2b);}}export function executeKiCADCommandSync(_0x5a7521,_0x3c862d=[],_0x2c7e95={}){const _0x5613e4=buildKiCADCommand(_0x5a7521,_0x3c862d);function _0x528783(_0x1bf74b,_0x53ed57){return a6_0x264f(_0x1bf74b-0x1a1,_0x53ed57);}try{return _0x2c7e95[_0x528783(0x1a5,0x1a6)]===_0x528783(0x1a1,0x1a5)?(execSync(_0x5613e4,{'cwd':_0x2c7e95['cwd'],'stdio':'inherit','timeout':_0x2c7e95['timeout']}),''):execSync(_0x5613e4,{'cwd':_0x2c7e95[_0x528783(0x1a6,0x1a7)],'encoding':'utf8','timeout':_0x2c7e95[_0x528783(0x1a2,0x1a3)],'stdio':[_0x528783(0x1a3,0x1a2),'pipe','pipe']});}catch(_0x2a1443){throw new Error('KiCAD\x20command\x20failed:\x20'+_0x5613e4+'\x0a'+_0x2a1443);}}function buildKiCADCommand(_0x5edc6f,_0x739c18){function _0x5e4dd7(_0xd2bee4,_0x4419dd){return a6_0x264f(_0x4419dd- -0x174,_0xd2bee4);}if(is_flatpak){const _0x4650aa='kicad-cli\x20'+_0x5edc6f+'\x20'+_0x739c18[_0x5e4dd7(-0x169,-0x16e)]('\x20');return _0x5e4dd7(-0x16e,-0x16d)+_0x4650aa+'\x22';}else{const _0x5f3b20=kicad_cli_path||'kicad-cli',_0x18b030=_0x5f3b20[_0x5e4dd7(-0x171,-0x16c)]('\x20')?'\x22'+_0x5f3b20+'\x22':_0x5f3b20;return _0x18b030+'\x20'+_0x5edc6f+'\x20'+_0x739c18['join']('\x20');}}export async function runDRC(_0x4ad4dd,_0x3cf36b={}){return executeKiCADCommand('drc',[_0x4ad4dd],_0x3cf36b);}export async function upgradeFootprint(_0x54e3ab,_0x1bb24a={}){function _0x14ae45(_0x43c817,_0x2eb43d){return a6_0x264f(_0x2eb43d- -0x15,_0x43c817);}return executeKiCADCommand('fp',[_0x14ae45(-0xf,-0xc),_0x54e3ab],_0x1bb24a);}export async function exportPCB(_0xd8b5c4,_0x19fccf,_0x1f2d40,_0x3189a3={}){const _0x166d09=['export',_0x1f2d40,_0xd8b5c4,'-o',_0x19fccf];return executeKiCADCommand('',_0x166d09,_0x3189a3);}function a6_0x2486(){const _0x479bab=['inherit','timeout','pipe','stdout','stdio','cwd','join','flatpak\x20run\x20--command=sh\x20org.kicad.kicad\x20-c\x20\x22','includes','upgrade'];a6_0x2486=function(){return _0x479bab;};return a6_0x2486();}export async function exportSchematic(_0x39c486,_0x3b1703,_0x2369bc,_0xb5a3b8={}){const _0xd01884=['export',_0x2369bc,_0x39c486,'-o',_0x3b1703];return executeKiCADCommand('',_0xd01884,_0xb5a3b8);}