microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

105lines · modeblame

299883f9Artem 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
7bc455e9Artem Egorov8 years ago4import * as semver from "semver";
4dfc9ffdRedMickey5 years ago5import { GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform";
6import { IWindowsRunOptions, PlatformType } from "../launchArgs";
7import { OutputVerifier, PatternToFailure } from "../../common/outputVerifier";
8import { TelemetryHelper } from "../../common/telemetryHelper";
9import { CommandExecutor } from "../../common/commandExecutor";
d7d405aeYuri Skorokhodov7 years ago10import { InternalErrorCode } from "../../common/error/internalErrorCode";
299883f9Artem Egorov8 years ago11
12/**
13* Windows specific platform implementation for debugging RN applications.
14*/
15export class WindowsPlatform extends GeneralMobilePlatform {
7bc455e9Artem Egorov8 years ago16protected static NO_PACKAGER_VERSION = "0.53.0";
299883f9Artem Egorov8 years ago17
34472878RedMickey5 years ago18private static SUCCESS_PATTERNS = ["Starting the app"];
299883f9Artem Egorov8 years ago19private static FAILURE_PATTERNS: PatternToFailure[] = [
20{
21pattern: "Unrecognized command 'run-windows'",
d7d405aeYuri Skorokhodov7 years ago22errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
299883f9Artem Egorov8 years ago23},
24];
25
26constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
27super(runOptions, platformDeps);
28}
29
ce5e88eeYuri Skorokhodov5 years ago30public runApp(enableDebug: boolean = true): Promise<void> {
ba953e9fRedMickey6 years ago31let extProps = {
031832ffArtem Egorov8 years ago32platform: {
259c018fYuri Skorokhodov5 years ago33value: PlatformType.Windows,
031832ffArtem Egorov8 years ago34isPii: false,
35},
36};
37
34472878RedMickey5 years ago38extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
39this.runOptions,
40this.runOptions.reactNativeVersions,
41extProps,
42);
ba953e9fRedMickey6 years ago43
031832ffArtem Egorov8 years ago44return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
34472878RedMickey5 years ago45const env = GeneralMobilePlatform.getEnvArgument(
46process.env,
47this.runOptions.env,
48this.runOptions.envFile,
49);
299883f9Artem Egorov8 years ago50
34472878RedMickey5 years ago51if (
52semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
53) {
4dfc9ffdRedMickey5 years ago54this.runArguments.push("--logging");
55if (enableDebug) {
c6027eadYuri Skorokhodov5 years ago56this.runArguments.push("--remote-debugging");
4dfc9ffdRedMickey5 years ago57}
299883f9Artem Egorov8 years ago58}
59
34472878RedMickey5 years ago60if (
61!semver.valid(
62this.runOptions.reactNativeVersions.reactNativeVersion,
63) /*Custom RN implementations should support this flag*/ ||
64semver.gte(
65this.runOptions.reactNativeVersions.reactNativeVersion,
66WindowsPlatform.NO_PACKAGER_VERSION,
67)
68) {
7fa90b3bRedMickey6 years ago69this.runArguments.push("--no-packager");
70}
299883f9Artem Egorov8 years ago71
34472878RedMickey5 years ago72const runWindowsSpawn = new CommandExecutor(
73this.projectPath,
74this.logger,
75).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
76return new OutputVerifier(
77() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
78() => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
79this.platformName,
80).process(runWindowsSpawn);
299883f9Artem Egorov8 years ago81});
82}
83
ce5e88eeYuri Skorokhodov5 years ago84public prewarmBundleCache(): Promise<void> {
259c018fYuri Skorokhodov5 years ago85return this.packager.prewarmBundleCache(PlatformType.Windows);
299883f9Artem Egorov8 years ago86}
87
cbc7ac5bArtem Egorov7 years ago88public getRunArguments(): string[] {
299883f9Artem Egorov8 years ago89let runArguments: string[] = [];
90
4dfc9ffdRedMickey5 years ago91if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
299883f9Artem Egorov8 years ago92runArguments.push(...this.runOptions.runArguments);
93} else {
34472878RedMickey5 years ago94let target =
95this.runOptions.target === WindowsPlatform.simulatorString
96? ""
97: this.runOptions.target;
dd90a856Artem Egorov8 years ago98if (target) {
99runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago100}
101}
102
103return runArguments;
104}
105}