microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/utils/reactNativeProjectHelper.ts
29lines · modeblame
3d97c2a3Meena Kunnathur Balakrishnan10 years ago | 1 | // 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 ago | 4 | import {Log} from "./commands/log"; |
3d97c2a3Meena Kunnathur Balakrishnan10 years ago | 5 | import {Package} from "./node/package"; |
a43d1bd5Meena Kunnathur Balakrishnan10 years ago | 6 | import * as vscode from "vscode"; |
3d97c2a3Meena Kunnathur Balakrishnan10 years ago | 7 | |
| 8 | export 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"]; | |
fb8f49fbMeena Kunnathur Balakrishnan10 years ago | 24 | }).catch((err: Error) => { |
a43d1bd5Meena Kunnathur Balakrishnan10 years ago | 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."); |
3d97c2a3Meena Kunnathur Balakrishnan10 years ago | 26 | return Q.resolve(false); |
| 27 | }); | |
| 28 | } | |
| 29 | } |