refactor: update MCPService and process utilities for improved binary management
- Refactored MCPService to streamline command handling for 'npx' and 'uvx', removing unnecessary installation checks and directly retrieving binary paths. - Updated getBinaryPath and isBinaryExists functions to be asynchronous, enhancing their reliability in checking binary existence and paths. - Cleaned up imports and removed unused dependencies for better code clarity.
This commit is contained in:
@@ -35,16 +35,15 @@ export function runInstallScript(scriptPath: string): Promise<void> {
|
||||
})
|
||||
}
|
||||
|
||||
export function getBinaryPath(name: string): string {
|
||||
export async function getBinaryPath(name: string): Promise<string> {
|
||||
let cmd = process.platform === 'win32' ? `${name}.exe` : name
|
||||
const binariesDir = path.join(os.homedir(), '.cherrystudio', 'bin')
|
||||
let cmd = path.join(binariesDir, name)
|
||||
cmd = process.platform === 'win32' ? `${cmd}.exe` : cmd
|
||||
const binariesDirExists = await fs.existsSync(binariesDir)
|
||||
cmd = binariesDirExists ? path.join(binariesDir, name) : name
|
||||
return cmd
|
||||
}
|
||||
|
||||
export function isBinaryExists(name: string): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
const cmd = getBinaryPath(name)
|
||||
resolve(fs.existsSync(cmd))
|
||||
})
|
||||
export async function isBinaryExists(name: string): Promise<boolean> {
|
||||
const cmd = await getBinaryPath(name)
|
||||
return await fs.existsSync(cmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user