microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4e7a6f0ea8877d0ec68aa871b8597e21af9cd6aa

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/utils/commands/commandExecutor.ts

54lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as Q from "q";
5import {Node} from "../node/node";
6import {Log} from "./log";
7
8interface EnvironmentOptions {
9 REACT_DEBUGGER?: string;
10}
11
12interface Options {
13 env?: EnvironmentOptions;
14}
15
16export class CommandExecutor {
17 private currentWorkingDirectory: string;
18
19 constructor(currentWorkingDirectory?: string) {
20 this.currentWorkingDirectory = currentWorkingDirectory;
21 }
22
23 public execute(command: string, options: Options = {}): Q.Promise<void> {
24 Log.commandStarted(command);
25 return new Node.ChildProcess().execToString(command, { cwd: this.currentWorkingDirectory, env: options.env })
26 .then(stdout => {
27 Log.logMessage(stdout);
28 Log.commandEnded(command);
29 },
30 reason => Log.commandFailed(command, reason));
31 }
32
33 public spawn(command: string, args: string[], options: Options = {}): Q.Promise<void> {
34 let spawnOptions = Object.assign({}, { cwd: this.currentWorkingDirectory }, options);
35 let commandWithArgs = command + " " + args.join(" ");
36
37 Log.commandStarted(commandWithArgs);
38 let result = new Node.ChildProcess().spawn(command, args, spawnOptions);
39
40 result.stderr.on("data", (data: Buffer) => {
41 process.stderr.write(data);
42 });
43
44 result.stdout.on("data", (data: Buffer) => {
45 process.stdout.write(data);
46 });
47
48 return result.outcome.then(() => {
49 Log.commandEnded(commandWithArgs);
50 },
51 reason => Log.commandFailed(commandWithArgs, reason));
52 }
53
54}
55