microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/windowsPlatform.ts
80lines · 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 | |
| 18 | private static SUCCESS_PATTERNS = [ | |
| 19 | "Starting the app", | |
| 20 | ]; | |
| 21 | private static FAILURE_PATTERNS: PatternToFailure[] = [ | |
| 22 | { | |
| 23 | pattern: "Unrecognized command 'run-windows'", | |
d7d405aeYuri Skorokhodov7 years ago | 24 | errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled, |
299883f9Artem Egorov8 years ago | 25 | }, |
| 26 | ]; | |
| 27 | | |
| 28 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 29 | super(runOptions, platformDeps); | |
| 30 | } | |
| 31 | | |
ce5e88eeYuri Skorokhodov5 years ago | 32 | public runApp(enableDebug: boolean = true): Promise<void> { |
ba953e9fRedMickey6 years ago | 33 | let extProps = { |
031832ffArtem Egorov8 years ago | 34 | platform: { |
259c018fYuri Skorokhodov5 years ago | 35 | value: PlatformType.Windows, |
031832ffArtem Egorov8 years ago | 36 | isPii: false, |
| 37 | }, | |
| 38 | }; | |
| 39 | | |
341dba36Yuri Skorokhodov5 years ago | 40 | extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(this.runOptions, this.runOptions.reactNativeVersions, extProps); |
ba953e9fRedMickey6 years ago | 41 | |
031832ffArtem Egorov8 years ago | 42 | return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => { |
de838bbfJiglioNero6 years ago | 43 | const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile); |
299883f9Artem Egorov8 years ago | 44 | |
4dfc9ffdRedMickey5 years ago | 45 | if (semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")) { |
| 46 | this.runArguments.push("--logging"); | |
| 47 | if (enableDebug) { | |
c6027eadYuri Skorokhodov5 years ago | 48 | this.runArguments.push("--remote-debugging"); |
4dfc9ffdRedMickey5 years ago | 49 | } |
299883f9Artem Egorov8 years ago | 50 | } |
| 51 | | |
7fa90b3bRedMickey6 years ago | 52 | if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, WindowsPlatform.NO_PACKAGER_VERSION)) { |
| 53 | this.runArguments.push("--no-packager"); | |
| 54 | } | |
299883f9Artem Egorov8 years ago | 55 | |
4dfc9ffdRedMickey5 years ago | 56 | const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env }); |
ce5e88eeYuri Skorokhodov5 years ago | 57 | return new OutputVerifier(() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS), () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS), this.platformName) |
7fa90b3bRedMickey6 years ago | 58 | .process(runWindowsSpawn); |
299883f9Artem Egorov8 years ago | 59 | }); |
| 60 | } | |
| 61 | | |
ce5e88eeYuri Skorokhodov5 years ago | 62 | public prewarmBundleCache(): Promise<void> { |
259c018fYuri Skorokhodov5 years ago | 63 | return this.packager.prewarmBundleCache(PlatformType.Windows); |
299883f9Artem Egorov8 years ago | 64 | } |
| 65 | | |
cbc7ac5bArtem Egorov7 years ago | 66 | public getRunArguments(): string[] { |
299883f9Artem Egorov8 years ago | 67 | let runArguments: string[] = []; |
| 68 | | |
4dfc9ffdRedMickey5 years ago | 69 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { |
299883f9Artem Egorov8 years ago | 70 | runArguments.push(...this.runOptions.runArguments); |
| 71 | } else { | |
dd90a856Artem Egorov8 years ago | 72 | let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target; |
| 73 | if (target) { | |
| 74 | runArguments.push(`--${target}`); | |
299883f9Artem Egorov8 years ago | 75 | } |
| 76 | } | |
| 77 | | |
| 78 | return runArguments; | |
| 79 | } | |
| 80 | } |