microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.7.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/exponent/exponentPlatform.ts

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