UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

99 lines (98 loc) 5.38 kB
"use strict"; 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 commandline_2 = require("../../util/commandline"); const commandline_3 = require("../../util/commandline"); const interaction_1 = require("../../util/interaction"); const util_1 = require("util"); const symbols_uploading_helper_1 = require("./lib/symbols-uploading-helper"); const symbols_uploading_helper_2 = require("./lib/symbols-uploading-helper"); const Fs = require("fs"); const Path = require("path"); const _ = require("lodash"); const debug = require("debug")("appcenter-cli:commands:apps:crashes:upload-mappings"); let UploadMappings = class UploadMappings extends commandline_1.AppCommand { run(client) { return __awaiter(this, void 0, void 0, function* () { const app = this.app; this.validateParameters(); this.getStatsForFsPath(this.mappingPath); if (Path.extname(this.mappingPath).toLowerCase() !== ".txt") { throw commandline_2.failure(commandline_2.ErrorCodes.InvalidParameter, `path ${this.mappingPath} does not point to valid mapping file – only .txt files are supported`); } const uploadRequest = { symbolType: symbols_uploading_helper_2.SymbolType.AndroidProGuard, fileName: Path.basename(this.mappingPath), version: this.versionName, build: String(this.versionCode), }; // upload mappings yield interaction_1.out.progress("Uploading mappings...", new symbols_uploading_helper_1.default(client, app, debug).uploadSymbolsArtifact(this.mappingPath, uploadRequest)); return commandline_2.success(); }); } getStatsForFsPath(filePath) { // take fs entry stats (and check it's existence BTW) try { debug(`Getting FS statistics for ${filePath}`); return Fs.statSync(filePath); } catch (error) { if (error.code === "ENOENT") { // path points to non-existing file system entry throw commandline_2.failure(commandline_2.ErrorCodes.InvalidParameter, `path ${filePath} points to non-existent item`); } else { // other errors debug(`Failed to get statistics for file system entry ${filePath} - ${util_1.inspect(error)}`); throw commandline_2.failure(commandline_2.ErrorCodes.Exception, `failed to get statistics for file system entry ${filePath}`); } } } validateParameters() { // check that user have selected all of --mapping, --version-name, and --version-code if (_.isNil(this.mappingPath) || _.isNil(this.versionName) || _.isNil(this.versionCode)) { throw commandline_2.failure(commandline_2.ErrorCodes.InvalidParameter, "all of '--mapping|-m', '--version-name|-n', and '--version-code|-c' are required"); } else if (Number.parseInt(this.versionCode, 10) <= 0) { throw commandline_2.failure(commandline_2.ErrorCodes.InvalidParameter, "--version-code|-c must be a positive non-zero integer"); } } }; __decorate([ commandline_3.help("Path to an Android mapping.txt file."), commandline_3.shortName("m"), commandline_3.longName("mapping"), commandline_3.hasArg ], UploadMappings.prototype, "mappingPath", void 0); __decorate([ commandline_3.help("The version name to associate with the mappings."), commandline_3.shortName("n"), commandline_3.longName("version-name"), commandline_3.hasArg ], UploadMappings.prototype, "versionName", void 0); __decorate([ commandline_3.help("The version code to associate with the mappings."), commandline_3.shortName("c"), commandline_3.longName("version-code"), commandline_3.hasArg ], UploadMappings.prototype, "versionCode", void 0); UploadMappings = __decorate([ commandline_3.help("Upload the Android mappings for the application") ], UploadMappings); exports.default = UploadMappings;