microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/debuggingConfiguration/debugScenarioNameGenerator.ts
144lines · modecode
| 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, |
| 21 | isExperimental: boolean = false, |
| 22 | ): string { |
| 23 | let debugScenarioName: DebugScenarioName = this.createScenarioAccordingToDebugScenarioType( |
| 24 | debugScenarioType, |
| 25 | ); |
| 26 | debugScenarioName.platformType = this.getPlatformTypeName(platformType); |
| 27 | if (debugType === DEBUG_TYPES.REACT_NATIVE) { |
| 28 | this.configureNotDirectModeScenario( |
| 29 | debugScenarioName, |
| 30 | debugScenarioType, |
| 31 | debugType, |
| 32 | platformType, |
| 33 | ); |
| 34 | } else { |
| 35 | this.configureDirectModeScenario( |
| 36 | debugScenarioName, |
| 37 | debugScenarioType, |
| 38 | debugType, |
| 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, |
| 87 | platformType?: PlatformType | string, |
| 88 | ) { |
| 89 | switch (platformType) { |
| 90 | case PlatformType.Android: |
| 91 | if (debugScenarioType === DebugScenarioType.AttachApp) { |
| 92 | debugScenarioName.prePlatformTypeDescription = "the React Native"; |
| 93 | debugScenarioName.platformType = "Hermes"; |
| 94 | } else { |
| 95 | debugScenarioName.postPlatformTypeDescription = "Hermes"; |
| 96 | } |
| 97 | break; |
| 98 | case PlatformType.iOS: |
| 99 | if (debugScenarioType === DebugScenarioType.AttachApp) { |
| 100 | debugScenarioName.prePlatformTypeDescription = "the React Native"; |
| 101 | } else { |
| 102 | debugScenarioName.prePlatformTypeDescription = "Direct"; |
| 103 | } |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | private static getPlatformTypeName(platformType?: PlatformType | string): string { |
| 109 | switch (platformType) { |
| 110 | case PlatformType.Android: |
| 111 | return "Android"; |
| 112 | case PlatformType.iOS: |
| 113 | return "iOS"; |
| 114 | case PlatformType.Exponent: |
| 115 | return "Exponent"; |
| 116 | case PlatformType.Windows: |
| 117 | return "Windows"; |
| 118 | case PlatformType.WPF: |
| 119 | return "WPF"; |
| 120 | case PlatformType.macOS: |
| 121 | return "macOS"; |
| 122 | default: |
| 123 | return ""; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | private static debugScenarioNameToString(debugScenarioName: DebugScenarioName): string { |
| 128 | let debugScenarioNameStr = debugScenarioName.debugScenarioType; |
| 129 | if (debugScenarioName.prePlatformTypeDescription) { |
| 130 | debugScenarioNameStr += ` ${debugScenarioName.prePlatformTypeDescription}`; |
| 131 | } |
| 132 | if (debugScenarioName.platformType) { |
| 133 | debugScenarioNameStr += ` ${debugScenarioName.platformType}`; |
| 134 | } |
| 135 | if (debugScenarioName.postPlatformTypeDescription) { |
| 136 | debugScenarioNameStr += ` ${debugScenarioName.postPlatformTypeDescription}`; |
| 137 | } |
| 138 | if (debugScenarioName.experimentalDescription) { |
| 139 | debugScenarioNameStr += ` ${debugScenarioName.experimentalDescription}`; |
| 140 | } |
| 141 | |
| 142 | return debugScenarioNameStr; |
| 143 | } |
| 144 | } |
| 145 | |