microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.1.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/reactNativeProjectHelper.ts

45lines · modeblame

3d97c2a3Meena Kunnathur Balakrishnan10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
bd539474digeff10 years ago4import * as Q from "q";
3d97c2a3Meena Kunnathur Balakrishnan10 years ago5import {Package} from "./node/package";
6
7export class ReactNativeProjectHelper {
8private workspaceRoot: string;
da86e6ffdigeff10 years ago9private static REACT_NATIVE_NPM_LIB_NAME = "react-native";
3d97c2a3Meena Kunnathur Balakrishnan10 years ago10
11constructor(workspaceRoot: string) {
12this.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*/
20public isReactNativeProject(): Q.Promise<boolean> {
21let currentPackage = new Package(this.workspaceRoot);
22return currentPackage.dependencies().then(dependencies => {
0633e07bMeena Kunnathur Balakrishnan10 years ago23return !!(dependencies && dependencies["react-native"]);
fb8f49fbMeena Kunnathur Balakrishnan10 years ago24}).catch((err: Error) => {
3d97c2a3Meena Kunnathur Balakrishnan10 years ago25return Q.resolve(false);
26});
27}
bd539474digeff10 years ago28
29public validateReactNativeVersion(): Q.Promise<void> {
da86e6ffdigeff10 years ago30return new Package(this.workspaceRoot).dependencyPackage(ReactNativeProjectHelper.REACT_NATIVE_NPM_LIB_NAME).version().then(version => {
bd539474digeff10 years ago31// TODO-V1: Use semver instead of all this logic
32const components = version.split(".");
33if (components.length >= 2) { // Even though react-native versions have 3 components, we only care about the first 2
4a25dae0digeff10 years ago34let minorVersion = parseInt(components[1], 10);
35if (components[0] !== "0" || minorVersion >= 19) {
bd539474digeff10 years ago36return Q.resolve<void>(void 0);
4a25dae0digeff10 years ago37} else if (!(<any>Number).isNaN(minorVersion)) {
38return Q.reject<void>(`Project version = ${version}`);
39} // else minor version is nan. Continue to return parse error
bd539474digeff10 years ago40}
41
4a25dae0digeff10 years ago42return Q.reject<void>(`Unable to read version = ${version}`);
bd539474digeff10 years ago43});
44}
3d97c2a3Meena Kunnathur Balakrishnan10 years ago45}