appcenter-cli
Version:
Command line tool for Visual Studio App Center
73 lines (72 loc) • 4.19 kB
JavaScript
;
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 util_1 = require("util");
const Os = require("os");
const date_parsing_helper_1 = require("./lib/date-parsing-helper");
const analytics_constants_1 = require("./lib/analytics-constants");
const debug = require("debug")("appcenter-cli:commands:analytics:app-versions");
let ShowAppVersionsCommand = class ShowAppVersionsCommand extends commandline_1.AppCommand {
run(client) {
return __awaiter(this, void 0, void 0, function* () {
const app = this.app;
const startDate = date_parsing_helper_1.parseDate(this.startDate, new Date(new Date().setHours(0, 0, 0, 0)), `start date value ${this.startDate} is not a valid date string`);
const endDate = date_parsing_helper_1.parseDate(this.endDate, new Date(), `end date value ${this.endDate} is not a valid date string`);
let listOfVersions;
try {
const result = yield interaction_1.out.progress("Getting list of application versions...", client.analytics.versions(startDate, app.ownerName, app.appName, {
end: endDate,
}));
listOfVersions = result.versions;
}
catch (error) {
debug(`Failed to get list of application versions - ${util_1.inspect(error)}`);
throw commandline_1.failure(commandline_1.ErrorCodes.Exception, "failed to get list of application versions");
}
if (this.devices) {
const outputArray = listOfVersions.map((version) => [version.version, String(version.count)]);
interaction_1.out.table(interaction_1.out.getCommandOutputTableOptions(["Version", "Number Of Devices"]), outputArray);
}
else {
interaction_1.out.text((versions) => versions.join(Os.EOL), listOfVersions.map((version) => version.version));
}
return commandline_1.success();
});
}
};
__decorate([
commandline_1.help(analytics_constants_1.startDateHelpMessage),
commandline_1.shortName("s"),
commandline_1.longName("start"),
commandline_1.hasArg
], ShowAppVersionsCommand.prototype, "startDate", void 0);
__decorate([
commandline_1.help(analytics_constants_1.endDateHelpMessage),
commandline_1.shortName("e"),
commandline_1.longName("end"),
commandline_1.hasArg
], ShowAppVersionsCommand.prototype, "endDate", void 0);
__decorate([
commandline_1.help("Show device count for each version"),
commandline_1.longName("devices")
], ShowAppVersionsCommand.prototype, "devices", void 0);
ShowAppVersionsCommand = __decorate([
commandline_1.help("Shows versions of the application")
], ShowAppVersionsCommand);
exports.default = ShowAppVersionsCommand;