Skip to content

Commit f0062cb

Browse files
committed
feat(cli): add --minor-versions option for list
Output only the available Unity minor versions.
1 parent 214d39e commit f0062cb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

bin/cli.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ const toNumber = function (version, max = false) {
1414
+ parseInt(match[5] || (max ? '99' : '0'));
1515
};
1616

17+
const toMinor = function (version) {
18+
const match = version.toString().match(/^(\d+)\.*(\d*)\.*(\d*)(\w*)(\d*)$/);
19+
if (match === null) return '';
20+
21+
return `${match[1]}.${match[2]}`;
22+
};
23+
24+
const groupBy = (array, getKey) =>
25+
array.reduce((obj, cur, idx, src) => {
26+
const key = getKey(cur, idx, src);
27+
(obj[key] || (obj[key] = [])).push(cur);
28+
return obj;
29+
}, {});
30+
1731
cli.command('<version>', 'Get a changeset for specific version')
1832
.action(version => (async () => {
1933
try {
@@ -32,7 +46,8 @@ cli.command('list', 'List changesets')
3246
.option('--json', 'Output in json format')
3347
.option('--all', 'List all changesets (alpha/beta included)')
3448
.option('--beta', 'List alpha/beta changesets')
35-
.option('--versions', 'Output only the available unity version')
49+
.option('--versions', 'Output only the available Unity versions')
50+
.option('--minor-versions', 'Output only the available Unity minor versions')
3651
.action(options => (async () => {
3752
var results = options.all
3853
? (await scrapeArchivedChangesets()).concat(await scrapeBetaChangesets())
@@ -50,8 +65,14 @@ cli.command('list', 'List changesets')
5065
return min <= n && n <= max;
5166
});
5267

68+
// Group by minor version
69+
if (options.minorVersions) {
70+
results.forEach(r => r.version = toMinor(r.version))
71+
results = Object.values(groupBy(results, r => r.version)).map(g => g[0]);
72+
}
73+
5374
// Output versions
54-
if (options.versions)
75+
if (options.versions || options.minorVersions)
5576
results = results.map(r => r.version);
5677

5778
// Output in json format or plain

0 commit comments

Comments
 (0)