UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

97 lines (96 loc) 5.2 kB
"use strict"; // apps create command var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const commandline_1 = require("../../util/commandline"); const interaction_1 = require("../../util/interaction"); const format_app_1 = require("./lib/format-app"); const app_release_type_validation_1 = require("./lib/app-release-type-validation"); let AppUpdateCommand = class AppUpdateCommand extends commandline_1.AppCommand { constructor(args) { super(args); } run(client) { return __awaiter(this, void 0, void 0, function* () { const appAttributes = {}; if (this.description) { appAttributes.description = this.description; } if (this.displayName) { appAttributes.displayName = this.displayName; } if (this.name) { appAttributes.name = this.name; } if (this.release_type) { if (this.release_type.length > app_release_type_validation_1.APP_RELEASE_TYPE_VALIDATIONS.maxLength.rule) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, app_release_type_validation_1.APP_RELEASE_TYPE_VALIDATIONS.maxLength.errorMessage); } if (!app_release_type_validation_1.APP_RELEASE_TYPE_VALIDATIONS.matchRegexp.rule.test(this.release_type)) { return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, app_release_type_validation_1.APP_RELEASE_TYPE_VALIDATIONS.matchRegexp.errorMessage); } appAttributes.releaseType = this.release_type; } const app = this.app; try { const updateAppResponse = yield interaction_1.out.progress("Updating app ...", client.apps.update(app.ownerName, app.appName)); format_app_1.reportApp(updateAppResponse); } catch (error) { const statusCode = error.response.status; if (statusCode >= 400) { switch (statusCode) { case 400: return commandline_1.failure(commandline_1.ErrorCodes.Exception, "the request was rejected for an unknown reason"); case 404: return commandline_1.failure(commandline_1.ErrorCodes.NotLoggedIn, `the app "${app.identifier}" could not be found`); case 409: return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, `an app with the "name" ${app.appName} already exists`); } } } return commandline_1.success(); }); } }; __decorate([ commandline_1.help("Description of the app"), commandline_1.longName("description"), commandline_1.hasArg ], AppUpdateCommand.prototype, "description", void 0); __decorate([ commandline_1.help("The descriptive name of the app. This can contain any characters."), commandline_1.shortName("d"), commandline_1.longName("display-name"), commandline_1.hasArg ], AppUpdateCommand.prototype, "displayName", void 0); __decorate([ commandline_1.help("The name of the app used in URLs."), commandline_1.shortName("n"), commandline_1.longName("name"), commandline_1.hasArg ], AppUpdateCommand.prototype, "name", void 0); __decorate([ commandline_1.help("The app release type. Suggested values are Alpha, Beta, Production, Store, Enterprise. Custom values are allowed and must be must be one word, alphanumeric, first letter capitalized."), commandline_1.shortName("r"), commandline_1.longName("release-type"), commandline_1.hasArg ], AppUpdateCommand.prototype, "release_type", void 0); AppUpdateCommand = __decorate([ commandline_1.help("Update an app") ], AppUpdateCommand); exports.default = AppUpdateCommand;