Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add a script to check font JSON for differences with SVGs #1657

Merged
merged 6 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions build/check-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

'use strict'

const fs = require('node:fs').promises
const path = require('node:path')
const process = require('node:process')
const picocolors = require('picocolors')

const fontJson = require(path.join(__dirname, '../font/bootstrap-icons.json'))
const iconsDir = path.join(__dirname, '../icons/')

const jsonIconList = Object.keys(fontJson)

;(async () => {
try {
const basename = path.basename(__filename)
const timeLabel = picocolors.cyan(`[${basename}] finished`)

console.log(picocolors.cyan(`[${basename}] started`))
console.time(timeLabel)

const files = await fs.readdir(iconsDir)
const svgIconList = files.map(file => file.slice(0, -4))

const onlyInJson = jsonIconList.filter(icon => !svgIconList.includes(icon))
const onlyInSvg = svgIconList.filter(icon => !jsonIconList.includes(icon))

if (onlyInJson.length !== 0 || onlyInSvg !== 0) {
if (onlyInJson.length > 0) {
console.error(picocolors.red('Found additional icons in JSON:'))

for (const icon of onlyInJson) {
console.log(` - ${picocolors.red(icon)}`)
}

process.exit(1)
}

if (onlyInSvg.length > 0) {
console.error(picocolors.red('Found additional icons in SVG files:'))

for (const icon of onlyInSvg) {
console.log(` - ${picocolors.red(icon)}`)
}

process.exit(1)
}
}

console.log(picocolors.green('Success, found no differences!'))
console.timeEnd(timeLabel)
} catch (error) {
console.error(error)
process.exit(1)
}
})()
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"test:stylelint": "stylelint docs/assets/scss/ --cache --cache-location node_modules/.cache/.stylelintcache --rd",
"test:lockfile-lint": "lockfile-lint --allowed-hosts npm --allowed-schemes https: --empty-hostname false --type npm --path package-lock.json",
"test:vnu": "node build/vnu-jar.js",
"test:check-icons": "node build/check-icons.js",
"test": "npm-run-all docs-build --parallel --aggregate-output --continue-on-error test:*"
},
"style": "font/bootstrap-icons.css",
Expand Down