microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.13

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/wpfPlatform.ts

81lines · modeblame

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