microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/windowsPlatform.ts
81lines · 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 Q from "q"; |
| 5 | import * as semver from "semver"; |
| 6 | |
| 7 | import {GeneralMobilePlatform, MobilePlatformDeps} from "../generalMobilePlatform"; |
| 8 | import {IWindowsRunOptions} from "../launchArgs"; |
| 9 | import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier"; |
| 10 | import {TelemetryHelper} from "../../common/telemetryHelper"; |
| 11 | import {CommandExecutor} from "../../common/commandExecutor"; |
| 12 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; |
| 13 | |
| 14 | /** |
| 15 | * Windows specific platform implementation for debugging RN applications. |
| 16 | */ |
| 17 | export class WindowsPlatform extends GeneralMobilePlatform { |
| 18 | protected static NO_PACKAGER_VERSION = "0.53.0"; |
| 19 | |
| 20 | private static SUCCESS_PATTERNS = [ |
| 21 | "Installing new version of the app", |
| 22 | "Starting the app", |
| 23 | ]; |
| 24 | private static FAILURE_PATTERNS: PatternToFailure[] = [ |
| 25 | { |
| 26 | pattern: "Unrecognized command 'run-windows'", |
| 27 | errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled, |
| 28 | }, |
| 29 | ]; |
| 30 | |
| 31 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { |
| 32 | super(runOptions, platformDeps); |
| 33 | } |
| 34 | |
| 35 | public runApp(enableDebug: boolean = true): Q.Promise<void> { |
| 36 | let extProps = { |
| 37 | platform: { |
| 38 | value: "windows", |
| 39 | isPii: false, |
| 40 | }, |
| 41 | }; |
| 42 | |
| 43 | extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeVersion, "reactNativeVersion", extProps); |
| 44 | extProps = TelemetryHelper.addPropertyToTelemetryProperties(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "reactNativeWindowsVersion", extProps); |
| 45 | |
| 46 | return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => { |
| 47 | const env = this.getEnvArgument(); |
| 48 | |
| 49 | if (enableDebug) { |
| 50 | this.runArguments.push("--proxy"); |
| 51 | } |
| 52 | |
| 53 | if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, WindowsPlatform.NO_PACKAGER_VERSION)) { |
| 54 | this.runArguments.push("--no-packager"); |
| 55 | } |
| 56 | |
| 57 | const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env}); |
| 58 | return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), this.platformName) |
| 59 | .process(runWindowsSpawn); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | public prewarmBundleCache(): Q.Promise<void> { |
| 64 | return this.packager.prewarmBundleCache("windows"); |
| 65 | } |
| 66 | |
| 67 | public getRunArguments(): string[] { |
| 68 | let runArguments: string[] = []; |
| 69 | |
| 70 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { |
| 71 | runArguments.push(...this.runOptions.runArguments); |
| 72 | } else { |
| 73 | let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target; |
| 74 | if (target) { |
| 75 | runArguments.push(`--${target}`); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return runArguments; |
| 80 | } |
| 81 | } |