const RESOLVE = require('./resolve.json') const loadBrands = require('./loadBrands') const getLibraryColor = require('./getLibraryColor') module.exports = async ({ type, repo, dependency: library, kind, color, }) => { if (!repo) { return null } const labelColor = '666666' const logoColor = 'ffffff' const style = 'flat-square' let badgeUrl switch (type) { case 'version': badgeUrl = new URL(`/badge/dynamic/json`, process.env.SHIELDS_IMAGE_BASE_URL) badgeUrl.search = new URLSearchParams({ color, query: '$.version', label: repo, style, labelColor, }).toString() return badgeUrl case 'dependency': const brands = await loadBrands() const libraryInfo = getLibraryColor(library, brands, RESOLVE) const libraryColor = libraryInfo ? libraryInfo.color.replace('#', '') : `${labelColor}` badgeUrl = new URL(`/badge/dynamic/json`, process.env.SHIELDS_IMAGE_BASE_URL) badgeUrl.search = new URLSearchParams({ color: libraryColor, label: library, query: `$.${kind}['${library}']`, labelColor, logo: libraryInfo.name, logoColor, style, }) return badgeUrl default: break } return null }