Proxy badge lookup for shields.io
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

getBadgeUrl.js 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const RESOLVE = require('./resolve.json')
  2. const loadBrands = require('./loadBrands')
  3. const getLibraryColor = require('./getLibraryColor')
  4. module.exports = async ({
  5. type,
  6. repo,
  7. dependency: library,
  8. kind,
  9. color,
  10. }) => {
  11. if (!repo) {
  12. return null
  13. }
  14. const labelColor = '666666'
  15. const logoColor = 'ffffff'
  16. const style = 'flat-square'
  17. let badgeUrl
  18. switch (type) {
  19. case 'version':
  20. badgeUrl = new URL(`/badge/dynamic/json`, process.env.SHIELDS_IMAGE_BASE_URL)
  21. badgeUrl.search = new URLSearchParams({
  22. color,
  23. query: '$.version',
  24. label: repo,
  25. style,
  26. labelColor,
  27. }).toString()
  28. return badgeUrl
  29. case 'dependency':
  30. const brands = await loadBrands()
  31. const libraryInfo = getLibraryColor(library, brands, RESOLVE)
  32. const libraryColor = libraryInfo ? libraryInfo.color.replace('#', '') : `${labelColor}`
  33. badgeUrl = new URL(`/badge/dynamic/json`, process.env.SHIELDS_IMAGE_BASE_URL)
  34. badgeUrl.search = new URLSearchParams({
  35. color: libraryColor,
  36. label: library,
  37. query: `$.${kind}['${library}']`,
  38. labelColor,
  39. logo: libraryInfo.name,
  40. logoColor,
  41. style,
  42. })
  43. return badgeUrl
  44. default:
  45. break
  46. }
  47. return null
  48. }