UNPKG

3.21 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.show = void 0;
4const util_1 = require("./util");
5const GalleryInterfaces_1 = require("azure-devops-node-api/interfaces/GalleryInterfaces");
6const viewutils_1 = require("./viewutils");
7const limitVersions = 6;
8const isExtensionTag = /^__ext_(.*)$/;
9function 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}
32exports.show = show;
33function showOverview({ displayName = 'unknown', extensionName = 'unknown', shortDescription = '', versions = [], publisher: { displayName: publisherDisplayName, publisherName }, categories = [], tags = [], statistics = [], publishedDate, lastUpdated, }) {
34 const [{ version = 'unknown' } = {}] = versions;
35 // Create formatted table list of versions
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 // Render
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//# sourceMappingURL=show.js.map
\No newline at end of file