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