microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.12.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

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