From bac1385ec346896d4f0478a125817c47a5bea2a4 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Wed, 15 Jun 2022 05:10:58 +0700 Subject: [PATCH] sort by semver --- scripts/downloads-by-versions.mjs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/downloads-by-versions.mjs b/scripts/downloads-by-versions.mjs index f4d647e3aaaa..21eaa1c09a05 100644 --- a/scripts/downloads-by-versions.mjs +++ b/scripts/downloads-by-versions.mjs @@ -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 = {}; @@ -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; @@ -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;