Skip to content

Commit

Permalink
sort by semver
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jun 14, 2022
1 parent 0233e1f commit bac1385
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/downloads-by-versions.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import coerce from 'semver/functions/coerce.js';
import semver from 'semver';

const { coerce, cmp } = semver;
const { cyan, green } = chalk;
const ALL = !argv['main-only'];
const downloadsByPatch = {};
Expand All @@ -20,9 +22,9 @@ const [core, pure, bundle] = await Promise.all([
]);

for (let [patch, downloads] of Object.entries(core)) {
const semver = coerce(patch);
const { major } = semver;
const minor = `${ major }.${ semver.minor }`;
const version = coerce(patch);
const { major } = version;
const minor = `${ major }.${ version.minor }`;
if (ALL) downloads += (pure[patch] || 0) + (bundle[patch] || 0);
downloadsByPatch[patch] = downloads;
downloadsByMinor[minor] = (downloadsByMinor[minor] || 0) + downloads;
Expand All @@ -32,7 +34,7 @@ for (let [patch, downloads] of Object.entries(core)) {

function log(kind, map) {
echo(green(`downloads for 7 days by ${ cyan(kind) } releases:`));
console.table(Object.keys(map).sort().reduce((memo, version) => {
console.table(Object.keys(map).sort((a, b) => cmp(coerce(a), '>', coerce(b)) ? 1 : -1).reduce((memo, version) => {
const downloads = map[version];
memo[version] = { downloads, '%': `${ (downloads / total * 100).toFixed(2).padStart(5) } %` };
return memo;
Expand Down

0 comments on commit bac1385

Please sign in to comment.