Skip to content

Take GraphQL over HTTP scoring into account + clean sort-libraries function #1352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 24, 2023
Merged
3 changes: 2 additions & 1 deletion gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promisify } from "util"
import { readFile } from "fs/promises"
import * as globby from "globby"
import * as frontmatterParser from "parser-front-matter"
import { sortLibs } from "./scripts/sort-libraries"
import { sortLibs } from "./scripts/sort-libraries/sort-libraries"

const parse$ = promisify(frontmatterParser.parse)

Expand Down Expand Up @@ -186,6 +186,7 @@ export const onCreatePage: GatsbyNode["onCreatePage"] = async ({
Object.keys(libraryCategoryMap).map(async libraryCategoryName => {
const libraries = libraryCategoryMap[libraryCategoryName]
const { sortedLibs, totalStars } = await sortLibs(libraries)

libraryCategoryMap[libraryCategoryName] = sortedLibs
languageTotalStars += totalStars || 0
})
Expand Down
234 changes: 0 additions & 234 deletions scripts/sort-libraries.ts

This file was deleted.

52 changes: 52 additions & 0 deletions scripts/sort-libraries/get-gem-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
type GemStatsFetchRespone = {
name: string
downloads: number
version: string
version_created_at: string
version_downloads: number
platform: string
authors: string
info: string
licenses: Array<string>
metadata: {
homepage_uri: string
changelog_uri: string
bug_tracker_uri: string
source_code_uri: string
mailing_list_uri: string
}
yanked: boolean
sha: string
gem_uri: string
homepage_uri: string
wiki_uri: string
documentation_uri: string
mailing_list_uri: string
source_code_uri: string
bug_tracker_uri: string
changelog_uri: string
funding_uri: string
dependencies: {
development: Array<string>
runtime: Array<string>
}
}

export async function getGemStats(packageName: string): Promise<number> {
const response = await fetch(
`https://rubygems.org/api/v1/gems/${encodeURIComponent(packageName)}.json`
)
if (!response.ok) {
console.warn(`Get invalid response from GEM for ${packageName}:`, response)
return 0
}
const responseJson: GemStatsFetchRespone = await response.json()
if (!responseJson) {
console.warn(
`Get invalid response from GEM for ${packageName}:`,
responseJson
)
return 0
}
return responseJson.downloads ?? 0
}
Loading