Amio 2018-08-05 13:09:16 +08:00
commit 9625e9680c
3 zmienionych plików z 93 dodań i 0 usunięć

Wyświetl plik

@ -139,6 +139,17 @@ Available query params:
['version (pre)', '/nuget/v/newtonsoft.json/pre'],
['version (latest)', '/nuget/v/newtonsoft.json/latest']
],
packagist: [
['version (stable)', '/packagist/v/monolog/monolog'],
['version (pre)', '/packagist/v/monolog/monolog/pre'],
['version (latest)', '/packagist/v/monolog/monolog/latest'],
['total downloads', '/packagist/dt/monolog/monolog'],
['daily downloads', '/packagist/dd/monolog/monolog'],
['monthly downloads', '/packagist/dm/monolog/monolog'],
['favers', '/packagist/favers/monolog/monolog'],
['dependents', '/packagist/dependents/monolog/monolog'],
['suggesters', '/packagist/suggesters/monolog/monolog'],
],
/* CIs */
travis: [
['build', '/travis/babel/babel'],

Wyświetl plik

@ -16,6 +16,7 @@ module.exports = {
'nuget': require('./nuget.js'),
'opencollective': require('./opencollective.js'),
'packagephobia': require('./packagephobia.js'),
'packagist': require('./packagist.js'),
'pypi': require('./pypi.js'),
'runkit': require('./runkit.js'),
'travis': require('./travis.js'),

Wyświetl plik

@ -0,0 +1,81 @@
const millify = require('millify')
const axios = require('../axios.js')
const semColor = require('../utils/sem-color.js')
const pre = versions => versions.filter(v => v.includes('-'))
const stable = versions => versions.filter(v => !v.includes('-'))
const latest = versions => versions.length > 0 && versions.slice(-1)[0]
module.exports = async function (topic, vendor, pkg, channel = 'stable') {
const endpoint = `https://packagist.org/packages/${vendor}/${pkg}.json`
const response = await axios.get(endpoint).then(res => res.data)
switch (topic) {
case 'v':
const versions = Object.keys(response.package.versions)
let version = ''
switch (channel) {
case 'latest':
version = latest(versions)
break
case 'pre':
version = latest(pre(versions))
break
default:
version = latest(stable(versions).reverse())
}
version = version || latest(versions)
return {
subject: 'packagist',
status: version || 'unknown',
color: semColor(version)
}
case 'dt':
return {
subject: 'downloads',
status: millify(response.package.downloads.total),
color: 'green'
}
case 'dd':
return {
subject: 'downloads',
status: millify(response.package.downloads.daily),
color: 'green'
}
case 'dm':
return {
subject: 'downloads',
status: millify(response.package.downloads.monthly),
color: 'green'
}
case 'favers':
return {
subject: 'favers',
status: millify(response.package.favers),
color: 'green'
}
case 'dependents':
return {
subject: 'dependents',
status: response.package.dependents,
color: 'green'
}
case 'suggesters':
return {
subject: 'suggesters',
status: response.package.suggesters,
color: 'green'
}
default:
return {
subject: 'packagist',
status: 'unknown',
color: 'grey'
}
}
}