microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
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 | |
| 4 | import {Log} from "./commands/log"; |
| 5 | import {Package} from "./node/package"; |
| 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((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 | |