executableVersion.ts 454 B

123456789101112131415
  1. // SPDX-License-Identifier: Apache-2.0
  2. import { spawnSync } from 'child_process';
  3. export default function executableVersion(path: string): string | undefined {
  4. console.debug('Checking availability of a binary at', path);
  5. const res = spawnSync(path, ['--version'], { encoding: 'utf8' });
  6. if (res.status == 0) {
  7. const match = res.stdout.match(/solang version v([\d.]+)/);
  8. if (match) {
  9. return match[1];
  10. }
  11. }
  12. return undefined;
  13. }