The term “url” is overloaded in services, to refer to the Shields route and also the API URL. Calling the Shields URL a “route” is on the whole more descriptive, and makes it clearer and more obvious which one of these we’re talking about. It’s a small thing, though seems like an improvement. We have a few functions called `buildUrl`. I’ve renamed them to `buildRoute` when they refer to routes, and left them as `buildUrl` when they refer to API URLs. I included a minor style tweak and some formatting cleanup in `TUTORIAL.md`.
87 lines
1.9 KiB
JavaScript
87 lines
1.9 KiB
JavaScript
'use strict'
|
|
|
|
const NPMBase = require('../npm/npm-base')
|
|
const { versionColorForRange } = require('./node-version-color')
|
|
|
|
module.exports = class NodeVersion extends NPMBase {
|
|
static get category() {
|
|
return 'platform-support'
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return { label: 'node' }
|
|
}
|
|
|
|
static get route() {
|
|
return this.buildRoute('node/v', { withTag: true })
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'node',
|
|
previewUrl: 'passport',
|
|
keywords: ['npm'],
|
|
},
|
|
{
|
|
title: 'node (scoped)',
|
|
previewUrl: '@stdlib/stdlib',
|
|
keywords: ['npm'],
|
|
},
|
|
{
|
|
title: 'node (tag)',
|
|
previewUrl: 'passport/latest',
|
|
keywords: ['npm'],
|
|
},
|
|
{
|
|
title: 'node (scoped with tag)',
|
|
previewUrl: '@stdlib/stdlib/latest',
|
|
keywords: ['npm'],
|
|
},
|
|
{
|
|
title: 'node (scoped with tag, custom registry)',
|
|
previewUrl: '@stdlib/stdlib/latest',
|
|
query: { registry_uri: 'https://registry.npmjs.com' },
|
|
keywords: ['npm'],
|
|
},
|
|
]
|
|
}
|
|
|
|
static async render({ tag, nodeVersionRange }) {
|
|
const label = tag ? `node@${tag}` : undefined
|
|
|
|
if (nodeVersionRange === undefined) {
|
|
return {
|
|
label,
|
|
message: 'not specified',
|
|
color: 'lightgray',
|
|
}
|
|
} else {
|
|
return {
|
|
label,
|
|
message: nodeVersionRange,
|
|
color: await versionColorForRange(nodeVersionRange),
|
|
}
|
|
}
|
|
}
|
|
|
|
async handle(namedParams, queryParams) {
|
|
const {
|
|
scope,
|
|
packageName,
|
|
tag,
|
|
registryUrl,
|
|
} = this.constructor.unpackParams(namedParams, queryParams)
|
|
const { engines } = await this.fetchPackageData({
|
|
scope,
|
|
packageName,
|
|
registryUrl,
|
|
tag,
|
|
})
|
|
|
|
const { node: nodeVersionRange } = engines || {}
|
|
|
|
return this.constructor.render({ tag, nodeVersionRange })
|
|
}
|
|
}
|