microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/extension/exponent/exponentPlatform.ts
96lines · modeblame
0a68f8dbArtem Egorov8 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 | | |
031832ffArtem Egorov8 years ago | 4 | import { ErrorHelper } from "../../common/error/errorHelper"; |
| 5 | import { InternalErrorCode } from "../../common/error/internalErrorCode"; | |
| 6 | import { IRunOptions } from "../launchArgs"; | |
| 7 | import { GeneralMobilePlatform, MobilePlatformDeps } from "../generalMobilePlatform"; | |
| 8 | import { ExponentHelper } from "./exponentHelper"; | |
| 9 | import { TelemetryHelper } from "../../common/telemetryHelper"; | |
0a68f8dbArtem Egorov8 years ago | 10 | |
| 11 | import * as vscode from "vscode"; | |
| 12 | import * as Q from "q"; | |
4787ec09Artem Egorov8 years ago | 13 | import * as XDL from "./xdlInterface"; |
| 14 | import * as url from "url"; | |
0a68f8dbArtem Egorov8 years ago | 15 | |
| 16 | export class ExponentPlatform extends GeneralMobilePlatform { | |
| 17 | private exponentTunnelPath: string | null; | |
2e432a9eArtem Egorov8 years ago | 18 | private exponentHelper: ExponentHelper; |
0a68f8dbArtem Egorov8 years ago | 19 | |
| 20 | constructor(runOptions: IRunOptions, platformDeps: MobilePlatformDeps = {}) { | |
| 21 | super(runOptions, platformDeps); | |
2e432a9eArtem Egorov8 years ago | 22 | this.exponentHelper = new ExponentHelper(runOptions.workspaceRoot, runOptions.projectRoot); |
0a68f8dbArtem Egorov8 years ago | 23 | this.exponentTunnelPath = null; |
| 24 | } | |
| 25 | | |
| 26 | public runApp(): Q.Promise<void> { | |
031832ffArtem Egorov8 years ago | 27 | const extProps = { |
| 28 | platform: { | |
| 29 | value: "exponent", | |
| 30 | isPii: false, | |
4787ec09Artem Egorov8 years ago | 31 | }, |
031832ffArtem Egorov8 years ago | 32 | }; |
4787ec09Artem Egorov8 years ago | 33 | |
031832ffArtem Egorov8 years ago | 34 | return TelemetryHelper.generate("ExponentPlatform.runApp", extProps, () => { |
| 35 | return this.exponentHelper.loginToExponent( | |
| 36 | (message, password) => { | |
| 37 | return Q.Promise((resolve, reject) => { | |
| 38 | vscode.window.showInputBox({ placeHolder: message, password: password }) | |
| 39 | .then(login => { | |
| 40 | resolve(login || ""); | |
| 41 | }, reject); | |
| 42 | }); | |
| 43 | }, | |
| 44 | (message) => { | |
| 45 | return Q.Promise((resolve, reject) => { | |
| 46 | vscode.window.showInformationMessage(message) | |
| 47 | .then(password => { | |
| 48 | resolve(password || ""); | |
| 49 | }, reject); | |
| 50 | }); | |
| 51 | } | |
| 52 | ) | |
| 53 | .then(() => | |
| 54 | XDL.setOptions(this.projectPath, { packagerPort: this.packager.port }) | |
| 55 | ) | |
| 56 | .then(() => | |
| 57 | XDL.startExponentServer(this.projectPath) | |
| 58 | ) | |
| 59 | .then(() => | |
| 60 | XDL.startTunnels(this.projectPath) | |
| 61 | ) | |
| 62 | .then(() => | |
| 63 | XDL.getUrl(this.projectPath, { dev: true, minify: false }) | |
| 64 | ).then(exponentUrl => { | |
| 65 | return "exp://" + url.parse(exponentUrl).host; | |
| 66 | }) | |
| 67 | .catch(reason => { | |
| 68 | return Q.reject<string>(reason); | |
| 69 | }) | |
| 70 | .then(exponentUrl => { | |
| 71 | vscode.commands.executeCommand("vscode.previewHtml", vscode.Uri.parse(exponentUrl), 1, "Expo QR code"); | |
| 72 | return exponentUrl; | |
| 73 | }) | |
| 74 | .then(exponentUrl => { | |
| 75 | if (!exponentUrl) { | |
| 76 | return Q.reject<void>(ErrorHelper.getInternalError(InternalErrorCode.ExpectedExponentTunnelPath, | |
| 77 | "No link provided by exponent. Is your project correctly setup?")); | |
| 78 | } | |
| 79 | this.exponentTunnelPath = exponentUrl; | |
| 80 | const outputMessage = `Application is running on Exponent. Open your exponent app at ${this.exponentTunnelPath} to see it.`; | |
| 81 | this.logger.info(outputMessage); | |
| 82 | | |
| 83 | return Q.resolve(void 0); | |
| 84 | }); | |
4787ec09Artem Egorov8 years ago | 85 | }); |
| 86 | } | |
| 87 | | |
| 88 | public beforeStartPackager(): Q.Promise<void> { | |
| 89 | return this.exponentHelper.configureExponentEnvironment(); | |
0a68f8dbArtem Egorov8 years ago | 90 | } |
| 91 | | |
| 92 | public enableJSDebuggingMode(): Q.Promise<void> { | |
| 93 | this.logger.info("Application is running on Exponent. Please shake device and select 'Debug JS Remotely' to enable debugging."); | |
| 94 | return Q.resolve<void>(void 0); | |
| 95 | } | |
| 96 | } |