microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts
137lines · 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 | | |
| 43 | if (isExperimental) { | |
| 44 | debugScenarioName.experimentalDescription = "- Experimental"; | |
| 45 | } | |
| 46 | | |
| 47 | return this.debugScenarioNameToString(debugScenarioName); | |
| 48 | } | |
| 49 | | |
| 50 | private static createScenarioAccordingToDebugScenarioType( | |
| 51 | debugScenarioType: DebugScenarioType, | |
| 52 | ): DebugScenarioName { | |
| 53 | switch (debugScenarioType) { | |
| 54 | case DebugScenarioType.RunApp: | |
| 55 | return { | |
| 56 | debugScenarioType: "Run", | |
| 57 | }; | |
| 58 | case DebugScenarioType.DebugApp: | |
| 59 | return { | |
| 60 | debugScenarioType: "Debug", | |
| 61 | }; | |
| 62 | case DebugScenarioType.AttachApp: | |
| 63 | return { | |
| 64 | debugScenarioType: "Attach to", | |
| 65 | }; | |
| 66 | } | |
| 67 | } | |
| 68 | | |
| 69 | private static configureNotDirectModeScenario( | |
| 70 | debugScenarioName: DebugScenarioName, | |
| 71 | debugScenarioType: DebugScenarioType, | |
| 72 | debugType: string, | |
| 73 | platformType?: PlatformType | string, | |
| 74 | ): void { | |
| 75 | if (debugScenarioType === DebugScenarioType.AttachApp) { | |
| 76 | debugScenarioName.platformType = "packager"; | |
| 77 | } | |
| 78 | if (platformType === PlatformType.Exponent) { | |
| 79 | debugScenarioName.prePlatformTypeDescription = "in"; | |
| 80 | } | |
| 81 | } | |
| 82 | | |
| 83 | private static configureDirectModeScenario( | |
| 84 | debugScenarioName: DebugScenarioName, | |
| 85 | debugScenarioType: DebugScenarioType, | |
| 86 | debugType: string, | |
6f9a0779JiglioNero5 years ago | 87 | useHermesEngine: boolean, |
5471436aRedMickey5 years ago | 88 | platformType?: PlatformType | string, |
| 89 | ) { | |
6f9a0779JiglioNero5 years ago | 90 | if (useHermesEngine) { |
| 91 | debugScenarioName.postPlatformTypeDescription = | |
| 92 | debugScenarioType === DebugScenarioType.AttachApp ? "Hermes application" : "Hermes"; | |
| 93 | } | |
5471436aRedMickey5 years ago | 94 | switch (platformType) { |
| 95 | case PlatformType.iOS: | |
6f9a0779JiglioNero5 years ago | 96 | if (!useHermesEngine) { |
5471436aRedMickey5 years ago | 97 | debugScenarioName.prePlatformTypeDescription = "Direct"; |
| 98 | } | |
| 99 | break; | |
| 100 | } | |
| 101 | } | |
| 102 | | |
| 103 | private static getPlatformTypeName(platformType?: PlatformType | string): string { | |
| 104 | switch (platformType) { | |
| 105 | case PlatformType.Android: | |
| 106 | return "Android"; | |
| 107 | case PlatformType.iOS: | |
| 108 | return "iOS"; | |
| 109 | case PlatformType.Exponent: | |
| 110 | return "Exponent"; | |
| 111 | case PlatformType.Windows: | |
| 112 | return "Windows"; | |
| 113 | case PlatformType.macOS: | |
| 114 | return "macOS"; | |
| 115 | default: | |
| 116 | return ""; | |
| 117 | } | |
| 118 | } | |
| 119 | | |
| 120 | private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string { | |
| 121 | let debugScenarioNameStr = debugScenarioName.debugScenarioType; | |
| 122 | if (debugScenarioName.prePlatformTypeDescription) { | |
| 123 | debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`; | |
| 124 | } | |
| 125 | if (debugScenarioName.platformType) { | |
| 126 | debugScenarioNameStr += ` ${debugScenarioName.platformType}`; | |
| 127 | } | |
| 128 | if (debugScenarioName.postPlatformTypeDescription) { | |
| 129 | debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`; | |
| 130 | } | |
| 131 | if (debugScenarioName.experimentalDescription) { | |
| 132 | debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`; | |
| 133 | } | |
| 134 | | |
| 135 | return debugScenarioNameStr; | |
| 136 | } | |
| 137 | } |