microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f2c5a59cb2776a7922f61302874b65e57aef42cd

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/reactNativeCommandExecutor.ts

81lines · modeblame

bef522ffMeena Kunnathur Balakrishnan10 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
4import {CommandExecutor} from "./commands/commandExecutor";
ec6e115dMeena Kunnathur Balakrishnan10 years ago5import {Log} from "./commands/log";
bef522ffMeena Kunnathur Balakrishnan10 years ago6import {Packager} from "./../debugger/packager";
3d97c2a3Meena Kunnathur Balakrishnan10 years ago7import {ReactNativeProjectHelper} from "./reactNativeProjectHelper";
3194e9afMeena Kunnathur Balakrishnan10 years ago8import * as vscode from "vscode";
bef522ffMeena Kunnathur Balakrishnan10 years ago9
10export class ReactNativeCommandExecutor {
11private reactNativePackager: Packager;
12private workspaceRoot: string;
13
14constructor(workspaceRoot: string) {
15this.workspaceRoot = workspaceRoot;
f8d32439dlebu10 years ago16this.reactNativePackager = new Packager(workspaceRoot);
bef522ffMeena Kunnathur Balakrishnan10 years ago17}
18
0904a0d7Meena Kunnathur Balakrishnan10 years ago19/**
3194e9afMeena Kunnathur Balakrishnan10 years ago20* Ensures that we are in a React Native project and then executes the operation
21* Otherwise, displays an error message banner
22* {operation} - a function that performs the expected operation
0904a0d7Meena Kunnathur Balakrishnan10 years ago23*/
3194e9afMeena Kunnathur Balakrishnan10 years ago24public executeCommandInContext(operation: () => void): void {
3d97c2a3Meena Kunnathur Balakrishnan10 years ago25let reactNativeProjectHelper = new ReactNativeProjectHelper(vscode.workspace.rootPath);
26reactNativeProjectHelper.isReactNativeProject().done(isRNProject => {
3194e9afMeena Kunnathur Balakrishnan10 years ago27if (isRNProject) {
28operation();
29} else {
30vscode.window.showErrorMessage("Current workspace is not a React Native project.");
31}
32});
bef522ffMeena Kunnathur Balakrishnan10 years ago33}
34
0904a0d7Meena Kunnathur Balakrishnan10 years ago35/**
36* Starts the React Native packager
37*/
bef522ffMeena Kunnathur Balakrishnan10 years ago38public startPackager(): void {
ec6e115dMeena Kunnathur Balakrishnan10 years ago39this.reactNativePackager.start(vscode.window.createOutputChannel("React-Native"))
f8d32439dlebu10 years ago40.done();
bef522ffMeena Kunnathur Balakrishnan10 years ago41}
42
0904a0d7Meena Kunnathur Balakrishnan10 years ago43/**
44* Kills the React Native packager invoked by the extension's packager
45*/
bef522ffMeena Kunnathur Balakrishnan10 years ago46public stopPackager(): void {
3194e9afMeena Kunnathur Balakrishnan10 years ago47this.reactNativePackager.stop(vscode.window.createOutputChannel("React-Native"));
48}
49
50/**
51* Executes the 'react-native run-android' command
52*/
53public runAndroid(): void {
3cf70711Meena Kunnathur Balakrishnan10 years ago54this.executeReactNativeRunCommand("run-android");
3194e9afMeena Kunnathur Balakrishnan10 years ago55}
56
57/**
58* Executes the 'react-native run-ios' command
59*/
60public runIos(): void {
3cf70711Meena Kunnathur Balakrishnan10 years ago61this.executeReactNativeRunCommand("run-ios");
3194e9afMeena Kunnathur Balakrishnan10 years ago62}
63
fb8f49fbMeena Kunnathur Balakrishnan10 years ago64/**
3cf70711Meena Kunnathur Balakrishnan10 years ago65* Executes a react-native command passed after starting the packager
fb8f49fbMeena Kunnathur Balakrishnan10 years ago66* {command} The command to be executed
67* {args} The arguments to be passed to the command
68*/
3cf70711Meena Kunnathur Balakrishnan10 years ago69public executeReactNativeRunCommand(command: string, args?: string[]): Q.Promise<void> {
ec6e115dMeena Kunnathur Balakrishnan10 years ago70// Start the packager before executing the React-Native command
71let outputChannel = vscode.window.createOutputChannel("React-Native");
72Log.appendStringToOutputChannel("Attempting to start the React Native packager", outputChannel);
73
74return this.reactNativePackager.start(outputChannel)
f8d32439dlebu10 years ago75.then(() => {
76return new CommandExecutor(this.workspaceRoot).spawnReactCommand(command, args, undefined, outputChannel);
77}).then(() => {
78return Q.resolve<void>(void 0);
79});
3194e9afMeena Kunnathur Balakrishnan10 years ago80}
bef522ffMeena Kunnathur Balakrishnan10 years ago81}