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