microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/debugger/platformResolver.ts
57lines · modeblame
a31b007cunknown10 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 | | |
fb2bae06Daniel10 years ago | 4 | import {IRunOptions} from "./launchArgs"; |
bc7a32ceJimmy Thomson10 years ago | 5 | import * as IOSPlatform from "./ios/iOSPlatform"; |
| 6 | import * as AndroidPlatform from "./android/androidPlatform"; | |
fb2bae06Daniel10 years ago | 7 | |
65ee84c9unknown10 years ago | 8 | /** |
| 9 | * Contains all the mobile platform specific debugging operations. | |
| 10 | */ | |
| 11 | export interface IMobilePlatform { | |
fb2bae06Daniel10 years ago | 12 | runApp(runOptions: IRunOptions): Q.Promise<void>; |
e639e7a4Daniel10 years ago | 13 | enableJSDebuggingMode(runOptions: IRunOptions): Q.Promise<void>; |
65ee84c9unknown10 years ago | 14 | } |
| 15 | | |
| 16 | /** | |
| 17 | * Contains all the desktop platform specific operations. | |
| 18 | */ | |
| 19 | export interface IDesktopPlatform { | |
2f10b3adunknown10 years ago | 20 | reactNativeCommandName: string; |
| 21 | reactPackagerExtraParameters: string[]; | |
65ee84c9unknown10 years ago | 22 | } |
| 23 | | |
f5ea0577unknown10 years ago | 24 | export class PlatformResolver { |
65ee84c9unknown10 years ago | 25 | |
f5ea0577unknown10 years ago | 26 | /** |
| 27 | * Resolves the dev machine, desktop platform. | |
| 28 | */ | |
| 29 | public resolveDesktopPlatform(): IDesktopPlatform { | |
| 30 | let platform = process.platform; | |
| 31 | switch (platform) { | |
| 32 | case "darwin": | |
2f10b3adunknown10 years ago | 33 | return { reactNativeCommandName: "react-native", reactPackagerExtraParameters: [] }; |
f5ea0577unknown10 years ago | 34 | case "win32": |
| 35 | default: | |
4677921cdigeff10 years ago | 36 | return { reactNativeCommandName: "react-native.cmd", reactPackagerExtraParameters: [] }; |
f5ea0577unknown10 years ago | 37 | } |
| 38 | } | |
| 39 | | |
| 40 | /** | |
| 41 | * Resolves the mobile application target platform. | |
| 42 | */ | |
bc7a32ceJimmy Thomson10 years ago | 43 | public resolveMobilePlatform(mobilePlatformString: string, desktopPlatform: IDesktopPlatform): IMobilePlatform { |
f5ea0577unknown10 years ago | 44 | switch (mobilePlatformString) { |
| 45 | // We lazyly load the strategies, because some components might be | |
| 46 | // missing on some platforms (like XCode in Windows) | |
| 47 | case "ios": | |
bc7a32ceJimmy Thomson10 years ago | 48 | let ios: typeof IOSPlatform = require("./ios/iOSPlatform"); |
| 49 | return new ios.IOSPlatform(desktopPlatform); | |
f5ea0577unknown10 years ago | 50 | case "android": |
bc7a32ceJimmy Thomson10 years ago | 51 | let android: typeof AndroidPlatform = require("./android/androidPlatform"); |
| 52 | return new android.AndroidPlatform(desktopPlatform); | |
f5ea0577unknown10 years ago | 53 | default: |
3af9a124unknown10 years ago | 54 | return null; |
f5ea0577unknown10 years ago | 55 | } |
| 56 | } | |
| 57 | } |