microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.8

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/appcenter/appCenterCommandPalleteHandler.ts

106lines · modeblame

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