microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/windows/wpfPlatform.ts
80lines · modeblame
dd90a856Artem 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 | import * as semver from "semver"; | |
| 6 | import * as path from "path"; | |
| 7 | | |
| 8 | import {MobilePlatformDeps} from "../generalMobilePlatform"; | |
| 9 | import {IWindowsRunOptions} from "../launchArgs"; | |
| 10 | import {TelemetryHelper} from "../../common/telemetryHelper"; | |
| 11 | import {CommandExecutor} from "../../common/commandExecutor"; | |
| 12 | import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper"; | |
| 13 | import {WindowsPlatform} from "./windowsPlatform"; | |
| 14 | | |
| 15 | /** | |
| 16 | * WPF specific platform implementation for debugging RN applications. | |
| 17 | */ | |
| 18 | export class WpfPlatform extends WindowsPlatform { | |
| 19 | private static WPF_SUPPORTED = "0.55.0"; | |
| 20 | constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 21 | super(runOptions, platformDeps); | |
| 22 | } | |
| 23 | | |
| 24 | public runApp(enableDebug: boolean = true): Q.Promise<void> { | |
| 25 | const extProps = { | |
| 26 | platform: { | |
| 27 | value: "wpf", | |
| 28 | isPii: false, | |
| 29 | }, | |
| 30 | }; | |
| 31 | | |
| 32 | return TelemetryHelper.generate("WpfPlatform.runApp", extProps, () => { | |
| 33 | const env = this.getEnvArgument(); | |
| 34 | | |
| 35 | if (enableDebug) { | |
db6fd42aRuslan Bikkinin7 years ago | 36 | this.runArguments.push("--proxy"); |
dd90a856Artem Egorov8 years ago | 37 | } |
| 38 | | |
| 39 | return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot) | |
| 40 | .then(version => { | |
| 41 | if (!semver.gt(version, WpfPlatform.WPF_SUPPORTED)) { | |
| 42 | throw new Error(`Debugging WPF platform is not supported for this react-native-windows version(${version})`); | |
| 43 | } | |
| 44 | | |
| 45 | if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WpfPlatform.NO_PACKAGER_VERSION)) { | |
db6fd42aRuslan Bikkinin7 years ago | 46 | this.runArguments.push("--no-packager"); |
dd90a856Artem Egorov8 years ago | 47 | } |
| 48 | | |
| 49 | const exec = new CommandExecutor(this.projectPath, this.logger); | |
| 50 | return Q.Promise((resolve, reject) => { | |
| 51 | const appName = this.projectPath.split(path.sep).pop(); | |
| 52 | // Killing another instances of the app which were run earlier | |
| 53 | return exec.execute(`cmd /C Taskkill /IM ${appName}.exe /F`) | |
| 54 | .finally(() => { | |
db6fd42aRuslan Bikkinin7 years ago | 55 | const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env}); |
dd90a856Artem Egorov8 years ago | 56 | let resolved = false; |
| 57 | let output = ""; | |
| 58 | runWpfSpawn.stdout.on("data", (data: Buffer) => { | |
| 59 | output += data.toString(); | |
| 60 | if (!resolved && output.indexOf("Starting the app") > -1) { | |
| 61 | resolved = true; | |
| 62 | resolve(void 0); | |
| 63 | } | |
| 64 | }); | |
| 65 | | |
| 66 | runWpfSpawn.stderr.on("data", (error: Buffer) => { | |
| 67 | if (error.toString().trim()) { | |
| 68 | reject(error.toString()); | |
| 69 | } | |
| 70 | }); | |
| 71 | | |
| 72 | runWpfSpawn.outcome.then(() => { | |
| 73 | reject(void 0); // If WPF process ended then app run fault | |
| 74 | }); | |
| 75 | }); | |
| 76 | }); | |
| 77 | }); | |
| 78 | }); | |
| 79 | } | |
| 80 | } |