microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7bc455e97274ff588d5fb1a0cfaccbc0d6fa56df

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

74lines · 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";
6
7import {GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform";
8import {IWindowsRunOptions} from "../launchArgs";
9import {OutputVerifier, PatternToFailure} from "../../common/outputVerifier";
10import {TelemetryHelper} from "../../common/telemetryHelper";
11import {CommandExecutor} from "../../common/commandExecutor";
12import {ReactNativeProjectHelper} from "../../common/reactNativeProjectHelper";
13
14/**
15 * Windows specific platform implementation for debugging RN applications.
16 */
17export class WindowsPlatform extends GeneralMobilePlatform {
18 protected static NO_PACKAGER_VERSION = "0.53.0";
19
20 private static SUCCESS_PATTERNS = [
21 "Installing new version of the app",
22 "Starting the app",
23 ];
24 private static FAILURE_PATTERNS: PatternToFailure[] = [
25 {
26 pattern: "Unrecognized command 'run-windows'",
27 message: "'rnpm-plugin-windows' doesn't install",
28 },
29 ];
30
31 constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
32 super(runOptions, platformDeps);
33 }
34
35 public runApp(enableDebug: boolean = true): Q.Promise<void> {
36 return TelemetryHelper.generate("WindowsPlatform.runApp", () => {
37 const runArguments = this.getRunArgument();
38 const env = this.getEnvArgument();
39
40 if (enableDebug) {
41 runArguments.push("--proxy");
42 }
43
44 return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot)
45 .then(version => {
46 if (semver.gte(version, WindowsPlatform.NO_PACKAGER_VERSION)) {
47 runArguments.push("--no-packager");
48 }
49
50 const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand("run-windows", runArguments, {env});
51 return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), "windows")
52 .process(runWindowsSpawn);
53 });
54 });
55 }
56
57 public prewarmBundleCache(): Q.Promise<void> {
58 return this.packager.prewarmBundleCache("windows");
59 }
60
61 public getRunArgument(): string[] {
62 let runArguments: string[] = [];
63
64 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
65 runArguments.push(...this.runOptions.runArguments);
66 } else {
67 if (this.runOptions.target) {
68 runArguments.push(this.runOptions.target === "device" ? this.runOptions.target : "emulator");
69 }
70 }
71
72 return runArguments;
73 }
74}
75