diff options
Diffstat (limited to 'editors/code/src/util.ts')
-rw-r--r-- | editors/code/src/util.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 53492a445..56e0e439e 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as lc from "vscode-languageclient/node"; | 1 | import * as lc from "vscode-languageclient/node"; |
2 | import * as vscode from "vscode"; | 2 | import * as vscode from "vscode"; |
3 | import { strict as nativeAssert } from "assert"; | 3 | import { strict as nativeAssert } from "assert"; |
4 | import { spawnSync } from "child_process"; | 4 | import { exec, ExecOptions, spawnSync } from "child_process"; |
5 | import { inspect } from "util"; | 5 | import { inspect } from "util"; |
6 | 6 | ||
7 | export function assert(condition: boolean, explanation: string): asserts condition { | 7 | export function assert(condition: boolean, explanation: string): asserts condition { |
@@ -141,3 +141,22 @@ export function memoize<Ret, TThis, Param extends string>(func: (this: TThis, ar | |||
141 | return result; | 141 | return result; |
142 | }; | 142 | }; |
143 | } | 143 | } |
144 | |||
145 | /** Awaitable wrapper around `child_process.exec` */ | ||
146 | export function execute(command: string, options: ExecOptions): Promise<string> { | ||
147 | return new Promise((resolve, reject) => { | ||
148 | exec(command, options, (err, stdout, stderr) => { | ||
149 | if (err) { | ||
150 | reject(err); | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | if (stderr) { | ||
155 | reject(new Error(stderr)); | ||
156 | return; | ||
157 | } | ||
158 | |||
159 | resolve(stdout.trimEnd()); | ||
160 | }); | ||
161 | }); | ||
162 | } | ||