microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.5.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/windows/windowsPlatform.ts

110lines · 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},
60ad4ec0JiglioNero5 years ago24{
25pattern: /×.+$/gm,
26errorCode: InternalErrorCode.WinRunCommandFailed,
27},
299883f9Artem Egorov8 years ago28];
29
30constructor(protected runOptions: IWindowsRunOptions, platformDeps: MobilePlatformDeps = {}) {
31super(runOptions, platformDeps);
32}
33
ce5e88eeYuri Skorokhodov5 years ago34public runApp(enableDebug: boolean = true): Promise<void> {
ba953e9fRedMickey6 years ago35let extProps = {
031832ffArtem Egorov7 years ago36platform: {
259c018fYuri Skorokhodov5 years ago37value: PlatformType.Windows,
031832ffArtem Egorov7 years ago38isPii: false,
39},
40};
41
34472878RedMickey5 years ago42extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
43this.runOptions,
44this.runOptions.reactNativeVersions,
45extProps,
46);
ba953e9fRedMickey6 years ago47
031832ffArtem Egorov7 years ago48return TelemetryHelper.generate("WindowsPlatform.runApp", extProps, () => {
34472878RedMickey5 years ago49const env = GeneralMobilePlatform.getEnvArgument(
50process.env,
51this.runOptions.env,
52this.runOptions.envFile,
53);
299883f9Artem Egorov8 years ago54
34472878RedMickey5 years ago55if (
56semver.gte(this.runOptions.reactNativeVersions.reactNativeWindowsVersion, "0.63.0")
57) {
4dfc9ffdRedMickey5 years ago58this.runArguments.push("--logging");
59if (enableDebug) {
c6027eadYuri Skorokhodov5 years ago60this.runArguments.push("--remote-debugging");
4dfc9ffdRedMickey5 years ago61}
299883f9Artem Egorov8 years ago62}
63
34472878RedMickey5 years ago64if (
65!semver.valid(
66this.runOptions.reactNativeVersions.reactNativeVersion,
67) /*Custom RN implementations should support this flag*/ ||
68semver.gte(
69this.runOptions.reactNativeVersions.reactNativeVersion,
70WindowsPlatform.NO_PACKAGER_VERSION,
71)
72) {
7fa90b3bRedMickey6 years ago73this.runArguments.push("--no-packager");
74}
299883f9Artem Egorov8 years ago75
34472878RedMickey5 years ago76const runWindowsSpawn = new CommandExecutor(
4dfb1c4cetatanova5 years ago77this.runOptions.nodeModulesRoot,
34472878RedMickey5 years ago78this.projectPath,
79this.logger,
80).spawnReactCommand(`run-${this.platformName}`, this.runArguments, { env });
81return new OutputVerifier(
82() => Promise.resolve(WindowsPlatform.SUCCESS_PATTERNS),
83() => Promise.resolve(WindowsPlatform.FAILURE_PATTERNS),
84this.platformName,
85).process(runWindowsSpawn);
299883f9Artem Egorov8 years ago86});
87}
88
ce5e88eeYuri Skorokhodov5 years ago89public prewarmBundleCache(): Promise<void> {
259c018fYuri Skorokhodov5 years ago90return this.packager.prewarmBundleCache(PlatformType.Windows);
299883f9Artem Egorov8 years ago91}
92
cbc7ac5bArtem Egorov7 years ago93public getRunArguments(): string[] {
299883f9Artem Egorov8 years ago94let runArguments: string[] = [];
95
4dfc9ffdRedMickey5 years ago96if (this.runOptions.runArguments && this.runOptions.runArguments.length > 0) {
299883f9Artem Egorov8 years ago97runArguments.push(...this.runOptions.runArguments);
98} else {
34472878RedMickey5 years ago99let target =
100this.runOptions.target === WindowsPlatform.simulatorString
101? ""
102: this.runOptions.target;
dd90a856Artem Egorov7 years ago103if (target) {
104runArguments.push(`--${target}`);
299883f9Artem Egorov8 years ago105}
106}
107
108return runArguments;
109}
110}