microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ea42d4004854292e5d6c536c4d57f8a3b348ee18

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

139lines · 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.macOS:
116return "macOS";
117default:
118return "";
119}
120}
121
122private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
123let debugScenarioNameStr = debugScenarioName.debugScenarioType;
124if (debugScenarioName.prePlatformTypeDescription) {
125debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
126}
127if (debugScenarioName.platformType) {
128debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
129}
130if (debugScenarioName.postPlatformTypeDescription) {
131debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
132}
133if (debugScenarioName.experimentalDescription) {
134debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
135}
136
137return debugScenarioNameStr;
138}
139}