microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a31b007c2af965bbb579b8e9ae0054a403891c95

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/commands/commandExecutor.ts

58lines · 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 * as _ from "lodash";
7import {Log} from "./log";
8
9interface EnvironmentOptions {
10 REACT_DEBUGGER?: string;
11}
12
13interface Options {
14 env?: EnvironmentOptions;
15}
16
17export class CommandExecutor {
18 private currentWorkingDirectory: string;
19
20 constructor(currentWorkingDirectory: string) {
21 this.currentWorkingDirectory = currentWorkingDirectory;
22 }
23
24 public execute(subject: string, command: string, options: Options = {}): Q.Promise<void> {
25 // let outputChannel = vscode.window.createOutputChannel("React Native: " + subject);
26 Log.commandStarted(command);
27 // outputChannel.show();
28 // let process = child_process.exec(command, {cwd: vscode.workspace.rootPath});
29 return new Node.ChildProcess().execToString(command, { cwd: this.currentWorkingDirectory, env: options.env })
30 .then(stdout => {
31 Log.logMessage(stdout);
32 Log.commandEnded(command);
33 },
34 reason => Log.commandFailed(command, reason));
35 }
36
37 public spawn(subject: string, command: string, args: string[], options: Options = {}): Q.Promise<void> {
38 let spawnOptions = _.extend({}, { cwd: this.currentWorkingDirectory }, options);
39 let commandWithArgs = command + " " + args.join(" ");
40
41 Log.commandStarted(commandWithArgs);
42 let result = new Node.ChildProcess().spawn(command, args, spawnOptions);
43
44 result.stderr.on("data", (data: Buffer) => {
45 process.stdout.write(data);
46 });
47
48 result.stdout.on("data", (data: Buffer) => {
49 process.stdout.write(data);
50 });
51
52 return result.outcome.then(() => {
53 Log.commandEnded(commandWithArgs);
54 },
55 reason => Log.commandFailed(commandWithArgs, reason));
56 }
57
58}
59