Files
shields/services/node/node.service.js
T
Paul MelnikowandGitHub 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

86 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 'version'
}
static get defaultBadgeData() {
return { label: 'node' }
}
static get url() {
return this.buildUrl('node/v', { withTag: true })
}
static get examples() {
return [
{
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 })
}
}