UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

112 lines (111 loc) 6.05 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"); const debug = require("debug")("appcenter-cli:commands:apps:create"); const util_1 = require("util"); let AppCreateCommand = class AppCreateCommand extends commandline_1.Command { constructor(args) { super(args); } run(client) { var _a; return __awaiter(this, void 0, void 0, function* () { const appAttributes = { displayName: this.displayName, platform: this.platform, os: this.os, description: this.description, 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; } debug(`Creating app with attributes: ${util_1.inspect(appAttributes)}`); try { const createAppResponse = yield interaction_1.out.progress("Creating app ...", client.apps.create(appAttributes)); format_app_1.reportApp(createAppResponse); } catch (error) { const statusCode = (_a = error.response) === null || _a === void 0 ? void 0 : _a.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.NotFound, "there appears to be no such user"); case 409: return commandline_1.failure(commandline_1.ErrorCodes.InvalidParameter, "an app with this 'name' already exists"); } } } return commandline_1.success(); }); } }; __decorate([ commandline_1.help("Description of the app"), commandline_1.longName("description"), commandline_1.hasArg ], AppCreateCommand.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.required, commandline_1.hasArg ], AppCreateCommand.prototype, "displayName", void 0); __decorate([ commandline_1.help("The name of the app used in URLs. Can optionally be provided specifically, otherwise a generated name will be derived from display-name"), commandline_1.shortName("n"), commandline_1.longName("name"), commandline_1.hasArg ], AppCreateCommand.prototype, "name", void 0); __decorate([ commandline_1.help("The OS the app will be running on. Supported values: Android, Custom, iOS, macOS, tvOS, Windows"), commandline_1.shortName("o"), commandline_1.longName("os"), commandline_1.required, commandline_1.hasArg ], AppCreateCommand.prototype, "os", void 0); __decorate([ commandline_1.help("The platform of the app. Supported values: Cordova, Java, Objective-C-Swift, React-Native, Unity, UWP, WinForms, WPF, Xamarin, Custom"), commandline_1.shortName("p"), commandline_1.longName("platform"), commandline_1.required, commandline_1.hasArg ], AppCreateCommand.prototype, "platform", 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 ], AppCreateCommand.prototype, "release_type", void 0); AppCreateCommand = __decorate([ commandline_1.help("Create a new app") ], AppCreateCommand); exports.default = AppCreateCommand;