|
1 | 1 | import * as vscode from "vscode"; |
2 | 2 | import * as child from "child_process"; |
3 | | -import {isWindows} from "./CheckOS"; |
| 3 | +import { isWindows } from "./CheckOS"; |
4 | 4 |
|
5 | | -export function RunSFDXCommand(commandString : string): Promise<any> { |
| 5 | +export function RunSFDXCommand(commandString: string): Promise<any> { |
6 | 6 |
|
7 | | - return new Promise<any>(resolve => { |
| 7 | + return new Promise<any>((resolve, reject) => { |
8 | 8 |
|
9 | | - if(isWindows()){ |
| 9 | + if (isWindows()) { |
10 | 10 | commandString = 'cmd /c ' + commandString; |
11 | 11 | } |
12 | 12 |
|
13 | 13 | let workspacePath = vscode.workspace.workspaceFolders; |
14 | | - let foo: child.ChildProcess = child.exec(commandString,{ |
| 14 | + let foo: child.ChildProcess = child.exec(commandString, { |
15 | 15 | maxBuffer: 1024 * 1024 * 6, |
16 | | - cwd: workspacePath?workspacePath[0].uri.fsPath:"" |
| 16 | + cwd: workspacePath ? workspacePath[0].uri.fsPath : "" |
17 | 17 | }); |
18 | 18 |
|
19 | | - let bufferOutData=''; |
20 | | - foo.stdout.on("data",(dataArg : any)=> { |
21 | | - bufferOutData+=dataArg; |
| 19 | + let bufferOutData = ''; |
| 20 | + foo.stdout.on("data", (dataArg: any) => { |
| 21 | + bufferOutData += dataArg; |
22 | 22 | }); |
23 | 23 |
|
24 | | - foo.stderr.on("data",(data : any)=> { |
| 24 | + foo.stderr.on("data", (data: any) => { |
25 | 25 | vscode.window.showErrorMessage(data); |
26 | | - resolve(); |
27 | 26 | }); |
28 | 27 |
|
29 | | - foo.stdin.on("data",(data : any)=> { |
30 | | - vscode.window.showErrorMessage(data); |
31 | | - resolve(); |
32 | | - }); |
33 | | - |
34 | | - foo.on('exit',(code,signal)=>{ |
35 | | - let data = JSON.parse(bufferOutData); |
36 | | - resolve(data); |
| 28 | + foo.on('exit', (code, signal) => { |
| 29 | + if (code === 0) { |
| 30 | + let data = JSON.parse(bufferOutData); |
| 31 | + resolve(data); |
| 32 | + } else { |
| 33 | + reject(new Error(`Command execution failed with code ${code}.`)); |
| 34 | + } |
37 | 35 | }); |
38 | | - |
39 | | - |
40 | 36 | }); |
41 | 37 | } |
0 commit comments