microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
637e599d4b707fa92106bcd3fbfc075bf8e4625c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/reactNativeProjectHelper.ts

29lines · modeblame

3d97c2a3Meena 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
fb8f49fbMeena Kunnathur Balakrishnan10 years ago4import {Log} from "./commands/log";
3d97c2a3Meena Kunnathur Balakrishnan10 years ago5import {Package} from "./node/package";
a43d1bd5Meena Kunnathur Balakrishnan10 years ago6import * as vscode from "vscode";
3d97c2a3Meena Kunnathur Balakrishnan10 years ago7
8export class ReactNativeProjectHelper {
9private workspaceRoot: string;
10
11constructor(workspaceRoot: string) {
12this.workspaceRoot = workspaceRoot;
13}
14
15/**
16* Ensures that we are in a React Native project and then executes the operation
17* Otherwise, displays an error message banner
18* {operation} - a function that performs the expected operation
19*/
20public isReactNativeProject(): Q.Promise<boolean> {
21let currentPackage = new Package(this.workspaceRoot);
22return currentPackage.dependencies().then(dependencies => {
23return dependencies && dependencies["react-native"];
fb8f49fbMeena Kunnathur Balakrishnan10 years ago24}).catch((err: Error) => {
a43d1bd5Meena Kunnathur Balakrishnan10 years ago25vscode.window.showErrorMessage("Attempting to read package.json file failed with error: " + err + ". Please make sure that the package.json file exists and is readable.");
3d97c2a3Meena Kunnathur Balakrishnan10 years ago26return Q.resolve(false);
27});
28}
29}