microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/appcenter/command/commandExecutor.ts

491lines · modeblame

bb45fbe6max-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 * as vscode from "vscode";
5import * as Q from "q";
6import * as qs from "qs";
7import * as os from "os";
8
9import { ILogger, LogLevel } from "../../log/LogHelper";
10import Auth from "../../appcenter/auth/auth";
2ceda59emax-mironov8 years ago11import { AppCenterLoginType, ACConstants, AppCenterOS, CurrentAppDeployments, Deployment, ACCommandNames } from "../appCenterConstants";
ef14e11bmax-mironov8 years ago12import { Profile } from "../../appcenter/auth/profile/profile";
bb45fbe6max-mironov8 years ago13import { SettingsHelper } from "../../settingsHelper";
e26df9e4max-mironov8 years ago14import { AppCenterClient, models } from "../api/index";
ff1d5ab0max-mironov8 years ago15import { DefaultApp, ICodePushReleaseParams } from "./commandParams";
640e6e98max-mironov8 years ago16import { AppCenterExtensionManager } from "../appCenterExtensionManager";
6a465861max-mironov8 years ago17import { ACStrings } from "../appCenterStrings";
bf370babSergey Akhalkov8 years ago18import CodePushRelease from "../codepush/release";
a653acfemax-mironov8 years ago19import { ACUtils } from "../helpers/utils";
9588b66eSergey Akhalkov8 years ago20import { updateContents, reactNative, fileUtils } from "codepush-node-sdk";
a446900cSergey Akhalkov8 years ago21import BundleConfig = reactNative.BundleConfig;
e26df9e4max-mironov8 years ago22import { getQPromisifiedClientResult } from "../api/createClient";
2ceda59emax-mironov8 years ago23import { validRange } from "semver";
24edcbd0max-mironov8 years ago24import { VsCodeUtils, IButtonMessageItem } from "../helpers/vscodeUtils";
bb45fbe6max-mironov8 years ago25
26interface IAppCenterAuth {
640e6e98max-mironov8 years ago27login(appcenterManager: AppCenterExtensionManager): Q.Promise<void>;
6a465861max-mironov8 years ago28logout(appcenterManager: AppCenterExtensionManager): Q.Promise<void>;
a653acfemax-mironov8 years ago29whoAmI(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
6a465861max-mironov8 years ago30}
31
32interface IAppCenterApps {
2ceda59emax-mironov8 years ago33getCurrentApp(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
e26df9e4max-mironov8 years ago34setCurrentApp(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
4a66f08bmax-mironov8 years ago35setCurrentDeployment(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
bb45fbe6max-mironov8 years ago36}
37
38interface IAppCenterCodePush {
ef14e11bmax-mironov8 years ago39showMenu(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
6a465861max-mironov8 years ago40releaseReact(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
2ceda59emax-mironov8 years ago41switchIsMandatoryForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
42setTargetBinaryVersionForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void>;
bb45fbe6max-mironov8 years ago43}
44
6a465861max-mironov8 years ago45export class AppCenterCommandExecutor implements IAppCenterAuth, IAppCenterCodePush, IAppCenterApps {
bb45fbe6max-mironov8 years ago46private logger: ILogger;
47
48constructor(logger: ILogger) {
49this.logger = logger;
50}
51
640e6e98max-mironov8 years ago52public login(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
b73e66f1max-mironov8 years ago53const appCenterLoginOptions: string[] = Object.keys(AppCenterLoginType).filter(k => typeof AppCenterLoginType[k as any] === "number");
6a465861max-mironov8 years ago54vscode.window.showQuickPick(appCenterLoginOptions, { placeHolder: ACStrings.SelectLoginTypeMsg })
ef14e11bmax-mironov8 years ago55.then((loginType) => {
56switch (loginType) {
57case (AppCenterLoginType[AppCenterLoginType.Interactive]):
24edcbd0max-mironov8 years ago58const messageItems: IButtonMessageItem[] = [];
59const loginUrl = `${SettingsHelper.getAppCenterLoginEndpoint()}?${qs.stringify({ hostname: os.hostname()})}`;
60messageItems.push({ title : ACStrings.OkBtnLabel,
61url : loginUrl });
62
63return VsCodeUtils.ShowInformationMessage(ACStrings.PleaseLoginViaBrowser, ...messageItems)
64.then((selection: IButtonMessageItem | undefined) => {
65if (selection) {
ef14e11bmax-mironov8 years ago66return vscode.window.showInputBox({ prompt: ACStrings.PleaseProvideToken, ignoreFocusOut: true })
67.then(token => {
68this.loginWithToken(token, appCenterManager);
69});
70} else return Q.resolve(void 0);
71});
72case (AppCenterLoginType[AppCenterLoginType.Token]):
73return vscode.window.showInputBox({ prompt: ACStrings.PleaseProvideToken , ignoreFocusOut: true})
74.then(token => {
75return this.loginWithToken(token, appCenterManager);
76});
77default:
78// User canel login otherwise
79return Q.resolve(void 0);
80}
bb45fbe6max-mironov8 years ago81});
b73e66f1max-mironov8 years ago82return Q.resolve(void 0);
bb45fbe6max-mironov8 years ago83}
84
6a465861max-mironov8 years ago85public logout(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
2ceda59emax-mironov8 years ago86return Auth.doLogout(appCenterManager.projectRootPath).then(() => {
24edcbd0max-mironov8 years ago87VsCodeUtils.ShowInformationMessage(ACStrings.UserLoggedOutMsg);
ef14e11bmax-mironov8 years ago88return appCenterManager.setupAppCenterStatusBar(null);
89}).catch(() => {
90this.logger.log("An errro occured on logout", LogLevel.Error);
91});
bb45fbe6max-mironov8 years ago92}
93
a653acfemax-mironov8 years ago94public whoAmI(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
95return Auth.getProfile(appCenterManager.projectRootPath).then((profile: Profile | null) => {
96if (profile && profile.displayName) {
24edcbd0max-mironov8 years ago97VsCodeUtils.ShowInformationMessage(ACStrings.YouAreLoggedInMsg(profile.displayName));
a653acfemax-mironov8 years ago98} else {
24edcbd0max-mironov8 years ago99VsCodeUtils.ShowInformationMessage(ACStrings.UserIsNotLoggedInMsg);
a653acfemax-mironov8 years ago100}
24edcbd0max-mironov8 years ago101return Q.resolve(void 0);
a653acfemax-mironov8 years ago102});
bb45fbe6max-mironov8 years ago103}
104
4a66f08bmax-mironov8 years ago105public setCurrentDeployment(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
2ceda59emax-mironov8 years ago106this.restoreCurrentApp(appCenterManager.projectRootPath)
107.then((currentApp: DefaultApp) => {
108if (currentApp && currentApp.currentAppDeployments && currentApp.currentAppDeployments.codePushDeployments) {
109const deploymentOptions: string[] = currentApp.currentAppDeployments.codePushDeployments.map((deployment) => {
110return deployment.name;
111});
112vscode.window.showQuickPick(deploymentOptions, { placeHolder: ACStrings.SelectCurrentDeploymentMsg })
113.then((deploymentName) => {
114if (deploymentName) {
115this.saveCurrentApp(
116appCenterManager.projectRootPath,
117currentApp.identifier,
118AppCenterOS[currentApp.os], {
119currentDeploymentName: deploymentName,
120codePushDeployments: currentApp.currentAppDeployments.codePushDeployments,
121},
122currentApp.targetBinaryVersion,
123currentApp.isMandatory
124);
4a66f08bmax-mironov8 years ago125}
126});
127}
128});
129return Q.resolve(void 0);
130}
131
2ceda59emax-mironov8 years ago132public getCurrentApp(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
133this.restoreCurrentApp(appCenterManager.projectRootPath).then((app: DefaultApp) => {
84abb0c7max-mironov8 years ago134if (app) {
24edcbd0max-mironov8 years ago135VsCodeUtils.ShowInformationMessage(ACStrings.YourCurrentAppMsg(app.identifier));
84abb0c7max-mironov8 years ago136} else {
24edcbd0max-mironov8 years ago137VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
84abb0c7max-mironov8 years ago138}
86466695max-mironov8 years ago139});
6a465861max-mironov8 years ago140return Q.resolve(void 0);
bb45fbe6max-mironov8 years ago141}
640e6e98max-mironov8 years ago142
e26df9e4max-mironov8 years ago143public setCurrentApp(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
7574c61amax-mironov8 years ago144vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Get Apps"}, p => {
145return new Promise((resolve, reject) => {
146p.report({message: ACStrings.FetchAppsStatusBarMessage });
147getQPromisifiedClientResult(client.account.apps.list()).then((apps: models.AppResponse[]) => {
148const appsList: models.AppResponse[] = apps;
149const reactNativeApps = appsList.filter(app => app.platform === ACConstants.AppCenterReactNativePlatformName);
150resolve(reactNativeApps);
151});
152});
153}).then((rnApps: models.AppResponse[]) => {
154let options = rnApps.map(app => {
e26df9e4max-mironov8 years ago155return {
156label: `${app.name} (${app.os})`,
157description: app.displayName,
158target: app.name,
159};
160});
161vscode.window.showQuickPick(options, { placeHolder: ACStrings.ProvideCurrentAppPromptMsg })
162.then((selected: {label: string, description: string, target: string}) => {
163if (selected) {
7574c61amax-mironov8 years ago164const selectedApps: models.AppResponse[] = rnApps.filter(app => app.name === selected.target);
e26df9e4max-mironov8 years ago165if (selectedApps && selectedApps.length === 1) {
166const selectedApp: models.AppResponse = selectedApps[0];
167const selectedAppName: string = `${selectedApp.owner.name}/${selectedApp.name}`;
2ceda59emax-mironov8 years ago168const OS: AppCenterOS = AppCenterOS[selectedApp.os.toLowerCase()];
7574c61amax-mironov8 years ago169
170vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Get Deployments"}, p => {
171return new Promise((resolve, reject) => {
172p.report({message: ACStrings.FetchDeploymentsStatusBarMessage });
173getQPromisifiedClientResult(client.codepush.codePushDeployments.list(selectedApp.name, selectedApp.owner.name))
174.then((deployments: models.Deployment[]) => {
ef14e11bmax-mironov8 years ago175resolve(deployments.sort((a, b): any => {
176return a.name < b.name; // sort alphabetically
177}));
7574c61amax-mironov8 years ago178});
179});
ef14e11bmax-mironov8 years ago180})
181.then((appDeployments: models.Deployment[]) => {
182let currentDeployments: CurrentAppDeployments | null = null;
7574c61amax-mironov8 years ago183if (appDeployments.length > 0) {
2ceda59emax-mironov8 years ago184const deployments: Deployment[] = appDeployments.map((d) => {
185return {
186name: d.name,
187};
188});
ef14e11bmax-mironov8 years ago189currentDeployments = {
2ceda59emax-mironov8 years ago190codePushDeployments: deployments,
7574c61amax-mironov8 years ago191currentDeploymentName: appDeployments[0].name, // Select 1st one by default
4a66f08bmax-mironov8 years ago192};
e26df9e4max-mironov8 years ago193}
2ceda59emax-mironov8 years ago194this.saveCurrentApp(
195appCenterManager.projectRootPath,
196selectedAppName,
197OS,
198currentDeployments,
199ACConstants.AppCenterDefaultTargetBinaryVersion,
200ACConstants.AppCenterDefaultIsMandatoryParam)
ef14e11bmax-mironov8 years ago201.then((app: DefaultApp | null) => {
4a66f08bmax-mironov8 years ago202if (app) {
24edcbd0max-mironov8 years ago203return VsCodeUtils.ShowInformationMessage(ACStrings.YourCurrentAppAndDeployemntMsg(selected.target
ef14e11bmax-mironov8 years ago204, app.currentAppDeployments.currentDeploymentName));
205} else {
206this.logger.error("Failed to save current app");
207return Q.resolve(void 0);
4a66f08bmax-mironov8 years ago208}
209});
e26df9e4max-mironov8 years ago210});
211}
bb685befmax-mironov8 years ago212}
213});
214});
7574c61amax-mironov8 years ago215return Q.resolve(void 0);
640e6e98max-mironov8 years ago216}
6a465861max-mironov8 years ago217
218public releaseReact(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
fbbc4447Sergey Akhalkov8 years ago219let codePushRelaseParams = <ICodePushReleaseParams>{};
220const projectRootPath: string = appCenterManager.projectRootPath;
9588b66eSergey Akhalkov8 years ago221return Q.Promise<any>((resolve, reject) => {
2ceda59emax-mironov8 years ago222let updateContentsDirectory: string;
223let isMandatory: boolean;
9588b66eSergey Akhalkov8 years ago224vscode.window.withProgress({ location: vscode.ProgressLocation.Window, title: "Get Apps" }, p => {
225return new Promise<DefaultApp>((appResolve, appReject) => {
226p.report({ message: ACStrings.GettingAppInfoMessage });
2ceda59emax-mironov8 years ago227this.restoreCurrentApp(appCenterManager.projectRootPath)
9588b66eSergey Akhalkov8 years ago228.then((currentApp: DefaultApp) => appResolve(<DefaultApp>currentApp))
229.catch(err => appReject(err));
230}).then((currentApp: DefaultApp): any => {
231p.report({ message: ACStrings.DetectingAppVersionMessage });
232if (!currentApp) {
ef14e11bmax-mironov8 years ago233throw new Error(`No current app has been specified.`);
9588b66eSergey Akhalkov8 years ago234}
2ceda59emax-mironov8 years ago235if (!currentApp.os || !reactNative.isValidOS(currentApp.os)) {
ef14e11bmax-mironov8 years ago236throw new Error(`OS must be "android", "ios", or "windows".`);
9588b66eSergey Akhalkov8 years ago237}
238codePushRelaseParams.app = currentApp;
ef14e11bmax-mironov8 years ago239codePushRelaseParams.deploymentName = currentApp.currentAppDeployments.currentDeploymentName;
9588b66eSergey Akhalkov8 years ago240currentApp.os = currentApp.os.toLowerCase();
2ceda59emax-mironov8 years ago241isMandatory = !!currentApp.isMandatory;
242if (currentApp.targetBinaryVersion !== ACConstants.AppCenterDefaultTargetBinaryVersion) {
243return currentApp.targetBinaryVersion;
244} else {
245switch (currentApp.os) {
246case "android": return reactNative.getAndroidAppVersion(projectRootPath);
247case "ios": return reactNative.getiOSAppVersion(projectRootPath);
248case "windows": return reactNative.getWindowsAppVersion(projectRootPath);
249default: throw new Error(`OS must be "android", "ios", or "windows".`);
250}
9588b66eSergey Akhalkov8 years ago251}
252}).then((appVersion: string) => {
253p.report({ message: ACStrings.RunningReactNativeBundleCommandMessage });
254codePushRelaseParams.appVersion = appVersion;
255return reactNative.makeUpdateContents(<BundleConfig>{
256os: codePushRelaseParams.app.os,
257projectRootPath: projectRootPath,
258});
259}).then((pathToUpdateContents: string) => {
260p.report({ message: ACStrings.ArchivingUpdateContentsMessage });
261updateContentsDirectory = pathToUpdateContents;
2ceda59emax-mironov8 years ago262this.logger.log(`CodePush updated contents directory path: ${updateContentsDirectory}`, LogLevel.Debug);
9588b66eSergey Akhalkov8 years ago263return updateContents.zip(pathToUpdateContents, projectRootPath);
264}).then((pathToZippedBundle: string) => {
265p.report({ message: ACStrings.ReleasingUpdateContentsMessage });
266codePushRelaseParams.updatedContentZipPath = pathToZippedBundle;
2ceda59emax-mironov8 years ago267codePushRelaseParams.isMandatory = isMandatory;
9588b66eSergey Akhalkov8 years ago268return new Promise<any>((publishResolve, publishReject) => {
bf370babSergey Akhalkov8 years ago269Auth.getProfile(projectRootPath)
270.then((profile: Profile) => {
774e7f5fSergey Akhalkov8 years ago271return profile.accessToken;
272}).then((token: string) => {
273codePushRelaseParams.token = token;
bf370babSergey Akhalkov8 years ago274return CodePushRelease.exec(client, codePushRelaseParams, this.logger);
275}).then((response: any) => publishResolve(response))
9588b66eSergey Akhalkov8 years ago276.catch((error: any) => publishReject(error));
277});
278}).then((response: any) => {
279if (response.succeeded && response.result) {
24edcbd0max-mironov8 years ago280VsCodeUtils.ShowInformationMessage(`Successfully released an update to the "${codePushRelaseParams.deploymentName}" deployment of the "${codePushRelaseParams.app.appName}" app`);
9588b66eSergey Akhalkov8 years ago281resolve(response.result);
282} else {
24edcbd0max-mironov8 years ago283VsCodeUtils.ShowErrorMessage(response.errorMessage);
9588b66eSergey Akhalkov8 years ago284}
285fileUtils.rmDir(codePushRelaseParams.updatedContentZipPath);
286}).catch((error: Error) => {
ef14e11bmax-mironov8 years ago287if (error && error.message) {
24edcbd0max-mironov8 years ago288VsCodeUtils.ShowErrorMessage(`An error occured on doing Code Push release. ${error.message}`);
ef14e11bmax-mironov8 years ago289} else {
24edcbd0max-mironov8 years ago290VsCodeUtils.ShowErrorMessage("An error occured on doing Code Push release");
ef14e11bmax-mironov8 years ago291}
292
9588b66eSergey Akhalkov8 years ago293fileUtils.rmDir(codePushRelaseParams.updatedContentZipPath);
42b1aa55Sergey Akhalkov8 years ago294});
9588b66eSergey Akhalkov8 years ago295});
ff1d5ab0max-mironov8 years ago296});
6a465861max-mironov8 years ago297}
298
ef14e11bmax-mironov8 years ago299public showMenu(client: AppCenterClient, appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
2ceda59emax-mironov8 years ago300return Auth.getProfile(appCenterManager.projectRootPath).then((profile: Profile | null) => {
ef14e11bmax-mironov8 years ago301let defaultApp: DefaultApp | null = null;
302if (profile && profile.defaultApp) {
303defaultApp = profile.defaultApp;
304}
2ceda59emax-mironov8 years ago305let menuPlaceHolederTitle = ACStrings.MenuTitlePlaceholder;
ef14e11bmax-mironov8 years ago306let appCenterMenuOptions = [
307{
2ceda59emax-mironov8 years ago308label: ACStrings.ReleaseReactMenuText(defaultApp),
309description: "",
ef14e11bmax-mironov8 years ago310target: ACCommandNames.CodePushReleaseReact,
311},
312{
2ceda59emax-mironov8 years ago313label: ACStrings.SetCurrentAppMenuText(defaultApp),
314description: "",
ef14e11bmax-mironov8 years ago315target: ACCommandNames.SetCurrentApp,
316},
317{
318label: ACStrings.LogoutMenuLabel,
2ceda59emax-mironov8 years ago319description: "",
ef14e11bmax-mironov8 years ago320target: ACCommandNames.Logout,
321},
322];
323
324// This item is avaliable only if we have specified app already
2ceda59emax-mironov8 years ago325if (defaultApp && defaultApp.currentAppDeployments) {
ef14e11bmax-mironov8 years ago326// Let logout command be always the last one in the list
327appCenterMenuOptions.splice(appCenterMenuOptions.length - 1, 0,
328{
2ceda59emax-mironov8 years ago329label: ACStrings.SetCurrentAppDeploymentText(defaultApp),
330description: "",
ef14e11bmax-mironov8 years ago331target: ACCommandNames.SetCurrentDeployment,
332}
333);
2ceda59emax-mironov8 years ago334appCenterMenuOptions.splice(appCenterMenuOptions.length - 1, 0,
335{
336label: ACStrings.SetCurrentAppTargetBinaryVersionText(defaultApp),
337description: "",
338target: ACCommandNames.SetTargetBinaryVersionForRelease,
339}
340);
341appCenterMenuOptions.splice(appCenterMenuOptions.length - 1, 0,
342{
343label: ACStrings.SetCurrentAppIsMandatoryText(defaultApp),
344description: "",
345target: ACCommandNames.SwitchMandatoryPropertyForRelease,
346}
347);
ef14e11bmax-mironov8 years ago348}
349
350return vscode.window.showQuickPick(appCenterMenuOptions, { placeHolder: menuPlaceHolederTitle })
351.then((selected: {label: string, description: string, target: string}) => {
352if (!selected) {
353// user cancel selection
354return Q.resolve(void 0);
355}
356switch (selected.target) {
357case (ACCommandNames.SetCurrentApp):
358return this.setCurrentApp(client, appCenterManager);
359
360case (ACCommandNames.SetCurrentDeployment):
361return this.setCurrentDeployment(appCenterManager);
362
363case (ACCommandNames.CodePushReleaseReact):
364return this.releaseReact(client, appCenterManager);
365
2ceda59emax-mironov8 years ago366case (ACCommandNames.SetTargetBinaryVersionForRelease):
367return this.setTargetBinaryVersionForRelease(appCenterManager);
368
369case (ACCommandNames.SwitchMandatoryPropertyForRelease):
370return this.switchIsMandatoryForRelease(appCenterManager);
371
ef14e11bmax-mironov8 years ago372case (ACCommandNames.Logout):
373return this.logout(appCenterManager);
374
375default:
376// Ideally shouldn't be there :)
377this.logger.error("Unknown appcenter show menu command");
378return Q.resolve(void 0);
379}
380});
381});
382}
383
2ceda59emax-mironov8 years ago384public switchIsMandatoryForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
385this.restoreCurrentApp(appCenterManager.projectRootPath).then((app: DefaultApp) => {
386if (app) {
387const newMandatoryValue = !!!app.isMandatory;
388const osVal: AppCenterOS = AppCenterOS[app.os];
389this.saveCurrentApp(
390appCenterManager.projectRootPath,
391app.identifier,
392osVal, {
393currentDeploymentName: app.currentAppDeployments.currentDeploymentName,
394codePushDeployments: app.currentAppDeployments.codePushDeployments,
395},
396app.targetBinaryVersion,
397newMandatoryValue
398).then(() => {
24edcbd0max-mironov8 years ago399VsCodeUtils.ShowInformationMessage(`Changed release to ${newMandatoryValue ? "Mandotory" : "NOT Mandatory"}`);
2ceda59emax-mironov8 years ago400});
401} else {
24edcbd0max-mironov8 years ago402VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
2ceda59emax-mironov8 years ago403}
404});
405return Q.resolve(void 0);
406}
407
408public setTargetBinaryVersionForRelease(appCenterManager: AppCenterExtensionManager): Q.Promise<void> {
409vscode.window.showInputBox({ prompt: ACStrings.PleaseProvideTargetBinaryVersion, ignoreFocusOut: true })
410.then(appVersion => {
24edcbd0max-mironov8 years ago411if (appVersion === ACConstants.AppCenterDefaultTargetBinaryVersion || (appVersion && !!validRange(appVersion))) {
2ceda59emax-mironov8 years ago412return this.restoreCurrentApp(appCenterManager.projectRootPath).then((app: DefaultApp) => {
413if (app) {
414return this.saveCurrentApp(
415appCenterManager.projectRootPath,
416app.identifier,
417AppCenterOS[app.os], {
418currentDeploymentName: app.currentAppDeployments.currentDeploymentName,
419codePushDeployments: app.currentAppDeployments.codePushDeployments,
420},
421appVersion,
422app.isMandatory
423).then(() => {
24edcbd0max-mironov8 years ago424if (appVersion) {
425VsCodeUtils.ShowInformationMessage(`Changed target binary version to '${appVersion}'`);
426} else {
427VsCodeUtils.ShowInformationMessage(`Changed target binary version to automatically fetched`);
428}
2ceda59emax-mironov8 years ago429});
430} else {
24edcbd0max-mironov8 years ago431VsCodeUtils.ShowInformationMessage(ACStrings.NoCurrentAppSetMsg);
2ceda59emax-mironov8 years ago432return Q.resolve(void 0);
433}
434});
435} else {
24edcbd0max-mironov8 years ago436VsCodeUtils.ShowWarningMessage(ACStrings.InvalidAppVersionParamMsg);
2ceda59emax-mironov8 years ago437return Q.resolve(void 0);
438}
439});
440return Q.resolve(void 0);
441}
442
443private saveCurrentApp(projectRootPath: string,
444currentAppName: string,
445appOS: AppCenterOS,
446currentAppDeployments: CurrentAppDeployments | null,
447targetBinaryVersion: string,
448isMandatory: boolean): Q.Promise<DefaultApp | null> {
449const defaultApp = ACUtils.toDefaultApp(currentAppName, appOS, currentAppDeployments, targetBinaryVersion, isMandatory);
bb685befmax-mironov8 years ago450if (!defaultApp) {
24edcbd0max-mironov8 years ago451VsCodeUtils.ShowWarningMessage(ACStrings.InvalidCurrentAppNameMsg);
e26df9e4max-mironov8 years ago452return Q.resolve(null);
bb685befmax-mironov8 years ago453}
65b8d098max-mironov8 years ago454
2ceda59emax-mironov8 years ago455return Auth.getProfile(projectRootPath).then((profile: Profile | null) => {
ef14e11bmax-mironov8 years ago456if (profile) {
457profile.defaultApp = defaultApp;
2ceda59emax-mironov8 years ago458profile.save(projectRootPath);
ef14e11bmax-mironov8 years ago459return Q.resolve(defaultApp);
460} else {
461// No profile - not logged in?
24edcbd0max-mironov8 years ago462VsCodeUtils.ShowWarningMessage(ACStrings.UserIsNotLoggedInMsg);
ef14e11bmax-mironov8 years ago463return Q.resolve(null);
464}
465});
bb685befmax-mironov8 years ago466}
467
2ceda59emax-mironov8 years ago468private restoreCurrentApp(projectRootPath: string): Q.Promise<DefaultApp | null> {
469return Auth.getProfile(projectRootPath).then((profile: Profile | null) => {
ef14e11bmax-mironov8 years ago470if (profile && profile.defaultApp) {
471return Q.resolve(profile.defaultApp);
bb685befmax-mironov8 years ago472}
ef14e11bmax-mironov8 years ago473return Q.resolve(null);
474});
6a465861max-mironov8 years ago475}
476
ff1d5ab0max-mironov8 years ago477private loginWithToken(token: string | undefined, appCenterManager: AppCenterExtensionManager) {
478if (!token) {
479return;
480}
2ceda59emax-mironov8 years ago481return Auth.doTokenLogin(token, appCenterManager.projectRootPath).then((profile: Profile) => {
84abb0c7max-mironov8 years ago482if (!profile) {
483this.logger.log("Failed to fetch user info from server", LogLevel.Error);
24edcbd0max-mironov8 years ago484VsCodeUtils.ShowWarningMessage(ACStrings.FailedToExecuteLoginMsg);
84abb0c7max-mironov8 years ago485return;
486}
24edcbd0max-mironov8 years ago487VsCodeUtils.ShowInformationMessage(ACStrings.YouAreLoggedInMsg(profile.displayName));
ef14e11bmax-mironov8 years ago488return appCenterManager.setupAppCenterStatusBar(profile);
6a465861max-mironov8 years ago489});
490}
bb45fbe6max-mironov8 years ago491}