@typecad/typecad
Version:
🤖programmatically 💥create 🛰️hardware
47 lines (46 loc) • 2.02 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _KiCAD_possible_paths;
import fs from 'node:fs';
import { platform } from 'node:os';
import { lookpathSync } from 'find-bin';
import { Config } from './config';
let conf = new Config();
export let kicad_path;
export let kicad_cli_path;
export class KiCAD {
constructor() {
_KiCAD_possible_paths.set(this, [
'C:/Program Files/KiCad/9.0/',
'C:/Program Files/KiCad/7.0/', // windows
'C:/Program Files/KiCad/8.0/',
'/usr/share/kicad/', // linux
'/Applications/KiCAD/KiCad.app/Contents/ShareSupport/' // mac?
]);
// push typecad.json#kicad_path into the list to check
__classPrivateFieldGet(this, _KiCAD_possible_paths, "f").push(conf.get('kicad_path'));
for (const path of __classPrivateFieldGet(this, _KiCAD_possible_paths, "f")) {
if (fs.existsSync(path)) {
kicad_path = path; // share/kicad/symbols
break;
}
}
// if it found a path, figure out where 'kicad-cli' is
if (kicad_path) {
if (platform() == 'win32') {
kicad_cli_path = kicad_path + 'bin/kicad-cli.exe';
}
else {
// whereis
kicad_cli_path = lookpathSync('kicad-cli');
}
// if typecad.json#kicad_cli is set, use it
if (conf.get("kicad_cli") != '')
kicad_cli_path = conf.get("kicad_cli");
}
}
}
_KiCAD_possible_paths = new WeakMap();