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/windowsPlatform.ts

82lines · 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 const extProps = {
37 platform: {
38 value: "windows",
39 isPii: false,
40 },
41 };
42
43 return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
44 const runArguments = this.getRunArgument();
45 const env = this.getEnvArgument();
46
47 if (enableDebug) {
48 runArguments.push("--proxy");
49 }
50
51 return ReactNativeProjectHelper.getReactNativeVersion(this.runOptions.projectRoot)
52 .then(version => {
53 if (!semver.valid(version) /*Custom RN implementations should support this flag*/ || semver.gte(version, WindowsPlatform.NO_PACKAGER_VERSION)) {
54 runArguments.push("--no-packager");
55 }
56
57 const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, runArguments, {env});
58 return new OutputVerifier(() => Q(WindowsPlatform.SUCCESS_PATTERNS), () => Q(WindowsPlatform.FAILURE_PATTERNS), this.platformName)
59 .process(runWindowsSpawn);
60 });
61 });
62 }
63
64 public prewarmBundleCache(): Q.Promise<void> {
65 return this.packager.prewarmBundleCache("windows");
66 }
67
68 public getRunArgument(): string[] {
69 let runArguments: string[] = [];
70
71 if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
72 runArguments.push(...this.runOptions.runArguments);
73 } else {
74 let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target;
75 if (target) {
76 runArguments.push(`--${target}`);
77 }
78 }
79
80 return runArguments;
81 }
82}