microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

144lines · 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,
21isExperimental: boolean = false,
22): string {
23let debugScenarioName: DebugScenarioName = this.createScenarioAccordingToDebugScenarioType(
24debugScenarioType,
25);
26debugScenarioName.platformType = this.getPlatformTypeName(platformType);
27if (debugType === DEBUG_TYPES.REACT_NATIVE) {
28this.configureNotDirectModeScenario(
29debugScenarioName,
30debugScenarioType,
31debugType,
32platformType,
33);
34} else {
35this.configureDirectModeScenario(
36debugScenarioName,
37debugScenarioType,
38debugType,
39platformType,
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,
87platformType?: PlatformType | string,
88) {
89switch (platformType) {
90case PlatformType.Android:
91if (debugScenarioType === DebugScenarioType.AttachApp) {
92debugScenarioName.prePlatformTypeDescription = "the React Native";
93debugScenarioName.platformType = "Hermes";
94} else {
95debugScenarioName.postPlatformTypeDescription = "Hermes";
96}
97break;
98case PlatformType.iOS:
99if (debugScenarioType === DebugScenarioType.AttachApp) {
100debugScenarioName.prePlatformTypeDescription = "the React Native";
101} else {
102debugScenarioName.prePlatformTypeDescription = "Direct";
103}
104break;
105}
106}
107
108private static getPlatformTypeName(platformType?: PlatformType | string): string {
109switch (platformType) {
110case PlatformType.Android:
111return "Android";
112case PlatformType.iOS:
113return "iOS";
114case PlatformType.Exponent:
115return "Exponent";
116case PlatformType.Windows:
117return "Windows";
118case PlatformType.WPF:
119return "WPF";
120case PlatformType.macOS:
121return "macOS";
122default:
123return "";
124}
125}
126
127private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
128let debugScenarioNameStr = debugScenarioName.debugScenarioType;
129if (debugScenarioName.prePlatformTypeDescription) {
130debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
131}
132if (debugScenarioName.platformType) {
133debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
134}
135if (debugScenarioName.postPlatformTypeDescription) {
136debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
137}
138if (debugScenarioName.experimentalDescription) {
139debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
140}
141
142return debugScenarioNameStr;
143}
144}