kopia lustrzana https://github.com/badgen/badgen.net
Fix missing apm badge topic
rodzic
b3566e4ee7
commit
f3341b80de
|
|
@ -3,62 +3,64 @@ import got from '../libs/got'
|
||||||
import { version, versionColor } from '../libs/utils'
|
import { version, versionColor } from '../libs/utils'
|
||||||
import {
|
import {
|
||||||
badgenServe,
|
badgenServe,
|
||||||
BadgenServeMeta,
|
BadgenServeMeta as Meta,
|
||||||
BadgenServeHandlers
|
BadgenServeHandlers as Handlers,
|
||||||
|
BadgenServeHandlerArgs as Args
|
||||||
} from '../libs/badgen-serve'
|
} from '../libs/badgen-serve'
|
||||||
|
|
||||||
export const meta: BadgenServeMeta = {
|
export const meta: Meta = {
|
||||||
title: 'Atom Package',
|
title: 'Atom Package',
|
||||||
examples: {
|
examples: {
|
||||||
'/apm/v/linter': 'version',
|
'/apm/v/linter': 'version',
|
||||||
'/apm/stars/linter': 'stars',
|
'/apm/stars/linter': 'stars',
|
||||||
'/apm/license/linter': 'license',
|
'/apm/license/linter': 'license',
|
||||||
'/apm/dl/linter': 'downloads'
|
'/apm/downloads/linter': 'downloads'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handlers: BadgenServeHandlers = {
|
export const handlers: Handlers = {
|
||||||
'/apm/:topic/:pkg': handler
|
'/apm/:topic/:pkg': handler
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handler (args) {
|
async function handler ({ topic, pkg }: Args) {
|
||||||
const { topic, pkg } = args
|
|
||||||
const endpoint = `https://atom.io/api/packages/${pkg}`
|
const endpoint = `https://atom.io/api/packages/${pkg}`
|
||||||
const meta = await got(endpoint).then(res => res.body)
|
const data = await got(endpoint).then(res => res.body)
|
||||||
|
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
|
case 'v':
|
||||||
case 'version': {
|
case 'version': {
|
||||||
return {
|
return {
|
||||||
subject: `apm`,
|
subject: `apm`,
|
||||||
status: version(meta.releases.latest),
|
status: version(data.releases.latest),
|
||||||
color: versionColor(meta.releases.latest)
|
color: versionColor(data.releases.latest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'dl':
|
||||||
|
case 'downloads': {
|
||||||
|
return {
|
||||||
|
subject: 'downloads',
|
||||||
|
status: millify(data.downloads),
|
||||||
|
color: 'green'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'license': {
|
case 'license': {
|
||||||
return {
|
return {
|
||||||
subject: 'license',
|
subject: 'license',
|
||||||
status: meta.versions[meta.releases.latest].license || 'unknown',
|
status: data.versions[data.releases.latest].license || 'unknown',
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'downloads': {
|
|
||||||
return {
|
|
||||||
subject: 'downloads',
|
|
||||||
status: millify(meta.downloads),
|
|
||||||
color: 'green'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 'stars': {
|
case 'stars': {
|
||||||
return {
|
return {
|
||||||
subject: 'stars',
|
subject: 'stars',
|
||||||
status: millify(meta.stargazers_count),
|
status: millify(data.stargazers_count),
|
||||||
color: 'green'
|
color: 'green'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return {
|
return {
|
||||||
subject: 'apm',
|
subject: 'apm',
|
||||||
status: 'unknown',
|
status: 'unknown topic',
|
||||||
color: 'grey'
|
color: 'grey'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue