microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
45944d15dab31409096b01c12901cd2131a68bbb

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/reactNativeProjectHelper.ts

29lines · 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 {Log} from "./commands/log";
5import {Package} from "./node/package";
6import * as vscode from "vscode";
7
8export class ReactNativeProjectHelper {
9 private workspaceRoot: string;
10
11 constructor(workspaceRoot: string) {
12 this.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 */
20 public isReactNativeProject(): Q.Promise<boolean> {
21 let currentPackage = new Package(this.workspaceRoot);
22 return currentPackage.dependencies().then(dependencies => {
23 return dependencies && dependencies["react-native"];
24 }).catch((err: Error) => {
25 vscode.window.showErrorMessage("Attempting to read package.json file failed with error: " + err + ". Please make sure that the package.json file exists and is readable.");
26 return Q.resolve(false);
27 });
28 }
29}
30