Merge pull request #36 from covespace/package_dtm

Package dtm
This commit is contained in:
boob.yang 2023-05-09 18:23:26 +08:00 committed by GitHub
commit f799de7ad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

BIN
bin/darwin/arm64/dtm Executable file

Binary file not shown.

View File

@ -13,6 +13,7 @@
"main": "./dist/extension.js",
"files": [
"dist/*",
"bin/*",
"assets/*",
"LICENSE",
"README.md"

View File

@ -1,5 +1,7 @@
import { spawn } from "child_process";
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { logger } from "../util/logger";
@ -11,9 +13,33 @@ interface DtmResponse {
class DtmWrapper {
private workspaceDir: string;
private binaryPath: string;
constructor() {
this.workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath || '.';
this.binaryPath = 'dtm';
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);
if (!fs.existsSync(this.binaryPath)) {
logger.channel()?.error(`Binary not found: ${this.binaryPath}`);
logger.channel()?.show();
}
}
private async runCommand(command: string, args: string[]): Promise<DtmResponse> {
@ -49,16 +75,16 @@ class DtmWrapper {
}
async scaffold(directoryTree: string): Promise<DtmResponse> {
return await this.runCommand('dtm', ['scaffold', directoryTree, '-o', 'json']);
return await this.runCommand(this.binaryPath, ['scaffold', directoryTree, '-o', 'json']);
}
async patch(patchFilePath: string): Promise<DtmResponse> {
return await this.runCommand('dtm', ['patch', patchFilePath, '-o', 'json']);
return await this.runCommand(this.binaryPath, ['patch', patchFilePath, '-o', 'json']);
}
async commit(commitMsg: string): Promise<DtmResponse> {
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}`);