microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e54a23cec8f8d2b2adefd558262187fc8444f2c1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/commands/commandExecutor.ts

68lines · modeblame

a31b007cunknown10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
2e15926eMeena Kunnathur Balakrishnan10 years ago4import {ChildProcess} from "child_process";
3fb37ad5unknown10 years ago5import {Log} from "./log";
5e5bf86eMeena Kunnathur Balakrishnan10 years ago6import {Node} from "../node/node";
7import {OutputChannel} from "vscode";
2e15926eMeena Kunnathur Balakrishnan10 years ago8import * as Q from "q";
3fb37ad5unknown10 years ago9
10interface EnvironmentOptions {
11REACT_DEBUGGER?: string;
12}
13
14interface Options {
15env?: EnvironmentOptions;
16}
17
18export class CommandExecutor {
19private currentWorkingDirectory: string;
20
110558c0Jimmy Thomson10 years ago21constructor(currentWorkingDirectory?: string) {
3fb37ad5unknown10 years ago22this.currentWorkingDirectory = currentWorkingDirectory;
23}
24
fb2bae06Daniel10 years ago25public execute(command: string, options: Options = {}): Q.Promise<void> {
bedf110funknown10 years ago26Log.commandStarted(command);
27return new Node.ChildProcess().execToString(command, { cwd: this.currentWorkingDirectory, env: options.env })
3fb37ad5unknown10 years ago28.then(stdout => {
bedf110funknown10 years ago29Log.logMessage(stdout);
30Log.commandEnded(command);
3fb37ad5unknown10 years ago31},
bedf110funknown10 years ago32reason => Log.commandFailed(command, reason));
3fb37ad5unknown10 years ago33}
34
2e15926eMeena Kunnathur Balakrishnan10 years ago35public spawn(command: string, args: string[], options: Options = {}, outputChannel?: OutputChannel): Q.Promise<ChildProcess> {
08e81a53unknown10 years ago36let spawnOptions = Object.assign({}, { cwd: this.currentWorkingDirectory }, options);
3fb37ad5unknown10 years ago37let commandWithArgs = command + " " + args.join(" ");
38
3194e9afMeena Kunnathur Balakrishnan10 years ago39Log.commandStarted(commandWithArgs, outputChannel);
3fb37ad5unknown10 years ago40let result = new Node.ChildProcess().spawn(command, args, spawnOptions);
41
42result.stderr.on("data", (data: Buffer) => {
5e5bf86eMeena Kunnathur Balakrishnan10 years ago43if (outputChannel) {
44outputChannel.append(data.toString());
45} else {
46process.stderr.write(data);
47}
3fb37ad5unknown10 years ago48});
49
50result.stdout.on("data", (data: Buffer) => {
5e5bf86eMeena Kunnathur Balakrishnan10 years ago51if (outputChannel) {
52outputChannel.append(data.toString());
53} else {
54process.stdout.write(data);
55}
3fb37ad5unknown10 years ago56});
57
2e15926eMeena Kunnathur Balakrishnan10 years ago58result.outcome.then(() => {
3194e9afMeena Kunnathur Balakrishnan10 years ago59Log.commandEnded(commandWithArgs, outputChannel);
bedf110funknown10 years ago60},
2e15926eMeena Kunnathur Balakrishnan10 years ago61(reason) => {
3194e9afMeena Kunnathur Balakrishnan10 years ago62Log.commandFailed(commandWithArgs, reason, outputChannel);
2e15926eMeena Kunnathur Balakrishnan10 years ago63});
64
65return Q.resolve(result.spawnedProcess);
3fb37ad5unknown10 years ago66}
67
68}