microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.7.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

80lines · 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
4import * as Q from "q";
5import * as semver from "semver";
6import * as path from "path";
7
8import {MobilePlatformDeps} from "../generalMobilePlatform";
9import {IWindowsRunOptions} from "../launchArgs";
10import {TelemetryHelper} from "../../common/telemetryHelper";
11import {CommandExecutor} from "../../common/commandExecutor";
12import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper";
13import {WindowsPlatform} from "./windowsPlatform";
14
15/**
16 * WPF specific platform implementation for debugging RN applications.
17 */
18export 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) {
36 this.runArguments.push("--proxy");
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)) {
46 this.runArguments.push("--no-packager");
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(() => {
55 const runWpfSpawn = exec.spawnReactCommand(`run-${this.platformName}`, this.runArguments, {env});
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}
81