kopia lustrzana https://github.com/badgen/badgen.net
live-fns: add visual studio marketplace #113
rodzic
eaa0beb1fe
commit
b1c8bad301
|
@ -227,6 +227,12 @@ Advanced usage (for badge makers):
|
|||
['version', '/hackage/v/Cabal'],
|
||||
['license', '/hackage/license/Cabal']
|
||||
],
|
||||
'visual studio marketplace': [
|
||||
['version', '/vs-marketplace/v/vscodevim.vim'],
|
||||
['installs', '/vs-marketplace/i/vscodevim.vim'],
|
||||
['downloads', '/vs-marketplace/d/vscodevim.vim'],
|
||||
['rating', '/vs-marketplace/rating/vscodevim.vim'],
|
||||
],
|
||||
/* CIs */
|
||||
travis: [
|
||||
['build', '/travis/babel/babel'],
|
||||
|
|
|
@ -25,5 +25,6 @@ module.exports = {
|
|||
rubygems: require('./rubygems.js'),
|
||||
runkit: require('./runkit.js'),
|
||||
travis: require('./travis.js'),
|
||||
'uptime-robot': require('./uptime-robot.js')
|
||||
'uptime-robot': require('./uptime-robot.js'),
|
||||
'vs-marketplace': require('./vs-marketplace.js')
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
const millify = require('millify')
|
||||
const axios = require('../axios.js')
|
||||
const v = require('../utils/version-formatter.js')
|
||||
const semColor = require('../utils/sem-color.js')
|
||||
|
||||
module.exports = async (topic, pkg) => {
|
||||
const { results } = await queryVSM(pkg).then(res => res.data)
|
||||
const extension = results[0].extensions[0]
|
||||
|
||||
switch (topic) {
|
||||
case 'v':
|
||||
const version = extension.versions[0].version
|
||||
return {
|
||||
subject: 'VS Marketplace',
|
||||
status: v(version),
|
||||
color: semColor(version)
|
||||
}
|
||||
case 'd':
|
||||
const { install, updateCount } = parseStatistics(extension)
|
||||
return {
|
||||
subject: 'downloads',
|
||||
status: millify(install + updateCount),
|
||||
color: 'green'
|
||||
}
|
||||
case 'i':
|
||||
return {
|
||||
subject: 'installs',
|
||||
status: millify(parseStatistics(extension).install),
|
||||
color: 'green'
|
||||
}
|
||||
case 'rating':
|
||||
const { averagerating, ratingcount } = parseStatistics(extension)
|
||||
return {
|
||||
subject: 'rating',
|
||||
status: `${averagerating.toFixed(1)}/5 (${ratingcount})`,
|
||||
color: 'green'
|
||||
}
|
||||
default:
|
||||
return {
|
||||
subject: 'Visual Studio Marketplace',
|
||||
status: 'unknown topic'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const queryVSM = async pkgName => {
|
||||
const endpoint = 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery/'
|
||||
return axios.post(endpoint, {
|
||||
filters: [{ criteria: [{ filterType: 7, value: pkgName }] }],
|
||||
flags: 914
|
||||
}, {
|
||||
headers: { Accept: 'application/json;api-version=3.0-preview.1' }
|
||||
})
|
||||
}
|
||||
|
||||
const parseStatistics = extension => {
|
||||
return extension.statistics.reduce((accu, curr) => {
|
||||
accu[curr.statisticName] = curr.value
|
||||
return accu
|
||||
}, {})
|
||||
}
|
Ładowanie…
Reference in New Issue