microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/macos/macOSPlatform.ts
72lines · 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 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 { |
| 16 | |
| 17 | private static SUCCESS_PATTERNS = [ |
| 18 | "Launching app", |
| 19 | ]; |
| 20 | private static FAILURE_PATTERNS: PatternToFailure[] = [ |
| 21 | { |
| 22 | pattern: "Unrecognized command 'run-macos'", |
| 23 | errorCode: InternalErrorCode.ReactNativemacOSIsNotInstalled, |
| 24 | }, |
| 25 | ]; |
| 26 | |
| 27 | constructor(protected runOptions: ImacOSRunOptions, platformDeps: MobilePlatformDeps = {}) { |
| 28 | super(runOptions, platformDeps); |
| 29 | } |
| 30 | |
| 31 | public runApp(): Promise<void> { |
| 32 | let extProps = { |
| 33 | platform: { |
| 34 | value: PlatformType.macOS, |
| 35 | isPii: false, |
| 36 | }, |
| 37 | }; |
| 38 | |
| 39 | extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(this.runOptions, this.runOptions.reactNativeVersions, extProps); |
| 40 | |
| 41 | return TelemetryHelper.generate("MacOSPlatform.runApp", extProps, () => { |
| 42 | const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile); |
| 43 | |
| 44 | if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, MacOSPlatform.NO_PACKAGER_VERSION)) { |
| 45 | this.runArguments.push("--no-packager"); |
| 46 | } |
| 47 | |
| 48 | const runmacOSSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env }); |
| 49 | return new OutputVerifier(() => Promise.resolve(MacOSPlatform.SUCCESS_PATTERNS), () => Promise.resolve(MacOSPlatform.FAILURE_PATTERNS), this.platformName) |
| 50 | .process(runmacOSSpawn); |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | public prewarmBundleCache(): Promise<void> { |
| 55 | return this.packager.prewarmBundleCache(PlatformType.macOS); |
| 56 | } |
| 57 | |
| 58 | public getRunArguments(): string[] { |
| 59 | let runArguments: string[] = []; |
| 60 | |
| 61 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { |
| 62 | runArguments.push(...this.runOptions.runArguments); |
| 63 | } else { |
| 64 | let target = this.runOptions.target === MacOSPlatform.simulatorString ? "" : this.runOptions.target; |
| 65 | if (target) { |
| 66 | runArguments.push(`--${target}`); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return runArguments; |
| 71 | } |
| 72 | } |
| 73 | |