diff --git a/bin/darwin/arm64/dtm b/bin/darwin/arm64/dtm new file mode 100755 index 0000000..3eba91a Binary files /dev/null and b/bin/darwin/arm64/dtm differ diff --git a/package.json b/package.json index 72ca370..a8e9cf0 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "main": "./dist/extension.js", "files": [ "dist/*", + "bin/*", "assets/*", "LICENSE", "README.md" diff --git a/src/toolwrapper/dtm.ts b/src/toolwrapper/dtm.ts index 2b18b30..508ece5 100644 --- a/src/toolwrapper/dtm.ts +++ b/src/toolwrapper/dtm.ts @@ -1,5 +1,6 @@ import { spawn } from "child_process"; import * as vscode from 'vscode'; +import * as path from 'path'; import { logger } from "../util/logger"; @@ -11,9 +12,28 @@ interface DtmResponse { class DtmWrapper { private workspaceDir: string; + private binaryPath: string; constructor() { this.workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath || '.'; + + let binaryName: string; + switch (process.platform) { + case 'win32': + binaryName = 'dtm.exe'; + break; + case 'darwin': + binaryName = 'dtm'; + break; + case 'linux': + binaryName = 'dtm'; + break; + default: + vscode.window.showErrorMessage(`Unsupported platform: ${process.platform}`); + return; + } + + this.binaryPath = path.join(__dirname, '..', 'bin', process.platform, process.arch, binaryName); } private async runCommand(command: string, args: string[]): Promise { @@ -49,16 +69,16 @@ class DtmWrapper { } async scaffold(directoryTree: string): Promise { - return await this.runCommand('dtm', ['scaffold', directoryTree, '-o', 'json']); + return await this.runCommand(this.binaryPath, ['scaffold', directoryTree, '-o', 'json']); } async patch(patchFilePath: string): Promise { - return await this.runCommand('dtm', ['patch', patchFilePath, '-o', 'json']); + return await this.runCommand(this.binaryPath, ['patch', patchFilePath, '-o', 'json']); } async commit(commitMsg: string): Promise { try { - return await this.runCommand('dtm', ['commit', '-m', commitMsg, '-o', 'json']); + return await this.runCommand(this.binaryPath, ['commit', '-m', commitMsg, '-o', 'json']); } catch (error) { // 处理 runCommand 中的 reject 错误 logger.channel()?.error(`Error in commit: ${error}`);