master
1#!/usr/bin/env node
2
3import allBadges from '#badges'
4import fs from 'node:fs'
5import { fileURLToPath } from 'node:url'
6import * as path from 'node:path'
7import { imageDimensionsFromStream } from 'image-dimensions'
8
9const expectedDimensions = 256
10
11const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
12
13let ok = true
14const processedBadges = new Set()
15for (const { default: b } of allBadges) {
16 const dirname = path.basename(path.dirname(fileURLToPath(b.url)))
17 for (const id of b.badges) {
18 const imagePath = path.join('badges', dirname, `${id}.png`)
19 const rootPath = path.join(root, imagePath)
20 if (!fs.existsSync(rootPath)) {
21 console.error(`Missing image for badge "${id}" at ${rootPath}`)
22 ok = false
23 }
24 const { width, height } = await imageDimensionsFromStream(
25 fs.createReadStream(rootPath),
26 )
27 if (width !== expectedDimensions || height !== expectedDimensions) {
28 console.error(
29 `Bad image dimensions for badge ${id}.png: ${width}x${height} (expected: ${expectedDimensions}x${expectedDimensions})`,
30 )
31 ok = false
32 }
33 if (processedBadges.has(id)) {
34 console.error(`Duplicate badge id: ${id} in ${dirname}`)
35 ok = false
36 }
37 processedBadges.add(id)
38 }
39}
40if (!ok) {
41 process.exit(1)
42} else {
43 console.log(
44 '✅ All images exist, have the expected dimensions, and have unique ids.',
45 )
46}