microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a7386bb907e63d7bf17972a019d7e21c95aca0e5

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

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