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