microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.9.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

137lines · modeblame

5471436aRedMickey5 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
4import { PlatformType } from "../launchArgs";
09f6024fHeniker4 years ago5import { DebugScenarioType, DEBUG_TYPES } from "./debugConfigTypesAndConstants";
5471436aRedMickey5 years ago6
7interface DebugScenarioName {
8debugScenarioType: string;
9prePlatformTypeDescription?: string;
10platformType?: string;
11postPlatformTypeDescription?: string;
12experimentalDescription?: string;
13}
14
15export class DebugScenarioNameGenerator {
16public static createScenarioName(
17debugScenarioType: DebugScenarioType,
18debugType: string,
19platformType?: PlatformType | string,
6f9a0779JiglioNero5 years ago20useHermesEngine: boolean = false,
5471436aRedMickey5 years ago21isExperimental: boolean = false,
22): string {
09f6024fHeniker4 years ago23const debugScenarioName: DebugScenarioName =
24this.createScenarioAccordingToDebugScenarioType(debugScenarioType);
5471436aRedMickey5 years ago25debugScenarioName.platformType = this.getPlatformTypeName(platformType);
26if (debugType === DEBUG_TYPES.REACT_NATIVE) {
27this.configureNotDirectModeScenario(
28debugScenarioName,
29debugScenarioType,
30debugType,
31platformType,
32);
33} else {
34this.configureDirectModeScenario(
35debugScenarioName,
36debugScenarioType,
37debugType,
6f9a0779JiglioNero5 years ago38useHermesEngine,
5471436aRedMickey5 years ago39platformType,
40);
41}
42
43if (isExperimental) {
44debugScenarioName.experimentalDescription = "- Experimental";
45}
46
47return this.debugScenarioNameToString(debugScenarioName);
48}
49
50private static createScenarioAccordingToDebugScenarioType(
51debugScenarioType: DebugScenarioType,
52): DebugScenarioName {
53switch (debugScenarioType) {
54case DebugScenarioType.RunApp:
55return {
56debugScenarioType: "Run",
57};
58case DebugScenarioType.DebugApp:
59return {
60debugScenarioType: "Debug",
61};
62case DebugScenarioType.AttachApp:
63return {
64debugScenarioType: "Attach to",
65};
66}
67}
68
69private static configureNotDirectModeScenario(
70debugScenarioName: DebugScenarioName,
71debugScenarioType: DebugScenarioType,
72debugType: string,
73platformType?: PlatformType | string,
74): void {
75if (debugScenarioType === DebugScenarioType.AttachApp) {
76debugScenarioName.platformType = "packager";
77}
78if (platformType === PlatformType.Exponent) {
79debugScenarioName.prePlatformTypeDescription = "in";
80}
81}
82
83private static configureDirectModeScenario(
84debugScenarioName: DebugScenarioName,
85debugScenarioType: DebugScenarioType,
86debugType: string,
6f9a0779JiglioNero5 years ago87useHermesEngine: boolean,
5471436aRedMickey5 years ago88platformType?: PlatformType | string,
89) {
6f9a0779JiglioNero5 years ago90if (useHermesEngine) {
91debugScenarioName.postPlatformTypeDescription =
92debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes";
93}
5471436aRedMickey5 years ago94switch (platformType) {
95case PlatformType.iOS:
6f9a0779JiglioNero5 years ago96if (!useHermesEngine) {
5471436aRedMickey5 years ago97debugScenarioName.prePlatformTypeDescription = "Direct";
98}
99break;
100}
101}
102
103private static getPlatformTypeName(platformType?: PlatformType | string): string {
104switch (platformType) {
105case PlatformType.Android:
106return "Android";
107case PlatformType.iOS:
108return "iOS";
109case PlatformType.Exponent:
110return "Exponent";
111case PlatformType.Windows:
112return "Windows";
113case PlatformType.macOS:
114return "macOS";
115default:
116return "";
117}
118}
119
120private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
121let debugScenarioNameStr = debugScenarioName.debugScenarioType;
122if (debugScenarioName.prePlatformTypeDescription) {
123debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
124}
125if (debugScenarioName.platformType) {
126debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
127}
128if (debugScenarioName.postPlatformTypeDescription) {
129debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
130}
131if (debugScenarioName.experimentalDescription) {
132debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
133}
134
135return debugScenarioNameStr;
136}
137}