microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.11.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

137lines · 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 (isExperimental) {
44 debugScenarioName.experimentalDescription = "- Experimental";
45 }
46
47 return this.debugScenarioNameToString(debugScenarioName);
48 }
49
50 private static createScenarioAccordingToDebugScenarioType(
51 debugScenarioType: DebugScenarioType,
52 ): DebugScenarioName {
53 switch (debugScenarioType) {
54 case DebugScenarioType.RunApp:
55 return {
56 debugScenarioType: "Run",
57 };
58 case DebugScenarioType.DebugApp:
59 return {
60 debugScenarioType: "Debug",
61 };
62 case DebugScenarioType.AttachApp:
63 return {
64 debugScenarioType: "Attach to",
65 };
66 }
67 }
68
69 private static configureNotDirectModeScenario(
70 debugScenarioName: DebugScenarioName,
71 debugScenarioType: DebugScenarioType,
72 debugType: string,
73 platformType?: PlatformType | string,
74 ): void {
75 if (debugScenarioType === DebugScenarioType.AttachApp) {
76 debugScenarioName.platformType = "packager";
77 }
78 if (platformType === PlatformType.Exponent) {
79 debugScenarioName.prePlatformTypeDescription = "in";
80 }
81 }
82
83 private static configureDirectModeScenario(
84 debugScenarioName: DebugScenarioName,
85 debugScenarioType: DebugScenarioType,
86 debugType: string,
87 useHermesEngine: boolean,
88 platformType?: PlatformType | string,
89 ) {
90 if (useHermesEngine) {
91 debugScenarioName.postPlatformTypeDescription =
92 debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes";
93 }
94 switch (platformType) {
95 case PlatformType.iOS:
96 if (!useHermesEngine) {
97 debugScenarioName.prePlatformTypeDescription = "Direct";
98 }
99 break;
100 }
101 }
102
103 private static getPlatformTypeName(platformType?: PlatformType | string): string {
104 switch (platformType) {
105 case PlatformType.Android:
106 return "Android";
107 case PlatformType.iOS:
108 return "iOS";
109 case PlatformType.Exponent:
110 return "Exponent";
111 case PlatformType.Windows:
112 return "Windows";
113 case PlatformType.macOS:
114 return "macOS";
115 default:
116 return "";
117 }
118 }
119
120 private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
121 let debugScenarioNameStr = debugScenarioName.debugScenarioType;
122 if (debugScenarioName.prePlatformTypeDescription) {
123 debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
124 }
125 if (debugScenarioName.platformType) {
126 debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
127 }
128 if (debugScenarioName.postPlatformTypeDescription) {
129 debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
130 }
131 if (debugScenarioName.experimentalDescription) {
132 debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
133 }
134
135 return debugScenarioNameStr;
136 }
137}
138