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