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