microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/services/validationService/checks/adb.ts
75lines · 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 * as nls from "vscode-nls"; |
| 5 | import { |
| 6 | basicCheck, |
| 7 | createNotFoundMessage, |
| 8 | createVersionErrorMessage, |
| 9 | parseVersion, |
| 10 | } from "../util"; |
| 11 | import { ValidationCategoryE, IValidation, ValidationResultT } from "./types"; |
| 12 | |
| 13 | nls.config({ |
| 14 | messageFormat: nls.MessageFormat.bundle, |
| 15 | bundleFormat: nls.BundleFormat.standalone, |
| 16 | })(); |
| 17 | |
| 18 | const toLocale = nls.loadMessageBundle(); |
| 19 | |
| 20 | const label = "ADB"; |
| 21 | |
| 22 | async function test(): Promise<ValidationResultT> { |
| 23 | const result = await basicCheck({ |
| 24 | command: "adb", |
| 25 | versionRange: "30.0.0", |
| 26 | getVersion: parseVersion.bind(null, "adb --version", /Version \d+\.\d+\.\d+/), |
| 27 | }); |
| 28 | |
| 29 | if (!result.exists) { |
| 30 | return { |
| 31 | status: "failure", |
| 32 | comment: createNotFoundMessage(label), |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | if (result.versionCompare === undefined) { |
| 37 | return { |
| 38 | status: "failure", |
| 39 | comment: createVersionErrorMessage(label), |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | if (result.versionCompare === -1) { |
| 44 | return { |
| 45 | status: "partial-success", |
| 46 | comment: |
| 47 | "Detected version is older than 30.0.0. " + |
| 48 | "Please update SDK tools in case of errors", |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | return { status: "success" }; |
| 53 | } |
| 54 | |
| 55 | const adbAndroid: IValidation = { |
| 56 | label, |
| 57 | description: toLocale( |
| 58 | "AdbCheckAndroidDescription", |
| 59 | "Required for app installation. Minimal version is 12", |
| 60 | ), |
| 61 | category: ValidationCategoryE.Android, |
| 62 | exec: test, |
| 63 | }; |
| 64 | |
| 65 | const adbExpo: IValidation = { |
| 66 | label, |
| 67 | description: toLocale( |
| 68 | "AdbCheckExpoDescription", |
| 69 | "Required for correct extension integration with Expo", |
| 70 | ), |
| 71 | category: ValidationCategoryE.Expo, |
| 72 | exec: test, |
| 73 | }; |
| 74 | |
| 75 | export { adbAndroid, adbExpo }; |
| 76 | |