microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix-ts-error1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

149lines · 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
7a4506dclexie0111 years ago4import { PlatformType, ExpoPlatform } 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;
7a4506dclexie0111 years ago13expoPlatformType?: ExpoPlatform;
5471436aRedMickey5 years ago14}
15
16export class DebugScenarioNameGenerator {
17public static createScenarioName(
18debugScenarioType: DebugScenarioType,
19debugType: string,
20platformType?: PlatformType | string,
6f9a0779JiglioNero5 years ago21useHermesEngine: boolean = false,
5471436aRedMickey5 years ago22isExperimental: boolean = false,
7a4506dclexie0111 years ago23expoPlatformType?: ExpoPlatform,
5471436aRedMickey5 years ago24): string {
09f6024fHeniker4 years ago25const debugScenarioName: DebugScenarioName =
26this.createScenarioAccordingToDebugScenarioType(debugScenarioType);
5471436aRedMickey5 years ago27debugScenarioName.platformType = this.getPlatformTypeName(platformType);
7a4506dclexie0111 years ago28
29if (platformType === PlatformType.Exponent) {
30debugScenarioName.expoPlatformType = expoPlatformType;
31}
32
5471436aRedMickey5 years ago33if (debugType === DEBUG_TYPES.REACT_NATIVE) {
34this.configureNotDirectModeScenario(
35debugScenarioName,
36debugScenarioType,
37debugType,
38platformType,
39);
40} else {
41this.configureDirectModeScenario(
42debugScenarioName,
43debugScenarioType,
44debugType,
6f9a0779JiglioNero5 years ago45useHermesEngine,
5471436aRedMickey5 years ago46platformType,
47);
48}
49
50if (isExperimental) {
51debugScenarioName.experimentalDescription = "- Experimental";
52}
53
54return this.debugScenarioNameToString(debugScenarioName);
55}
56
57private static createScenarioAccordingToDebugScenarioType(
58debugScenarioType: DebugScenarioType,
59): DebugScenarioName {
60switch (debugScenarioType) {
61case DebugScenarioType.RunApp:
62return {
63debugScenarioType: "Run",
64};
65case DebugScenarioType.DebugApp:
66return {
67debugScenarioType: "Debug",
68};
69case DebugScenarioType.AttachApp:
70return {
71debugScenarioType: "Attach to",
72};
73}
74}
75
76private static configureNotDirectModeScenario(
77debugScenarioName: DebugScenarioName,
78debugScenarioType: DebugScenarioType,
79debugType: string,
80platformType?: PlatformType | string,
81): void {
82if (debugScenarioType === DebugScenarioType.AttachApp) {
83debugScenarioName.platformType = "packager";
84}
85if (platformType === PlatformType.Exponent) {
86debugScenarioName.prePlatformTypeDescription = "in";
87}
88}
89
90private static configureDirectModeScenario(
91debugScenarioName: DebugScenarioName,
92debugScenarioType: DebugScenarioType,
93debugType: string,
6f9a0779JiglioNero5 years ago94useHermesEngine: boolean,
5471436aRedMickey5 years ago95platformType?: PlatformType | string,
96) {
6f9a0779JiglioNero5 years ago97if (useHermesEngine) {
98debugScenarioName.postPlatformTypeDescription =
99debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes";
100}
5471436aRedMickey5 years ago101switch (platformType) {
102case PlatformType.iOS:
6f9a0779JiglioNero5 years ago103if (!useHermesEngine) {
5471436aRedMickey5 years ago104debugScenarioName.prePlatformTypeDescription = "Direct";
105}
106break;
107}
108}
109
110private static getPlatformTypeName(platformType?: PlatformType | string): string {
111switch (platformType) {
112case PlatformType.Android:
113return "Android";
114case PlatformType.iOS:
115return "iOS";
116case PlatformType.Exponent:
117return "Exponent";
118case PlatformType.Windows:
119return "Windows";
120case PlatformType.macOS:
121return "macOS";
9f8c460dEzio Li2 years ago122case PlatformType.ExpoWeb:
123return "Expo Web";
5471436aRedMickey5 years ago124default:
125return "";
126}
127}
128
129private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
130let debugScenarioNameStr = debugScenarioName.debugScenarioType;
131if (debugScenarioName.prePlatformTypeDescription) {
132debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
133}
134if (debugScenarioName.platformType) {
135debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
136}
7a4506dclexie0111 years ago137if (debugScenarioName.expoPlatformType) {
138debugScenarioNameStr += ` ${debugScenarioName.expoPlatformType}`;
139}
5471436aRedMickey5 years ago140if (debugScenarioName.postPlatformTypeDescription) {
141debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
142}
143if (debugScenarioName.experimentalDescription) {
144debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
145}
146
147return debugScenarioNameStr;
148}
149}