Skip to content

Commit

Permalink
feat: show targets in show command (#922)
Browse files Browse the repository at this point in the history
fixes #875
  • Loading branch information
joaomoreno authored Dec 16, 2023
1 parent 4df2693 commit 1be75b2
Showing 1 changed file with 77 additions and 53 deletions.
130 changes: 77 additions & 53 deletions src/show.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPublicGalleryAPI, log } from './util';
import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
import { ExtensionQueryFlags, ExtensionVersion, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
import { ViewTable, formatDate, formatDateTime, ratingStars, tableView, indentRow, wordWrap, icons } from './viewutils';

const limitVersions = 6;
Expand Down Expand Up @@ -60,6 +60,33 @@ function unit(value: number, statisticName: string): string {
}
}

function getVersionTable(versions: ExtensionVersion[]): ViewTable {
if (!versions.length) {
return [];
}

const set = new Set<string>();
const result = versions
.filter(({ version }) => !set.has(version!) && set.add(version!))
.slice(0, limitVersions)
.map(({ version, lastUpdated, properties }) => [version, formatDate(lastUpdated!), properties?.some(p => p.key === 'Microsoft.VisualStudio.Code.PreRelease')]);

// Only show pre-release column if there are any pre-releases
if (result.every(v => !v[2])) {
for (const version of result) {
version.pop();
}
result.unshift(['Version', 'Last Updated']);
} else {
for (const version of result) {
version[2] = version[2] ? `✔️` : '';
}
result.unshift(['Version', 'Last Updated', 'Pre-release']);
}

return result as ViewTable;
}

function showOverview({
displayName = 'unknown',
extensionName = 'unknown',
Expand All @@ -73,65 +100,62 @@ function showOverview({
lastUpdated,
}: VSCodePublishedExtension) {
const [{ version = 'unknown' } = {}] = versions;
const versionTable = getVersionTable(versions);

// Create formatted table list of versions
const versionList = versions
.slice(0, limitVersions)
.map(({ version, lastUpdated, properties }) => [version, formatDate(lastUpdated!), properties?.some(p => p.key === 'Microsoft.VisualStudio.Code.PreRelease')]);

// Only show pre-release column if there are any pre-releases
if (versionList.every(v => !v[2])) {
for (const version of versionList) {
version.pop();
}
versionList.unshift(['Version', 'Last Updated']);
} else {
for (const version of versionList) {
version[2] = version[2] ? `✔️` : '';
}
versionList.unshift(['Version', 'Last Updated', 'Pre-release']);
}
const latestVersionTargets = versions
.filter(v => v.version === version)
.filter(v => v.targetPlatform)
.map(v => v.targetPlatform);

const { install: installs = 0, averagerating = 0, ratingcount = 0 } = statistics.reduce(
(map, { statisticName, value }) => ({ ...map, [statisticName!]: value }),
<ExtensionStatisticsMap>{}
);

// Render
console.log(
[
`${displayName}`,
`${publisherDisplayName} | ${icons.download} ` +
`${Number(installs).toLocaleString()} installs |` +
` ${ratingStars(averagerating)} (${ratingcount})`,
'',
`${shortDescription}`,
'',
...(versionList.length ? tableView(<ViewTable>versionList).map(indentRow) : ['no versions found']),
'',
'Categories:',
` ${categories.join(', ')}`,
'',
'Tags:',
` ${tags.filter(tag => !isExtensionTag.test(tag)).join(', ')}`,
'',
'More info:',
...tableView([
['Unique identifier:', `${publisherName}.${extensionName}`],
['Version:', version],
['Last updated:', formatDateTime(lastUpdated!)],
['Publisher:', publisherDisplayName],
['Published at:', formatDate(publishedDate!)],
]).map(indentRow),
const rows = [
`${displayName}`,
`${publisherDisplayName} | ${icons.download} ` +
`${Number(installs).toLocaleString()} installs |` +
` ${ratingStars(averagerating)} (${ratingcount})`,
'',
`${shortDescription}`,
'',
...(versionTable.length ? tableView(versionTable).map(indentRow) : ['no versions found']),
'',
'Categories:',
` ${categories.join(', ')}`,
'',
'Tags:',
` ${tags.filter(tag => !isExtensionTag.test(tag)).join(', ')}`
];

if (latestVersionTargets.length) {
rows.push(
'',
'Statistics:',
...tableView(
<ViewTable>statistics
.filter(({ statisticName }) => !/^trending/.test(statisticName!))
.map(({ statisticName, value }) => [statisticName, unit(round(value!), statisticName!)])
).map(indentRow),
]
.map(line => wordWrap(line))
.join('\n')
'Targets:',
` ${latestVersionTargets.join(', ')}`,
);
}

rows.push(
'',
'More info:',
...tableView([
['Unique identifier:', `${publisherName}.${extensionName}`],
['Version:', version],
['Last updated:', formatDateTime(lastUpdated!)],
['Publisher:', publisherDisplayName],
['Published at:', formatDate(publishedDate!)],
]).map(indentRow),
'',
'Statistics:',
...tableView(
<ViewTable>statistics
.filter(({ statisticName }) => !/^trending/.test(statisticName!))
.map(({ statisticName, value }) => [statisticName, unit(round(value!), statisticName!)])
).map(indentRow),
);

// Render
console.log(rows.map(line => wordWrap(line)).join('\n'));
}

0 comments on commit 1be75b2

Please sign in to comment.