Amio 6 years ago
parent
commit
72bc209d33
  1. 4
      libs/index.md
  2. 28
      libs/live-fns/david.js
  3. 6
      libs/setup-live-badge.js

4
libs/index.md

@ -67,6 +67,10 @@ Available color names:
| circleci | ![](/circleci/github/amio/now-go) | [/circleci/github/amio/now-go](/circleci/github/amio/now-go)
| circleci (branch) | ![](/circleci/github/amio/now-go/master) | [/circleci/github/amio/now-go/master](/circleci/github/amio/now-go/master)
| appveyor ci | ![](/appveyor/ci/gruntjs/grunt) | [/appveyor/ci/gruntjs/grunt](/appveyor/ci/gruntjs/grunt)
| david-dm | ![](/david/dep/zeit/pkg) | [/david/dep/zeit/pkg](/david/dep/zeit/pkg)
| david-dm dev dependencies | ![](/david/dev/zeit/pkg) | [/david/dev/zeit/pkg](/david/dev/zeit/pkg)
| david-dm peer dependencies | ![](/david/peer/epoberezkin/ajv-keywords) | [/david/peer/epoberezkin/ajv-keywords](/david/peer/epoberezkin/ajv-keywords)
| david-dm optional dependencies | ![](/david/optional/epoberezkin/ajv-keywords) | [/david/optional/epoberezkin/ajv-keywords](/david/optional/epoberezkin/ajv-keywords)
## About

28
libs/live-fns/david.js

@ -5,11 +5,17 @@ const statusInfo = {
'outofdate': ['out of date', 'orange'],
'notsouptodate': ['up to date', 'yellow'],
'uptodate': ['up to date', 'green'],
'none': ['pending', 'grey']
'none': ['none', 'blue']
}
module.exports = async function (depType, user, repo) {
const endpoint = `https://david-dm.org/${user}/${repo}/info.json`
const prefix = {
'dep': '',
'dev': 'dev-',
'peer': 'peer-',
'optional': 'optional-'
}[depType]
const endpoint = `https://david-dm.org/${user}/${repo}/${prefix}info.json`
const { status } = await axios.get(endpoint).then(res => res.data)
switch (depType) {
@ -19,5 +25,23 @@ module.exports = async function (depType, user, repo) {
status: statusInfo[status][0],
color: statusInfo[status][1]
}
case 'dev':
return {
subject: 'devDependencies',
status: statusInfo[status][0],
color: statusInfo[status][1]
}
case 'peer':
return {
subject: 'peerDependencies',
status: statusInfo[status][0],
color: statusInfo[status][1]
}
case 'optional':
return {
subject: 'optionalDependencies',
status: statusInfo[status][0],
color: statusInfo[status][1]
}
}
}

6
libs/setup-live-badge.js

@ -13,10 +13,10 @@ module.exports = function (router) {
fail = false
} = await fetchLiveParams(name, fn, params['*'])
const sharedMaxAge = fail ? '0' : (Math.random() * 60 + 60).toFixed()
const sharedMaxAge = fail ? '0' : (Math.random() * 240 + 120).toFixed()
res.writeHead(200, {
'Content-Type': 'image/svg+xml;charset=utf-8',
'Cache-Control': 'public, max-age=20, s-maxage=' + sharedMaxAge
'Cache-Control': 'public, max-age=30, s-maxage=' + sharedMaxAge
})
res.end(badgen({subject, status, color, style}))
})
@ -29,7 +29,7 @@ async function fetchLiveParams (scope, fn, paramsPath) {
console.time(fetchKey)
waitings[fetchKey] = fn(...paramsPath.split('/')).catch(e => {
console.error(fetchKey, e)
console.error(fetchKey, 'LIVE_ERROR', e.message)
return { fail: true }
}).then(result => {
console.timeEnd(fetchKey)

Loading…
Cancel
Save