ソースを参照

Use dynamic URL

Remove dependency with Axios.
master
コミット
db8fb3547d
2個のファイルの変更10行の追加22行の削除
  1. +9
    -22
      getBadgeUrl.js
  2. +1
    -0
      index.js

+ 9
- 22
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,


+ 1
- 0
index.js ファイルの表示

@@ -17,6 +17,7 @@ const server = http.createServer(async (req, res) => {
}),
{}
)

const badgeUrl = await getBadgeUrl(searchParams)

if (badgeUrl === null) {


読み込み中…
キャンセル
保存