microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
42b1aa5553c67930776e5dccc6981ba25a79e2ec

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/appcenter/appCenterCommandPalleteHandler.ts

96lines · 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 { ILogger, LogLevel } from "../log/LogHelper";
5import * as Q from "q";
6import { AppCenterCommandExecutor } from "./command/commandExecutor";
7import Auth from "../appcenter/auth/auth";
8import * as vscode from "vscode";
9import { AppCenterClient } from "./api/index";
10import { getUser, Profile } from "./auth/profile/profile";
11import { AppCenterClientFactory, createAppCenterClient } from "./api/createClient";
12import { SettingsHelper } from "../settingsHelper";
13import { AppCenterCommandType } from "./appCenterConstants";
14import { AppCenterExtensionManager } from "./appCenterExtensionManager";
15import { ACStrings } from "./appCenterStrings";
16import { ACUtils } from "./appCenterUtils";
17
18export class AppCenterCommandPalleteHandler {
19 private commandExecutor: AppCenterCommandExecutor;
20 private client: AppCenterClient;
21 private logger: ILogger;
22 private clientFactory: AppCenterClientFactory;
23 private appCenterManager: AppCenterExtensionManager;
24
25 constructor(logger: ILogger) {
26 this.commandExecutor = new AppCenterCommandExecutor(logger);
27 this.clientFactory = createAppCenterClient();
28 this.logger = logger;
29 }
30
31 public set AppCenterManager(manager: AppCenterExtensionManager) {
32 this.appCenterManager = manager;
33 }
34
35 public run(command: AppCenterCommandType): Q.Promise<void> {
36 if (!ACUtils.isCodePushProject(this.appCenterManager.projectRootPath)) {
37 vscode.window.showInformationMessage(ACStrings.NoCodePushDetectedMsg);
38 return Q.resolve(void 0);
39 }
40
41 // Login is special case
42 if (command === AppCenterCommandType.Login) {
43 return this.commandExecutor.login(this.appCenterManager);
44 }
45
46 return Auth.whoAmI().then((profile: Profile) => {
47 if (!profile) {
48 vscode.window.showInformationMessage(ACStrings.UserIsNotLoggedInMsg);
49 return Q.resolve(void 0);
50 } else {
51 const clientOrNull: AppCenterClient | null = this.resolveAppCenterClient();
52 if (clientOrNull) {
53 this.client = clientOrNull;
54
55 switch (command) {
56 case (AppCenterCommandType.Logout):
57 return this.commandExecutor.logout(this.appCenterManager);
58
59 case (AppCenterCommandType.Whoami):
60 return this.commandExecutor.whoAmI(profile);
61
62 case (AppCenterCommandType.SetCurrentApp):
63 return this.commandExecutor.setCurrentApp(this.client, this.appCenterManager);
64
65 case (AppCenterCommandType.GetCurrentApp):
66 return this.commandExecutor.getCurrentApp();
67
68 case (AppCenterCommandType.SetCurrentDeployment):
69 return this.commandExecutor.setCurrentDeployment(this.appCenterManager);
70
71 case (AppCenterCommandType.CodePushReleaseReact):
72 return this.commandExecutor.releaseReact(this.client, this.appCenterManager);
73
74 default:
75 throw new Error("Unknown App Center command!");
76 }
77 } else {
78 this.logger.log("Failed to get App Center client", LogLevel.Error);
79 throw new Error("Failed to get App Center client!");
80 }
81 }
82 });
83 }
84
85 private resolveAppCenterClient(): AppCenterClient | null {
86 if (!this.client) {
87 const user = getUser();
88 if (user) {
89 return this.clientFactory.fromProfile(user, SettingsHelper.getAppCenterAPIEndpoint());
90 } else {
91 throw new Error("No App Center user specified");
92 }
93 }
94 return this.client;
95 }
96}