kopia lustrzana https://github.com/badgen/badgen.net
feat: migrate badge generator /winget
Seems we can no longer get license info from manifest now.pull/579/head
rodzic
ba31eb8a33
commit
56d6d41b8c
|
@ -23,19 +23,25 @@ const nextConfig = {
|
|||
destination: `/api/badge/:path*`,
|
||||
}]
|
||||
|
||||
const badgeRedirects = liveBadgeRedirects.concat(staticBadgeRedirects)
|
||||
|
||||
// return badgeRedirects
|
||||
return [
|
||||
{ source: '/static/:path*', destination: '/api/static' },
|
||||
{ source: '/static', destination: '/api/static' },
|
||||
|
||||
const badgeRedirects = [
|
||||
{ source: '/badge/:path*', destination: '/api/static' },
|
||||
{ source: '/badge', destination: '/api/static' },
|
||||
|
||||
{ source: '/xo/:path*', destination: '/api/xo' },
|
||||
{ source: '/xo', destination: '/api/xo' },
|
||||
]
|
||||
|
||||
const badgeApis = [
|
||||
'/static',
|
||||
'/winget',
|
||||
'/xo',
|
||||
]
|
||||
|
||||
badgeApis.forEach(b => {
|
||||
badgeRedirects.push({ source: `${b}/:path*`, destination: `/api${b}` }) // badges
|
||||
badgeRedirects.push({ source: b, destination: `/api${b}` }) // doc pages
|
||||
})
|
||||
|
||||
// const badgeRedirects = liveBadgeRedirects.concat(staticBadgeRedirects)
|
||||
|
||||
return badgeRedirects
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import got from '../libs/got'
|
||||
import { restGithub } from '../libs/github'
|
||||
import { parseDocument } from 'yaml'
|
||||
import { restGithub } from '../../libs/github'
|
||||
import { basename, extname } from 'path'
|
||||
import { version, versionColor } from '../libs/utils'
|
||||
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
|
||||
import { version, versionColor } from '../../libs/utils'
|
||||
import { createBadgenHandler } from '../../libs/create-badgen-handler-next'
|
||||
|
||||
import type { PathArgs, BadgenResult } from '../../libs/create-badgen-handler-next'
|
||||
|
||||
const WINGET_GITHUB_REPO = 'microsoft/winget-pkgs'
|
||||
|
||||
|
@ -98,16 +98,15 @@ class Version {
|
|||
export default createBadgenHandler({
|
||||
title: 'winget',
|
||||
examples: {
|
||||
'/winget/v/GitHub.cli': 'version',
|
||||
'/winget/v/Balena.Etcher': 'version',
|
||||
'/winget/license/Arduino.Arduino': 'license'
|
||||
'/winget/v/aria2.aria2': 'version',
|
||||
'/winget/v/Amazon.AWSCLI': 'version',
|
||||
},
|
||||
handlers: {
|
||||
'/winget/:topic<v|license>/:appId': handler
|
||||
'/winget/v/:appId': handler,
|
||||
}
|
||||
})
|
||||
|
||||
async function handler ({ topic, appId }: PathArgs) {
|
||||
async function handler ({ topic, appId }: PathArgs): BadgenResult {
|
||||
switch (topic) {
|
||||
case 'v': {
|
||||
const versions = await fetchVersions(appId)
|
||||
|
@ -120,29 +119,25 @@ async function handler ({ topic, appId }: PathArgs) {
|
|||
}
|
||||
}
|
||||
case 'license': {
|
||||
const yaml = await fetchManifest(appId)
|
||||
const manifest = parseDocument(yaml)
|
||||
const license = manifest.get('License')
|
||||
|
||||
return {
|
||||
subject: 'license',
|
||||
status: license || 'unknown',
|
||||
status: 'unknown',
|
||||
color: 'blue'
|
||||
}
|
||||
}
|
||||
default:
|
||||
return {
|
||||
subject: 'winget',
|
||||
status: 'unknown topic',
|
||||
color: 'grey'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchManifest(appId: string) {
|
||||
const versions = await fetchVersions(appId)
|
||||
const version = last(versions)
|
||||
const path = [...appId.split('.'), `${version}.yaml`].join('/')
|
||||
return got(`https://github.com/${WINGET_GITHUB_REPO}/raw/master/manifests/${path}`).text()
|
||||
}
|
||||
|
||||
async function fetchVersions(appId: string): Promise<Version[]> {
|
||||
const path = appId.replace(/\./g, '/')
|
||||
const files = await restGithub<any[]>(`repos/${WINGET_GITHUB_REPO}/contents/manifests/${path}`)
|
||||
const appPath = appId.replace(/\./g, '/')
|
||||
const categoryPath = appPath[0].toLowerCase()
|
||||
const files = await restGithub<any[]>(`repos/${WINGET_GITHUB_REPO}/contents/manifests/${categoryPath}/${appPath}`)
|
||||
const versions = files.map(file => {
|
||||
const name = basename(file.name, extname(file.name))
|
||||
return new Version(name)
|
Ładowanie…
Reference in New Issue