microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
test-microbuild1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts

153lines · 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
6ad9254blexie0112 years ago50if (platformType === PlatformType.ExpoWeb || !useHermesEngine) {
9f8c460dEzio Li2 years ago51isExperimental = true;
52}
53
5471436aRedMickey5 years ago54if (isExperimental) {
55debugScenarioName.experimentalDescription = "- Experimental";
56}
57
58return this.debugScenarioNameToString(debugScenarioName);
59}
60
61private static createScenarioAccordingToDebugScenarioType(
62debugScenarioType: DebugScenarioType,
63): DebugScenarioName {
64switch (debugScenarioType) {
65case DebugScenarioType.RunApp:
66return {
67debugScenarioType: "Run",
68};
69case DebugScenarioType.DebugApp:
70return {
71debugScenarioType: "Debug",
72};
73case DebugScenarioType.AttachApp:
74return {
75debugScenarioType: "Attach to",
76};
77}
78}
79
80private static configureNotDirectModeScenario(
81debugScenarioName: DebugScenarioName,
82debugScenarioType: DebugScenarioType,
83debugType: string,
84platformType?: PlatformType | string,
85): void {
86if (debugScenarioType === DebugScenarioType.AttachApp) {
87debugScenarioName.platformType = "packager";
88}
89if (platformType === PlatformType.Exponent) {
90debugScenarioName.prePlatformTypeDescription = "in";
91}
92}
93
94private static configureDirectModeScenario(
95debugScenarioName: DebugScenarioName,
96debugScenarioType: DebugScenarioType,
97debugType: string,
6f9a0779JiglioNero5 years ago98useHermesEngine: boolean,
5471436aRedMickey5 years ago99platformType?: PlatformType | string,
100) {
6f9a0779JiglioNero5 years ago101if (useHermesEngine) {
102debugScenarioName.postPlatformTypeDescription =
103debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes";
104}
5471436aRedMickey5 years ago105switch (platformType) {
106case PlatformType.iOS:
6f9a0779JiglioNero5 years ago107if (!useHermesEngine) {
5471436aRedMickey5 years ago108debugScenarioName.prePlatformTypeDescription = "Direct";
109}
110break;
111}
112}
113
114private static getPlatformTypeName(platformType?: PlatformType | string): string {
115switch (platformType) {
116case PlatformType.Android:
117return "Android";
118case PlatformType.iOS:
119return "iOS";
120case PlatformType.Exponent:
121return "Exponent";
122case PlatformType.Windows:
123return "Windows";
124case PlatformType.macOS:
125return "macOS";
9f8c460dEzio Li2 years ago126case PlatformType.ExpoWeb:
127return "Expo Web";
5471436aRedMickey5 years ago128default:
129return "";
130}
131}
132
133private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string {
134let debugScenarioNameStr = debugScenarioName.debugScenarioType;
135if (debugScenarioName.prePlatformTypeDescription) {
136debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`;
137}
138if (debugScenarioName.platformType) {
139debugScenarioNameStr += ` ${debugScenarioName.platformType}`;
140}
7a4506dclexie0111 years ago141if (debugScenarioName.expoPlatformType) {
142debugScenarioNameStr += ` ${debugScenarioName.expoPlatformType}`;
143}
5471436aRedMickey5 years ago144if (debugScenarioName.postPlatformTypeDescription) {
145debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`;
146}
147if (debugScenarioName.experimentalDescription) {
148debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`;
149}
150
151return debugScenarioNameStr;
152}
153}