microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/windowsPlatform.ts
110lines · 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 | }, |
60ad4ec0JiglioNero5 years ago | 24 | { |
| 25 | pattern: /×.+$/gm, | |
| 26 | errorCode: InternalErrorCode.WinRunCommandFailed, | |
| 27 | }, | |
299883f9Artem Egorov8 years ago | 28 | ]; |
| 29 | | |
| 30 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 31 | super(runOptions, platformDeps); | |
| 32 | } | |
| 33 | | |
ce5e88eeYuri Skorokhodov5 years ago | 34 | public runApp(enableDebug: boolean = true): Promise<void> { |
ba953e9fRedMickey6 years ago | 35 | let extProps = { |
031832ffArtem Egorov7 years ago | 36 | platform: { |
259c018fYuri Skorokhodov5 years ago | 37 | value: PlatformType.Windows, |
031832ffArtem Egorov7 years ago | 38 | isPii: false, |
| 39 | }, | |
| 40 | }; | |
| 41 | | |
34472878RedMickey5 years ago | 42 | extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties( |
| 43 | this.runOptions, | |
| 44 | this.runOptions.reactNativeVersions, | |
| 45 | extProps, | |
| 46 | ); | |
ba953e9fRedMickey6 years ago | 47 | |
031832ffArtem Egorov7 years ago | 48 | return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => { |
34472878RedMickey5 years ago | 49 | const env = GeneralMobilePlatform.getEnvArgument( |
| 50 | process.env, | |
| 51 | this.runOptions.env, | |
| 52 | this.runOptions.envFile, | |
| 53 | ); | |
299883f9Artem Egorov8 years ago | 54 | |
34472878RedMickey5 years ago | 55 | if ( |
| 56 | semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0") | |
| 57 | ) { | |
4dfc9ffdRedMickey5 years ago | 58 | this.runArguments.push("--logging"); |
| 59 | if (enableDebug) { | |
c6027eadYuri Skorokhodov5 years ago | 60 | this.runArguments.push("--remote-debugging"); |
4dfc9ffdRedMickey5 years ago | 61 | } |
299883f9Artem Egorov8 years ago | 62 | } |
| 63 | | |
34472878RedMickey5 years ago | 64 | if ( |
| 65 | !semver.valid( | |
| 66 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 67 | ) /*Custom RN implementations should support this flag*/ || | |
| 68 | semver.gte( | |
| 69 | this.runOptions.reactNativeVersions.reactNativeVersion, | |
| 70 | WindowsPlatform.NO_PACKAGER_VERSION, | |
| 71 | ) | |
| 72 | ) { | |
7fa90b3bRedMickey6 years ago | 73 | this.runArguments.push("--no-packager"); |
| 74 | } | |
299883f9Artem Egorov8 years ago | 75 | |
34472878RedMickey5 years ago | 76 | const runWindowsSpawn = new CommandExecutor( |
4dfb1c4cetatanova5 years ago | 77 | this.runOptions.nodeModulesRoot, |
34472878RedMickey5 years ago | 78 | this.projectPath, |
| 79 | this.logger, | |
| 80 | ).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env }); | |
| 81 | return new OutputVerifier( | |
| 82 | () => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS), | |
| 83 | () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS), | |
| 84 | this.platformName, | |
| 85 | ).process(runWindowsSpawn); | |
299883f9Artem Egorov8 years ago | 86 | }); |
| 87 | } | |
| 88 | | |
ce5e88eeYuri Skorokhodov5 years ago | 89 | public prewarmBundleCache(): Promise<void> { |
259c018fYuri Skorokhodov5 years ago | 90 | return this.packager.prewarmBundleCache(PlatformType.Windows); |
299883f9Artem Egorov8 years ago | 91 | } |
| 92 | | |
cbc7ac5bArtem Egorov7 years ago | 93 | public getRunArguments(): string[] { |
299883f9Artem Egorov8 years ago | 94 | let runArguments: string[] = []; |
| 95 | | |
4dfc9ffdRedMickey5 years ago | 96 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { |
299883f9Artem Egorov8 years ago | 97 | runArguments.push(...this.runOptions.runArguments); |
| 98 | } else { | |
34472878RedMickey5 years ago | 99 | let target = |
| 100 | this.runOptions.target === WindowsPlatform.simulatorString | |
| 101 | ? "" | |
| 102 | : this.runOptions.target; | |
dd90a856Artem Egorov7 years ago | 103 | if (target) { |
| 104 | runArguments.push(`--${target}`); | |
299883f9Artem Egorov8 years ago | 105 | } |
| 106 | } | |
| 107 | | |
| 108 | return runArguments; | |
| 109 | } | |
| 110 | } |