microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts
149lines · modeblame
5471436aRedMickey5 years ago | 1 | // 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 ago | 4 | import { PlatformType, ExpoPlatform } from "../launchArgs"; |
09f6024fHeniker4 years ago | 5 | import { DebugScenarioType, DEBUG_TYPES } from "./debugConfigTypesAndConstants"; |
5471436aRedMickey5 years ago | 6 | |
| 7 | interface DebugScenarioName { | |
| 8 | debugScenarioType: string; | |
| 9 | prePlatformTypeDescription?: string; | |
| 10 | platformType?: string; | |
| 11 | postPlatformTypeDescription?: string; | |
| 12 | experimentalDescription?: string; | |
7a4506dclexie0111 years ago | 13 | expoPlatformType?: ExpoPlatform; |
5471436aRedMickey5 years ago | 14 | } |
| 15 | | |
| 16 | export class DebugScenarioNameGenerator { | |
| 17 | public static createScenarioName( | |
| 18 | debugScenarioType: DebugScenarioType, | |
| 19 | debugType: string, | |
| 20 | platformType?: PlatformType | string, | |
6f9a0779JiglioNero5 years ago | 21 | useHermesEngine: boolean = false, |
5471436aRedMickey5 years ago | 22 | isExperimental: boolean = false, |
7a4506dclexie0111 years ago | 23 | expoPlatformType?: ExpoPlatform, |
5471436aRedMickey5 years ago | 24 | ): string { |
09f6024fHeniker4 years ago | 25 | const debugScenarioName: DebugScenarioName = |
| 26 | this.createScenarioAccordingToDebugScenarioType(debugScenarioType); | |
5471436aRedMickey5 years ago | 27 | debugScenarioName.platformType = this.getPlatformTypeName(platformType); |
7a4506dclexie0111 years ago | 28 | |
| 29 | if (platformType === PlatformType.Exponent) { | |
| 30 | debugScenarioName.expoPlatformType = expoPlatformType; | |
| 31 | } | |
| 32 | | |
5471436aRedMickey5 years ago | 33 | if (debugType === DEBUG_TYPES.REACT_NATIVE) { |
| 34 | this.configureNotDirectModeScenario( | |
| 35 | debugScenarioName, | |
| 36 | debugScenarioType, | |
| 37 | debugType, | |
| 38 | platformType, | |
| 39 | ); | |
| 40 | } else { | |
| 41 | this.configureDirectModeScenario( | |
| 42 | debugScenarioName, | |
| 43 | debugScenarioType, | |
| 44 | debugType, | |
6f9a0779JiglioNero5 years ago | 45 | useHermesEngine, |
5471436aRedMickey5 years ago | 46 | platformType, |
| 47 | ); | |
| 48 | } | |
| 49 | | |
| 50 | if (isExperimental) { | |
| 51 | debugScenarioName.experimentalDescription = "- Experimental"; | |
| 52 | } | |
| 53 | | |
| 54 | return this.debugScenarioNameToString(debugScenarioName); | |
| 55 | } | |
| 56 | | |
| 57 | private static createScenarioAccordingToDebugScenarioType( | |
| 58 | debugScenarioType: DebugScenarioType, | |
| 59 | ): DebugScenarioName { | |
| 60 | switch (debugScenarioType) { | |
| 61 | case DebugScenarioType.RunApp: | |
| 62 | return { | |
| 63 | debugScenarioType: "Run", | |
| 64 | }; | |
| 65 | case DebugScenarioType.DebugApp: | |
| 66 | return { | |
| 67 | debugScenarioType: "Debug", | |
| 68 | }; | |
| 69 | case DebugScenarioType.AttachApp: | |
| 70 | return { | |
| 71 | debugScenarioType: "Attach to", | |
| 72 | }; | |
| 73 | } | |
| 74 | } | |
| 75 | | |
| 76 | private static configureNotDirectModeScenario( | |
| 77 | debugScenarioName: DebugScenarioName, | |
| 78 | debugScenarioType: DebugScenarioType, | |
| 79 | debugType: string, | |
| 80 | platformType?: PlatformType | string, | |
| 81 | ): void { | |
| 82 | if (debugScenarioType === DebugScenarioType.AttachApp) { | |
| 83 | debugScenarioName.platformType = "packager"; | |
| 84 | } | |
| 85 | if (platformType === PlatformType.Exponent) { | |
| 86 | debugScenarioName.prePlatformTypeDescription = "in"; | |
| 87 | } | |
| 88 | } | |
| 89 | | |
| 90 | private static configureDirectModeScenario( | |
| 91 | debugScenarioName: DebugScenarioName, | |
| 92 | debugScenarioType: DebugScenarioType, | |
| 93 | debugType: string, | |
6f9a0779JiglioNero5 years ago | 94 | useHermesEngine: boolean, |
5471436aRedMickey5 years ago | 95 | platformType?: PlatformType | string, |
| 96 | ) { | |
6f9a0779JiglioNero5 years ago | 97 | if (useHermesEngine) { |
| 98 | debugScenarioName.postPlatformTypeDescription = | |
| 99 | debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes"; | |
| 100 | } | |
5471436aRedMickey5 years ago | 101 | switch (platformType) { |
| 102 | case PlatformType.iOS: | |
6f9a0779JiglioNero5 years ago | 103 | if (!useHermesEngine) { |
5471436aRedMickey5 years ago | 104 | debugScenarioName.prePlatformTypeDescription = "Direct"; |
| 105 | } | |
| 106 | break; | |
| 107 | } | |
| 108 | } | |
| 109 | | |
| 110 | private static getPlatformTypeName(platformType?: PlatformType | string): string { | |
| 111 | switch (platformType) { | |
| 112 | case PlatformType.Android: | |
| 113 | return "Android"; | |
| 114 | case PlatformType.iOS: | |
| 115 | return "iOS"; | |
| 116 | case PlatformType.Exponent: | |
| 117 | return "Exponent"; | |
| 118 | case PlatformType.Windows: | |
| 119 | return "Windows"; | |
| 120 | case PlatformType.macOS: | |
| 121 | return "macOS"; | |
9f8c460dEzio Li2 years ago | 122 | case PlatformType.ExpoWeb: |
| 123 | return "Expo Web"; | |
5471436aRedMickey5 years ago | 124 | default: |
| 125 | return ""; | |
| 126 | } | |
| 127 | } | |
| 128 | | |
| 129 | private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string { | |
| 130 | let debugScenarioNameStr = debugScenarioName.debugScenarioType; | |
| 131 | if (debugScenarioName.prePlatformTypeDescription) { | |
| 132 | debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`; | |
| 133 | } | |
| 134 | if (debugScenarioName.platformType) { | |
| 135 | debugScenarioNameStr += ` ${debugScenarioName.platformType}`; | |
| 136 | } | |
7a4506dclexie0111 years ago | 137 | if (debugScenarioName.expoPlatformType) { |
| 138 | debugScenarioNameStr += ` ${debugScenarioName.expoPlatformType}`; | |
| 139 | } | |
5471436aRedMickey5 years ago | 140 | if (debugScenarioName.postPlatformTypeDescription) { |
| 141 | debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`; | |
| 142 | } | |
| 143 | if (debugScenarioName.experimentalDescription) { | |
| 144 | debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`; | |
| 145 | } | |
| 146 | | |
| 147 | return debugScenarioNameStr; | |
| 148 | } | |
| 149 | } |