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