microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.1.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

80lines · 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
18private static SUCCESS_PATTERNS = [
19"Starting the app",
20];
21private static FAILURE_PATTERNS: PatternToFailure[] = [
22{
23pattern: "Unrecognized command 'run-windows'",
d7d405aeYuri Skorokhodov7 years ago24errorCode: InternalErrorCode.WinRNMPPluginIsNotInstalled,
299883f9Artem Egorov8 years ago25},
26];
27
28constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
29super(runOptions, platformDeps);
30}
31
ce5e88eeYuri Skorokhodov5 years ago32public runApp(enableDebug: boolean = true): Promise<void> {
ba953e9fRedMickey6 years ago33let extProps = {
031832ffArtem Egorov8 years ago34platform: {
259c018fYuri Skorokhodov5 years ago35value: PlatformType.Windows,
031832ffArtem Egorov8 years ago36isPii: false,
37},
38};
39
341dba36Yuri Skorokhodov5 years ago40extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(this.runOptions, this.runOptions.reactNativeVersions, extProps);
ba953e9fRedMickey6 years ago41
031832ffArtem Egorov8 years ago42return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
de838bbfJiglioNero6 years ago43const env = GeneralMobilePlatform.getEnvArgument(process.env, this.runOptions.env, this.runOptions.envFile);
299883f9Artem Egorov8 years ago44
4dfc9ffdRedMickey5 years ago45if (semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")) {
46this.runArguments.push("--logging");
47if (enableDebug) {
c6027eadYuri Skorokhodov5 years ago48this.runArguments.push("--remote-debugging");
4dfc9ffdRedMickey5 years ago49}
299883f9Artem Egorov8 years ago50}
51
7fa90b3bRedMickey6 years ago52if (!semver.valid(this.runOptions.reactNativeVersions.reactNativeVersion) /*Custom RN implementations should support this flag*/ || semver.gte(this.runOptions.reactNativeVersions.reactNativeVersion, WindowsPlatform.NO_PACKAGER_VERSION)) {
53this.runArguments.push("--no-packager");
54}
299883f9Artem Egorov8 years ago55
4dfc9ffdRedMickey5 years ago56const runWindowsSpawn = new CommandExecutor(this.projectPath, this.logger).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
ce5e88eeYuri Skorokhodov5 years ago57return new OutputVerifier(() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS), () => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS), this.platformName)
7fa90b3bRedMickey6 years ago58.process(runWindowsSpawn);
299883f9Artem Egorov8 years ago59});
60}
61
ce5e88eeYuri Skorokhodov5 years ago62public prewarmBundleCache(): Promise<void> {
259c018fYuri Skorokhodov5 years ago63return this.packager.prewarmBundleCache(PlatformType.Windows);
299883f9Artem Egorov8 years ago64}
65
cbc7ac5bArtem Egorov7 years ago66public getRunArguments(): string[] {
299883f9Artem Egorov8 years ago67let runArguments: string[] = [];
68
4dfc9ffdRedMickey5 years ago69if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
299883f9Artem Egorov8 years ago70runArguments.push(...this.runOptions.runArguments);
71} else {
dd90a856Artem Egorov8 years ago72let target = this.runOptions.target === WindowsPlatform.simulatorString ? "" : this.runOptions.target;
73if (target) {
74runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago75}
76}
77
78return runArguments;
79}
80}