diff --git a/getBadgeUrl.js b/getBadgeUrl.js index 8fb2d46..242f7f6 100644 --- a/getBadgeUrl.js +++ b/getBadgeUrl.js @@ -1,6 +1,3 @@ -const axios = require('axios') -const path = require('path') - const RESOLVE = require('./resolve.json') const loadBrands = require('./loadBrands') const getLibraryColor = require('./getLibraryColor') @@ -9,48 +6,38 @@ module.exports = async ({ type, repo, dependency: library, + kind, color, }) => { if (!repo) { return null } - const labelColor = '666666' const logoColor = 'ffffff' const style = 'flat-square' - const { data, } = await axios({ - method: 'GET', - url: path.join(process.env.REPO_BASE_URL, repo, 'raw', 'branch', process.env.MAIN_BRANCH, 'package.json') - }) - - const { name, version, dependencies, devDependencies, } = data - let badgeUrl switch (type) { case 'version': - badgeUrl = new URL(`/badge/${name.replace(/-/g, '--')}-${version}-${color}`, process.env.SHIELDS_IMAGE_BASE_URL) + 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': - let libraryVersion - if (Object.keys(dependencies).includes(library)) { - libraryVersion = dependencies[library] - } else if (Object.keys(devDependencies).includes(library)) { - libraryVersion = devDependencies[library] - } else { - libraryVersion = '0.0.0' - } - const brands = await loadBrands() const libraryInfo = getLibraryColor(library, brands, RESOLVE) const libraryColor = libraryInfo ? libraryInfo.color.replace('#', '') : `${labelColor}` - badgeUrl = new URL(`/badge/${library.replace(/-/g, '--')}-${libraryVersion}-${libraryColor}`, process.env.SHIELDS_IMAGE_BASE_URL) + 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, diff --git a/index.js b/index.js index f799600..82358ce 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ const server = http.createServer(async (req, res) => { }), {} ) + const badgeUrl = await getBadgeUrl(searchParams) if (badgeUrl === null) {