microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/windowsPlatform.ts
74lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | import * as Q from "q"; |
| 5 | import * as semver from "semver"; |
| 6 | |
| 7 | import {GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform"; |
| 8 | import {IWindowsRunOptions} from "../launchArgs"; |
| 9 | import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier"; |
| 10 | import {TelemetryHelper} from "../../common/telemetryHelper"; |
| 11 | import {CommandExecutor} from "../../common/commandExecutor"; |
| 12 | import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper"; |
| 13 | |
| 14 | /** |
| 15 | * Windows specific platform implementation for debugging RN applications. |
| 16 | */ |
| 17 | export class WindowsPlatform extends GeneralMobilePlatform { |
| 18 | protected static NO_PACKAGER_VERSION = "0.53.0"; |
| 19 | |
| 20 | private static SUCCESS_PATTERNS = [ |
| 21 | "Installing new version of the app", |
| 22 | "Starting the app", |
| 23 | ]; |
| 24 | private static FAILURE_PATTERNS: PatternToFailure[] = [ |
| 25 | { |
| 26 | pattern: "Unrecognized command 'run-windows'", |
| 27 | message: "'rnpm-plugin-windows' doesn't install", |
| 28 | }, |
| 29 | ]; |
| 30 | |
| 31 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { |
| 32 | super(runOptions, platformDeps); |
| 33 | } |
| 34 | |
| 35 | public runApp(enableDebug: boolean = true): Q.Promise<void> { |
| 36 | return TelemetryHelper.generate("WindowsPlatform.runApp", () => { |
| 37 | const runArguments = this.getRunArgument(); |
| 38 | const env = this.getEnvArgument(); |
| 39 | |
| 40 | if (enableDebug) { |
| 41 | runArguments.push("--proxy"); |
| 42 | } |
| 43 | |
| 44 | return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot) |
| 45 | .then(version => { |
| 46 | if (semver.gte(version, WindowsPlatform.NO_PACKAGER_VERSION)) { |
| 47 | runArguments.push("--no-packager"); |
| 48 | } |
| 49 | |
| 50 | const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand("run-windows", runArguments, {env}); |
| 51 | return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), "windows") |
| 52 | .process(runWindowsSpawn); |
| 53 | }); |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | public prewarmBundleCache(): Q.Promise<void> { |
| 58 | return this.packager.prewarmBundleCache("windows"); |
| 59 | } |
| 60 | |
| 61 | public getRunArgument(): string[] { |
| 62 | let runArguments: string[] = []; |
| 63 | |
| 64 | if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) { |
| 65 | runArguments.push(...this.runOptions.runArguments); |
| 66 | } else { |
| 67 | if (this.runOptions.target) { |
| 68 | runArguments.push(this.runOptions.target === "device" ? this.runOptions.target : "emulator"); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return runArguments; |
| 73 | } |
| 74 | } |
| 75 | |