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

55 lines
1.4 KiB
TypeScript

/*
Install DevChat with python=3.11.4
*/
import { logger } from "../logger";
import { appInstall } from "./app_install"
import * as path from 'path';
import * as fs from 'fs';
let isDevChatInstalling: boolean | undefined = undefined;
export function isDevchatInstalling(): boolean {
if (isDevChatInstalling === true) {
return true;
}
return false;
}
// python version: 3.11.4
// pkg name: devchat
// return: path to devchat, devchat is located in the same directory as python
export async function installDevchat(): Promise<string> {
try {
logger.channel()?.info(`start installing devchat with python=3.11.4 ...`);
isDevChatInstalling = true;
const pythonCommand = await appInstall('devchat', "", '3.11.4');
if (!pythonCommand) {
logger.channel()?.error(`failed to install devchat with python=3.11.4`);
logger.channel()?.show();
isDevChatInstalling = false;
return '';
}
// Get the directory of pythonCommand
const pythonDirectory = path.dirname(pythonCommand);
// Get the path of devchat
let devchatPath = path.join(pythonDirectory, 'devchat');
// Check if devchatPath exists, if not, try with 'Scripts' subdirectory
if (!fs.existsSync(devchatPath)) {
devchatPath = path.join(pythonDirectory, 'Scripts', 'devchat');
}
isDevChatInstalling = false;
return devchatPath;
} catch (error) {
logger.channel()?.error(`${error}`);
logger.channel()?.show();
isDevChatInstalling = false;
return '';
}
}