Proxy badge lookup for shields.io
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

56 lignes
1.5 KiB

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