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