microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/common/reactNativeProjectHelper.ts
26lines · 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 | | |
| 6 | export class ReactNativeProjectHelper { | |
| 7 | private workspaceRoot: string; | |
| 8 | | |
| 9 | constructor(workspaceRoot: string) { | |
| 10 | this.workspaceRoot = workspaceRoot; | |
| 11 | } | |
| 12 | | |
| 13 | /** | |
| 14 | * Ensures that we are in a React Native project and then executes the operation | |
| 15 | * Otherwise, displays an error message banner | |
| 16 | * {operation} - a function that performs the expected operation | |
| 17 | */ | |
| 18 | public isReactNativeProject(): Q.Promise<boolean> { | |
| 19 | let currentPackage = new Package(this.workspaceRoot); | |
| 20 | return currentPackage.dependencies().then(dependencies => { | |
0633e07bMeena Kunnathur Balakrishnan10 years ago | 21 | return !!(dependencies && dependencies["react-native"]); |
fb8f49fbMeena Kunnathur Balakrishnan10 years ago | 22 | }).catch((err: Error) => { |
3d97c2a3Meena Kunnathur Balakrishnan10 years ago | 23 | return Q.resolve(false); |
| 24 | }); | |
| 25 | } | |
| 26 | } |