basant307/AI_Governance_Project
048
1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.show = show;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 GalleryInterfaces_1.ExtensionQueryFlags.IncludeVersionProperties,16 ];17 return (0, util_1.getPublicGalleryAPI)()18 .getExtension(extensionId, flags)19 .then(extension => {20 if (json) {21 console.log(JSON.stringify(extension, undefined, '\t'));22 }23 else {24 if (extension === undefined) {25 util_1.log.error(`Extension "${extensionId}" not found.`);26 }27 else {28 showOverview(extension);29 }30 }31 });32}33function round(num) {34 return Math.round(num * 100) / 100;35}36function unit(value, statisticName) {37 switch (statisticName) {38 case 'install':39 return `${value} installs`;40 case 'updateCount':41 return `${value} updates`;42 case 'averagerating':43 case 'weightedRating':44 return `${value} stars`;45 case 'ratingcount':46 return `${value} ratings`;47 case 'downloadCount':48 return `${value} downloads`;49 default:50 return `${value}`;51 }52}53function getVersionTable(versions) {54 if (!versions.length) {55 return [];56 }57 const set = new Set();58 const result = versions59 .filter(({ version }) => !set.has(version) && set.add(version))60 .slice(0, limitVersions)61 .map(({ version, lastUpdated, properties }) => [version, (0, viewutils_1.formatDate)(lastUpdated), properties?.some(p => p.key === 'Microsoft.VisualStudio.Code.PreRelease')]);62 // Only show pre-release column if there are any pre-releases63 if (result.every(v => !v[2])) {64 for (const version of result) {65 version.pop();66 }67 result.unshift(['Version', 'Last Updated']);68 }69 else {70 for (const version of result) {71 version[2] = version[2] ? `✔️` : '';72 }73 result.unshift(['Version', 'Last Updated', 'Pre-release']);74 }75 return result;76}77function showOverview({ displayName = 'unknown', extensionName = 'unknown', shortDescription = '', versions = [], publisher: { displayName: publisherDisplayName, publisherName }, categories = [], tags = [], statistics = [], publishedDate, lastUpdated, }) {78 const [{ version = 'unknown' } = {}] = versions;79 const versionTable = getVersionTable(versions);80 const latestVersionTargets = versions81 .filter(v => v.version === version)82 .filter(v => v.targetPlatform)83 .map(v => v.targetPlatform);84 const { install: installs = 0, averagerating = 0, ratingcount = 0 } = statistics.reduce((map, { statisticName, value }) => ({ ...map, [statisticName]: value }), {});85 const rows = [86 `${displayName}`,87 `${publisherDisplayName} | ${viewutils_1.icons.download} ` +88 `${Number(installs).toLocaleString()} installs |` +89 ` ${(0, viewutils_1.ratingStars)(averagerating)} (${ratingcount})`,90 '',91 `${shortDescription}`,92 '',93 ...(versionTable.length ? (0, viewutils_1.tableView)(versionTable).map(viewutils_1.indentRow) : ['no versions found']),94 '',95 'Categories:',96 ` ${categories.join(', ')}`,97 '',98 'Tags:',99 ` ${tags.filter(tag => !isExtensionTag.test(tag)).join(', ')}`100 ];101 if (latestVersionTargets.length) {102 rows.push('', 'Targets:', ` ${latestVersionTargets.join(', ')}`);103 }104 rows.push('', 'More info:', ...(0, viewutils_1.tableView)([105 ['Unique identifier:', `${publisherName}.${extensionName}`],106 ['Version:', version],107 ['Last updated:', (0, viewutils_1.formatDateTime)(lastUpdated)],108 ['Publisher:', publisherDisplayName],109 ['Published at:', (0, viewutils_1.formatDate)(publishedDate)],110 ]).map(viewutils_1.indentRow), '', 'Statistics:', ...(0, viewutils_1.tableView)(statistics111 .filter(({ statisticName }) => !/^trending/.test(statisticName))112 .map(({ statisticName, value }) => [statisticName, unit(round(value), statisticName)])).map(viewutils_1.indentRow));113 // Render114 console.log(rows.map(line => (0, viewutils_1.wordWrap)(line)).join('\n'));115}116//# sourceMappingURL=show.js.map