microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/remove-ios-relative-project-path

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

149lines · 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 { PlatformType, ExpoPlatform } from "../launchArgs";
5import { DebugScenarioType, DEBUG_TYPES } from "./debugConfigTypesAndConstants";
6
7interface DebugScenarioName {
8 debugScenarioType: string;
9 prePlatformTypeDescription?: string;
10 platformType?: string;
11 postPlatformTypeDescription?: string;
12 experimentalDescription?: string;
13 expoPlatformType?: ExpoPlatform;
14}
15
16export class DebugScenarioNameGenerator {
17 public static createScenarioName(
18 debugScenarioType: DebugScenarioType,
19 debugType: string,
20 platformType?: PlatformType | string,
21 useHermesEngine: boolean = false,
22 isExperimental: boolean = false,
23 expoPlatformType?: ExpoPlatform,
24 ): string {
25 const debugScenarioName: DebugScenarioName =
26 this.createScenarioAccordingToDebugScenarioType(debugScenarioType);
27 debugScenarioName.platformType = this.getPlatformTypeName(platformType);
28
29 if (platformType === PlatformType.Exponent) {
30 debugScenarioName.expoPlatformType = expoPlatformType;
31 }
32
33 if (debugType === DEBUG_TYPES.REACT_NATIVE) {
34 this.configureNotDirectModeScenario(
35 debugScenarioName,
36 debugScenarioType,
37 debugType,
38 platformType,
39 );
40 } else {
41 this.configureDirectModeScenario(
42 debugScenarioName,
43 debugScenarioType,
44 debugType,
45 useHermesEngine,
46 platformType,
47 );
48 }
49
50 if (isExperimental) {
51 debugScenarioName.experimentalDescription = "- Experimental";
52 }
53
54 return this.debugScenarioNameToString(debugScenarioName);
55 }
56
57 private static createScenarioAccordingToDebugScenarioType(
58 debugScenarioType: DebugScenarioType,
59 ): DebugScenarioName {
60 switch (debugScenarioType) {
61 case DebugScenarioType.RunApp:
62 return {
63 debugScenarioType: "Run",
64 };
65 case DebugScenarioType.DebugApp:
66 return {
67 debugScenarioType: "Debug",
68 };
69 case DebugScenarioType.AttachApp:
70 return {
71 debugScenarioType: "Attach to",
72 };
73 }
74 }
75
76 private static configureNotDirectModeScenario(
77 debugScenarioName: DebugScenarioName,
78 debugScenarioType: DebugScenarioType,
79 debugType: string,
80 platformType?: PlatformType | string,
81 ): void {
82 if (debugScenarioType === DebugScenarioType.AttachApp) {
83 debugScenarioName.platformType = "packager";
84 }
85 if (platformType === PlatformType.Exponent) {
86 debugScenarioName.prePlatformTypeDescription = "in";
87 }
88 }
89
90 private static configureDirectModeScenario(
91 debugScenarioName: DebugScenarioName,
92 debugScenarioType: DebugScenarioType,
93 debugType: string,
94 useHermesEngine: boolean,
95 platformType?: PlatformType | string,
96 ) {
97 if (useHermesEngine) {
98 debugScenarioName.postPlatformTypeDescription =
99 debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes";
100 }
101 switch (platformType) {
102 case PlatformType.iOS:
103 if (!useHermesEngine) {
104 debugScenarioName.prePlatformTypeDescription = "Direct";
105 }
106 break;
107 }
108 }
109
110 private static getPlatformTypeName(platformType?: PlatformType | string): string {
111 switch (platformType) {
112 case PlatformType.Android:
113 return "Android";
114 case PlatformType.iOS:
115 return "iOS";
116 case PlatformType.Exponent:
117 return "Exponent";
118 case PlatformType.Windows:
119 return "Windows";
120 case PlatformType.macOS:
121 return "macOS";
122 case PlatformType.ExpoWeb:
123 return "Expo Web";
124 default:
125 return "";
126 }
127 }
128
129 private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
130 let debugScenarioNameStr = debugScenarioName.debugScenarioType;
131 if (debugScenarioName.prePlatformTypeDescription) {
132 debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
133 }
134 if (debugScenarioName.platformType) {
135 debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
136 }
137 if (debugScenarioName.expoPlatformType) {
138 debugScenarioNameStr += ` ${debugScenarioName.expoPlatformType}`;
139 }
140 if (debugScenarioName.postPlatformTypeDescription) {
141 debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
142 }
143 if (debugScenarioName.experimentalDescription) {
144 debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
145 }
146
147 return debugScenarioNameStr;
148 }
149}