microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/common/reactNativeProjectHelper.ts
26lines · 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 | |
| 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 => { |
| 21 | return !!(dependencies && dependencies["react-native"]); |
| 22 | }).catch((err: Error) => { |
| 23 | return Q.resolve(false); |
| 24 | }); |
| 25 | } |
| 26 | } |
| 27 | |