@typecad/schematic
Version:
Generate KiCAD schematics from your typeCAD project
45 lines (39 loc) • 1.55 kB
text/typescript
import fs from 'node:fs';
import { platform } from 'node:os';
import {lookpathSync} from 'find-bin';
export let kicad_path: string | undefined;
export let kicad_cli_path: string | undefined;
export class KiCAD {
#possible_paths: string[] = [
'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?
]
constructor() {
let foundPath: string | undefined = undefined;
for (const path of this.#possible_paths) {
if (fs.existsSync(path)) {
const symbolsSubDir = platform() === 'win32' ? 'share/kicad/symbols' : 'symbols';
const expectedSymbolsPath = path + symbolsSubDir;
if (fs.existsSync(expectedSymbolsPath)) {
foundPath = path;
break;
}
}
}
if (foundPath) {
kicad_path = foundPath;
} else {
console.error('Could not find a valid KiCAD installation path with symbols directory.');
}
if (kicad_path) {
if (platform() == 'win32') {
kicad_cli_path = kicad_path + 'bin/kicad-cli.exe';
} else {
kicad_cli_path = lookpathSync('kicad-cli');
}
}
}
}