Proxy badge lookup for shields.io
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

53 líneas
1.3 KiB

  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. }