* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * reformat all the things (prettier 3) * update tests to await calls to prettier.format() --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: chris48s <git@chris-shaw.dev>
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import { fileURLToPath, URL } from 'url'
|
|
import config from 'config'
|
|
import got from 'got'
|
|
import emojic from 'emojic'
|
|
import Server from '../core/server/server.js'
|
|
import trace from '../core/base-service/trace.js'
|
|
|
|
function normalizeBadgeUrl(url) {
|
|
// Provide a base URL in order to accept fragments.
|
|
const { pathname, searchParams } = new URL(url, 'http://example.com')
|
|
let newPath = pathname.replace('.svg', '')
|
|
if (!newPath.endsWith('.json')) {
|
|
newPath = `${newPath}.json`
|
|
}
|
|
return `${newPath}?${searchParams.toString()}`
|
|
}
|
|
|
|
async function traceBadge(badgeUrl) {
|
|
const server = new Server(config.util.toObject())
|
|
await server.start()
|
|
const body = await got(
|
|
`${server.baseUrl.replace(/\/$/, '')}${badgeUrl}`,
|
|
).json()
|
|
trace.logTrace('outbound', emojic.shield, 'Rendered badge', body)
|
|
await server.stop()
|
|
}
|
|
|
|
async function main() {
|
|
if (process.argv.length < 3) {
|
|
console.error(`Usage: node ${fileURLToPath(import.meta.url)} badge-url`)
|
|
process.exit(1)
|
|
}
|
|
const [, , url] = process.argv
|
|
const normalized = normalizeBadgeUrl(url)
|
|
await traceBadge(normalized)
|
|
}
|
|
|
|
;(async () => {
|
|
try {
|
|
await main()
|
|
} catch (e) {
|
|
console.error(e)
|
|
process.exit(1)
|
|
}
|
|
})()
|