@codacy/codacy-mcp
Version:
Codacy MCP server
32 lines (31 loc) • 1.23 kB
JavaScript
import { MacCodacyCli } from './MacCodacyCli.js';
export class WinWSLCodacyCli extends MacCodacyCli {
constructor(rootPath, provider, organization, repository) {
const winRootPath = rootPath.startsWith('/mnt/')
? WinWSLCodacyCli.fromWSLPath(rootPath)
: rootPath;
super(winRootPath, provider, organization, repository);
}
static toWSLPath(path) {
// Convert Windows path to WSL path
// Example: C:\Users\user\project -> /mnt/c/Users/user/project
const wslPath = path.replace(/\\/g, '/').replace(/^([a-zA-Z]):/, '/mnt/$1');
return wslPath;
}
static fromWSLPath(path) {
// Convert WSL path to Windows path
// Example: /mnt/c/Users/user/project -> C:\Users\user\project
const windowsPath = path.replace(/^\/mnt\/([a-zA-Z])/, '$1:').replace(/\//g, '\\');
return windowsPath;
}
preparePathForExec(path) {
// Convert the path to WSL format
return WinWSLCodacyCli.toWSLPath(path);
}
async execAsync(command, args) {
return await super.execAsync(`wsl ${command}`, args);
}
getCliCommand() {
return WinWSLCodacyCli.toWSLPath(super.getCliCommand());
}
}