microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/utils/reactNativeProjectHelper.ts
28lines · 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 | | |
| 4 | import {Package} from "./node/package"; | |
| 5 | import * as path from "path"; | |
| 6 | import * as vscode from "vscode"; | |
| 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"]; | |
| 24 | }).catch(() => { | |
| 25 | return Q.resolve(false); | |
| 26 | }); | |
| 27 | } | |
| 28 | } |