Skip to content

Commit

Permalink
Update how we sort plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Oct 22, 2021
1 parent c5e0120 commit f84fb57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion docs/.vuepress/sorted-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const plugins = require("./plugins.js");
try {
const downloads = require("./plugin-downloads.json");

plugins.sort((p1, p2) => downloads[p2.name] - downloads[p1.name]);
plugins.officialPlugins.sort(
(p1, p2) => downloads[p2.name] - downloads[p1.name]
);

plugins.communityPlugins.sort(
(p1, p2) => downloads[p2.name] - downloads[p1.name]
);
} catch (e) {
// we just don't sort here
}
Expand Down
10 changes: 6 additions & 4 deletions docs/get-plugins-downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fetch from "node-fetch";

const plugins = require("./.vuepress/plugins");

async function getLastWeekDownloads(npmPackage: string): Promise<number> {
async function getLastMonthDownloads(npmPackage: string): Promise<number> {
const res = await fetch(
`https://api.npmjs.org/downloads/point/last-month/${npmPackage}`,
{
Expand All @@ -25,9 +25,11 @@ async function getLastWeekDownloads(npmPackage: string): Promise<number> {

async function main() {
const downloads: Array<{ [plugin: string]: number }> = await Promise.all(
plugins.map(async (p: any) => ({
[p.name]: await getLastWeekDownloads(p.npmPackage ?? p.name),
}))
[...plugins.officialPlugins, ...plugins.communityPlugins].map(
async (p: any) => ({
[p.name]: await getLastMonthDownloads(p.npmPackage ?? p.name),
})
)
);

downloads.sort((p1, p2) => Object.values(p2)[0] - Object.values(p1)[0]);
Expand Down

0 comments on commit f84fb57

Please sign in to comment.