* allow service classes to define a static example * define static example for some services (apm, appveyor, cdnjs, clojars, gem, librariesio, npm, uptimerobot) * add/update tests This allows us to show an example without making an API call to a live service for better performance. We can now specify 3 fields in the example definition: * urlPattern for the version with placeholders e.g: /npm/dw/:package.svg * ExampleUrl/Uri for the concrete example e.g: /npm/dw/localeval.svg * PreviewUrl/Uri for the static (or live) image we will actually show
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
'use strict'
|
|
|
|
const { metric } = require('../../lib/text-formatters')
|
|
const LibrariesIoBase = require('./librariesio-base')
|
|
|
|
// https://libraries.io/api#project-dependents
|
|
class LibrariesIoDependents extends LibrariesIoBase {
|
|
static get category() {
|
|
return 'other'
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'dependents',
|
|
}
|
|
}
|
|
|
|
static get url() {
|
|
return this.buildUrl('librariesio/dependents')
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Dependents (via libraries.io)',
|
|
exampleUrl: 'npm/got',
|
|
urlPattern: ':platform/:library',
|
|
staticExample: this.render({ dependentCount: 2000 }),
|
|
},
|
|
]
|
|
}
|
|
|
|
static render({ dependentCount }) {
|
|
return {
|
|
message: metric(dependentCount),
|
|
color: dependentCount === 0 ? 'orange' : 'brightgreen',
|
|
}
|
|
}
|
|
|
|
async handle({ platform, packageName }) {
|
|
const { dependents_count: dependentCount } = await this.fetch(
|
|
{
|
|
platform,
|
|
packageName,
|
|
},
|
|
{ allowPackages: true }
|
|
)
|
|
return this.constructor.render({ dependentCount })
|
|
}
|
|
}
|
|
|
|
module.exports = LibrariesIoDependents
|