bobo.yang 48a9f0cb28 Add version check for devchat-ask package
- Added a version check for the devchat-ask package in commands.ts.
- Updated appInstall function in app_install.ts to accept package version.
- Modified installAskCode function in install_askcode.ts to pass package version to appInstall.
- Updated installDevchat function in install_devchat.ts to pass empty string as package version to appInstall.
- Added a new utility function getPackageVersion in pip_package_version.ts to get the installed version of a package.
2023-08-24 10:45:51 +08:00

13 lines
499 B
TypeScript

import { execSync } from 'child_process';
export function getPackageVersion(pythonPath: string, packageName: string): string | undefined {
try {
const stdout = execSync(`${pythonPath} -m pip show ${packageName}`).toString();
const versionLine = stdout.split('\n').find(line => line.startsWith('Version'));
return versionLine ? versionLine.split(': ')[1] : undefined;
} catch (error) {
console.error(`exec error: ${error}`);
return undefined;
}
}