microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bedf110fbb4cf82fb995f4cf2770e8339d5adbea

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/commands/commandExecutor.ts

55lines · modecode

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