1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.show = void 0;
|
4 | const util_1 = require("./util");
|
5 | const GalleryInterfaces_1 = require("azure-devops-node-api/interfaces/GalleryInterfaces");
|
6 | const viewutils_1 = require("./viewutils");
|
7 | const limitVersions = 6;
|
8 | const isExtensionTag = /^__ext_(.*)$/;
|
9 | function show(extensionId, json = false) {
|
10 | const flags = [
|
11 | GalleryInterfaces_1.ExtensionQueryFlags.IncludeCategoryAndTags,
|
12 | GalleryInterfaces_1.ExtensionQueryFlags.IncludeMetadata,
|
13 | GalleryInterfaces_1.ExtensionQueryFlags.IncludeStatistics,
|
14 | GalleryInterfaces_1.ExtensionQueryFlags.IncludeVersions,
|
15 | ];
|
16 | return (0, util_1.getPublicGalleryAPI)()
|
17 | .getExtension(extensionId, flags)
|
18 | .then(extension => {
|
19 | if (json) {
|
20 | console.log(JSON.stringify(extension, undefined, '\t'));
|
21 | }
|
22 | else {
|
23 | if (extension === undefined) {
|
24 | util_1.log.error(`Extension "${extensionId}" not found.`);
|
25 | }
|
26 | else {
|
27 | showOverview(extension);
|
28 | }
|
29 | }
|
30 | });
|
31 | }
|
32 | exports.show = show;
|
33 | function showOverview({ displayName = 'unknown', extensionName = 'unknown', shortDescription = '', versions = [], publisher: { displayName: publisherDisplayName, publisherName }, categories = [], tags = [], statistics = [], publishedDate, lastUpdated, }) {
|
34 | const [{ version = 'unknown' } = {}] = versions;
|
35 |
|
36 | const versionList = (versions.slice(0, limitVersions).map(({ version, lastUpdated }) => [version, (0, viewutils_1.formatDate)(lastUpdated)]));
|
37 | const { install: installs = 0, averagerating = 0, ratingcount = 0 } = statistics.reduce((map, { statisticName, value }) => ({ ...map, [statisticName]: value }), {});
|
38 |
|
39 | console.log([
|
40 | `${displayName}`,
|
41 | `${publisherDisplayName} | ${viewutils_1.icons.download} ` +
|
42 | `${Number(installs).toLocaleString()} installs |` +
|
43 | ` ${(0, viewutils_1.ratingStars)(averagerating)} (${ratingcount})`,
|
44 | '',
|
45 | `${shortDescription}`,
|
46 | '',
|
47 | 'Recent versions:',
|
48 | ...(versionList.length ? (0, viewutils_1.tableView)(versionList).map(viewutils_1.indentRow) : ['no versions found']),
|
49 | '',
|
50 | 'Categories:',
|
51 | ` ${categories.join(', ')}`,
|
52 | '',
|
53 | 'Tags:',
|
54 | ` ${tags.filter(tag => !isExtensionTag.test(tag)).join(', ')}`,
|
55 | '',
|
56 | 'More info:',
|
57 | ...(0, viewutils_1.tableView)([
|
58 | ['Unique identifier:', `${publisherName}.${extensionName}`],
|
59 | ['Version:', version],
|
60 | ['Last updated:', (0, viewutils_1.formatDateTime)(lastUpdated)],
|
61 | ['Publisher:', publisherDisplayName],
|
62 | ['Published at:', (0, viewutils_1.formatDate)(publishedDate)],
|
63 | ]).map(viewutils_1.indentRow),
|
64 | '',
|
65 | 'Statistics:',
|
66 | ...(0, viewutils_1.tableView)(statistics.map(({ statisticName, value }) => [statisticName, Number(value).toFixed(2)])).map(viewutils_1.indentRow),
|
67 | ]
|
68 | .map(line => (0, viewutils_1.wordWrap)(line))
|
69 | .join('\n'));
|
70 | }
|
71 |
|
\ | No newline at end of file |