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