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