microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/services/validationService/checks/emulator.ts
65lines · modeblame
c7856462Heniker4 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 | | |
09f6024fHeniker4 years ago | 4 | import * as nls from "vscode-nls"; |
c7856462Heniker4 years ago | 5 | import { |
948a0d44Heniker4 years ago | 6 | basicCheck, |
c7856462Heniker4 years ago | 7 | createNotFoundMessage, |
| 8 | createVersionErrorMessage, | |
948a0d44Heniker4 years ago | 9 | parseVersion, |
c7856462Heniker4 years ago | 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 = "Android Emulator"; | |
| 21 | | |
| 22 | async function test(): Promise<ValidationResultT> { | |
948a0d44Heniker4 years ago | 23 | const result = await basicCheck({ |
| 24 | command: "emulator", | |
| 25 | versionRange: "30.0.0", | |
| 26 | getVersion: parseVersion.bind(null, "emulator -version", /version (.*?)( |$)/gi), | |
| 27 | }); | |
| 28 | | |
| 29 | if (!result.exists) { | |
c7856462Heniker4 years ago | 30 | return { |
| 31 | status: "failure", | |
| 32 | comment: createNotFoundMessage(label), | |
| 33 | }; | |
| 34 | } | |
| 35 | | |
948a0d44Heniker4 years ago | 36 | if (result.versionCompare === undefined) { |
c7856462Heniker4 years ago | 37 | return { |
| 38 | status: "failure", | |
| 39 | comment: createVersionErrorMessage(label), | |
| 40 | }; | |
| 41 | } | |
| 42 | | |
948a0d44Heniker4 years ago | 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 | } | |
c7856462Heniker4 years ago | 51 | |
948a0d44Heniker4 years ago | 52 | return { status: "success" }; |
c7856462Heniker4 years ago | 53 | } |
| 54 | | |
| 55 | const main: IValidation = { | |
| 56 | label, | |
| 57 | description: toLocale( | |
| 58 | "EmulatorCheckDescription", | |
| 59 | "Required for working with Android emulators", | |
| 60 | ), | |
| 61 | category: ValidationCategoryE.Android, | |
| 62 | exec: test, | |
| 63 | }; | |
| 64 | | |
| 65 | export default main; |