microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/macos/macOSPlatform.ts
94lines · modeblame
341dba36Yuri Skorokhodov5 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 | | |
| 4 | import * as semver from "semver"; | |
| 5 | import { GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform"; | |
| 6 | import { ImacOSRunOptions, PlatformType } from "../launchArgs"; | |
| 7 | import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier"; | |
| 8 | import { TelemetryHelper } from "../../common/telemetryHelper"; | |
| 9 | import { CommandExecutor } from "../../common/commandExecutor"; | |
| 10 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; | |
| 11 | | |
| 12 | /** | |
| 13 | * macOS specific platform implementation for debugging RN applications. | |
| 14 | */ | |
| 15 | export class MacOSPlatform extends GeneralMobilePlatform { | |
34472878RedMickey5 years ago | 16 | private static SUCCESS_PATTERNS = ["Launching app"]; |
341dba36Yuri Skorokhodov5 years ago | 17 | private static FAILURE_PATTERNS: PatternToFailure[] = [ |
| 18 | { | |
| 19 | pattern: "Unrecognized command 'run-macos'", | |
| 20 | errorCode: InternalErrorCode.ReactNativemacOSIsNotInstalled, | |
| 21 | }, | |
| 22 | ]; | |
| 23 | | |
| 24 | constructor(protected runOptions: ImacOSRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 25 | super(runOptions, platformDeps); | |
| 26 | } | |
| 27 | | |
| 28 | public runApp(): Promise<void> { | |
| 29 | let extProps = { | |
| 30 | platform: { | |
| 31 | value: PlatformType.macOS, | |
| 32 | isPii: false, | |
| 33 | }, | |
| 34 | }; | |
| 35 | | |
34472878RedMickey5 years ago | 36 | extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties( |
| 37 | this.runOptions, | |
| 38 | this.runOptions.reactNativeVersions, | |
| 39 | extProps, | |
| 40 | ); | |
341dba36Yuri Skorokhodov5 years ago | 41 | |
| 42 | return TelemetryHelper.generate("MacOSPlatform.runApp", extProps, () => { | |
34472878RedMickey5 years ago | 43 | const env = GeneralMobilePlatform.getEnvArgument( |
| 44 | process.env, | |
| 45 | this.runOptions.env, | |
| 46 | this.runOptions.envFile, | |
| 47 | ); | |
341dba36Yuri Skorokhodov5 years ago | 48 | |
34472878RedMickey5 years ago | 49 | if ( |
| 50 | !semver.valid( | |
| 51 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 52 | ) /*Custom RN implementations should support this flag*/ || | |
| 53 | semver.gte( | |
| 54 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 55 | MacOSPlatform.NO_PACKAGER_VERSION, | |
| 56 | ) | |
| 57 | ) { | |
341dba36Yuri Skorokhodov5 years ago | 58 | this.runArguments.push("--no-packager"); |
| 59 | } | |
| 60 | | |
34472878RedMickey5 years ago | 61 | const runmacOSSpawn = new CommandExecutor( |
| 62 | this.projectPath, | |
| 63 | this.logger, | |
| 64 | ).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env }); | |
| 65 | return new OutputVerifier( | |
| 66 | () => Promise.resolve(MacOSPlatform.SUCCESS_PATTERNS), | |
| 67 | () => Promise.resolve(MacOSPlatform.FAILURE_PATTERNS), | |
| 68 | this.platformName, | |
| 69 | ).process(runmacOSSpawn); | |
341dba36Yuri Skorokhodov5 years ago | 70 | }); |
| 71 | } | |
| 72 | | |
| 73 | public prewarmBundleCache(): Promise<void> { | |
| 74 | return this.packager.prewarmBundleCache(PlatformType.macOS); | |
| 75 | } | |
| 76 | | |
| 77 | public getRunArguments(): string[] { | |
| 78 | let runArguments: string[] = []; | |
| 79 | | |
| 80 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { | |
| 81 | runArguments.push(...this.runOptions.runArguments); | |
| 82 | } else { | |
34472878RedMickey5 years ago | 83 | let target = |
| 84 | this.runOptions.target === MacOSPlatform.simulatorString | |
| 85 | ? "" | |
| 86 | : this.runOptions.target; | |
341dba36Yuri Skorokhodov5 years ago | 87 | if (target) { |
| 88 | runArguments.push(`--${target}`); | |
| 89 | } | |
| 90 | } | |
| 91 | | |
| 92 | return runArguments; | |
| 93 | } | |
| 94 | } |