microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.8

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

73lines · 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";
5
6import {GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform";
7import {IWindowsRunOptions} from "../launchArgs";
8import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier";
9import {TelemetryHelper} from "../../common/telemetryHelper";
10import {CommandExecutor} from "../../common/commandExecutor";
11import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper";
12
13/**
14 * Windows specific platform implementation for debugging RN applications.
15 */
16export 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}
74