Skip to content

Commit 1be75b2

Browse files
authored
feat: show targets in show command (#922)
fixes #875
1 parent 4df2693 commit 1be75b2

File tree

1 file changed

+77
-53
lines changed

1 file changed

+77
-53
lines changed

src/show.ts

+77-53
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getPublicGalleryAPI, log } from './util';
2-
import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
2+
import { ExtensionQueryFlags, ExtensionVersion, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
33
import { ViewTable, formatDate, formatDateTime, ratingStars, tableView, indentRow, wordWrap, icons } from './viewutils';
44

55
const limitVersions = 6;
@@ -60,6 +60,33 @@ function unit(value: number, statisticName: string): string {
6060
}
6161
}
6262

63+
function getVersionTable(versions: ExtensionVersion[]): ViewTable {
64+
if (!versions.length) {
65+
return [];
66+
}
67+
68+
const set = new Set<string>();
69+
const result = versions
70+
.filter(({ version }) => !set.has(version!) && set.add(version!))
71+
.slice(0, limitVersions)
72+
.map(({ version, lastUpdated, properties }) => [version, formatDate(lastUpdated!), properties?.some(p => p.key === 'Microsoft.VisualStudio.Code.PreRelease')]);
73+
74+
// Only show pre-release column if there are any pre-releases
75+
if (result.every(v => !v[2])) {
76+
for (const version of result) {
77+
version.pop();
78+
}
79+
result.unshift(['Version', 'Last Updated']);
80+
} else {
81+
for (const version of result) {
82+
version[2] = version[2] ? `✔️` : '';
83+
}
84+
result.unshift(['Version', 'Last Updated', 'Pre-release']);
85+
}
86+
87+
return result as ViewTable;
88+
}
89+
6390
function showOverview({
6491
displayName = 'unknown',
6592
extensionName = 'unknown',
@@ -73,65 +100,62 @@ function showOverview({
73100
lastUpdated,
74101
}: VSCodePublishedExtension) {
75102
const [{ version = 'unknown' } = {}] = versions;
103+
const versionTable = getVersionTable(versions);
76104

77-
// Create formatted table list of versions
78-
const versionList = versions
79-
.slice(0, limitVersions)
80-
.map(({ version, lastUpdated, properties }) => [version, formatDate(lastUpdated!), properties?.some(p => p.key === 'Microsoft.VisualStudio.Code.PreRelease')]);
81-
82-
// Only show pre-release column if there are any pre-releases
83-
if (versionList.every(v => !v[2])) {
84-
for (const version of versionList) {
85-
version.pop();
86-
}
87-
versionList.unshift(['Version', 'Last Updated']);
88-
} else {
89-
for (const version of versionList) {
90-
version[2] = version[2] ? `✔️` : '';
91-
}
92-
versionList.unshift(['Version', 'Last Updated', 'Pre-release']);
93-
}
105+
const latestVersionTargets = versions
106+
.filter(v => v.version === version)
107+
.filter(v => v.targetPlatform)
108+
.map(v => v.targetPlatform);
94109

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

100-
// Render
101-
console.log(
102-
[
103-
`${displayName}`,
104-
`${publisherDisplayName} | ${icons.download} ` +
105-
`${Number(installs).toLocaleString()} installs |` +
106-
` ${ratingStars(averagerating)} (${ratingcount})`,
107-
'',
108-
`${shortDescription}`,
109-
'',
110-
...(versionList.length ? tableView(<ViewTable>versionList).map(indentRow) : ['no versions found']),
111-
'',
112-
'Categories:',
113-
` ${categories.join(', ')}`,
114-
'',
115-
'Tags:',
116-
` ${tags.filter(tag => !isExtensionTag.test(tag)).join(', ')}`,
117-
'',
118-
'More info:',
119-
...tableView([
120-
['Unique identifier:', `${publisherName}.${extensionName}`],
121-
['Version:', version],
122-
['Last updated:', formatDateTime(lastUpdated!)],
123-
['Publisher:', publisherDisplayName],
124-
['Published at:', formatDate(publishedDate!)],
125-
]).map(indentRow),
115+
const rows = [
116+
`${displayName}`,
117+
`${publisherDisplayName} | ${icons.download} ` +
118+
`${Number(installs).toLocaleString()} installs |` +
119+
` ${ratingStars(averagerating)} (${ratingcount})`,
120+
'',
121+
`${shortDescription}`,
122+
'',
123+
...(versionTable.length ? tableView(versionTable).map(indentRow) : ['no versions found']),
124+
'',
125+
'Categories:',
126+
` ${categories.join(', ')}`,
127+
'',
128+
'Tags:',
129+
` ${tags.filter(tag => !isExtensionTag.test(tag)).join(', ')}`
130+
];
131+
132+
if (latestVersionTargets.length) {
133+
rows.push(
126134
'',
127-
'Statistics:',
128-
...tableView(
129-
<ViewTable>statistics
130-
.filter(({ statisticName }) => !/^trending/.test(statisticName!))
131-
.map(({ statisticName, value }) => [statisticName, unit(round(value!), statisticName!)])
132-
).map(indentRow),
133-
]
134-
.map(line => wordWrap(line))
135-
.join('\n')
135+
'Targets:',
136+
` ${latestVersionTargets.join(', ')}`,
137+
);
138+
}
139+
140+
rows.push(
141+
'',
142+
'More info:',
143+
...tableView([
144+
['Unique identifier:', `${publisherName}.${extensionName}`],
145+
['Version:', version],
146+
['Last updated:', formatDateTime(lastUpdated!)],
147+
['Publisher:', publisherDisplayName],
148+
['Published at:', formatDate(publishedDate!)],
149+
]).map(indentRow),
150+
'',
151+
'Statistics:',
152+
...tableView(
153+
<ViewTable>statistics
154+
.filter(({ statisticName }) => !/^trending/.test(statisticName!))
155+
.map(({ statisticName, value }) => [statisticName, unit(round(value!), statisticName!)])
156+
).map(indentRow),
136157
);
158+
159+
// Render
160+
console.log(rows.map(line => wordWrap(line)).join('\n'));
137161
}

0 commit comments

Comments
 (0)