From 05dfb7fbf300d0dd7dd189c8d990f7c424b76c0d Mon Sep 17 00:00:00 2001 From: korki <65349313+korki43@users.noreply.github.com> Date: Sun, 26 Mar 2023 21:34:10 +0200 Subject: [PATCH 1/5] check font json for differences with svgs --- build/check-json.js | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 build/check-json.js diff --git a/build/check-json.js b/build/check-json.js new file mode 100755 index 0000000000..fbb85e43c1 --- /dev/null +++ b/build/check-json.js @@ -0,0 +1,46 @@ +#!/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 jsonIconList = Object.keys(fontJson) + +const iconsDir = path.join(__dirname, '../icons/'); + +(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(i => !svgIconList.includes(i)) + const onlyInSvg = svgIconList.filter(i => !jsonIconList.includes(i)) + + if(onlyInJson.length != 0 || onlyInSvg != 0) { + if(onlyInJson.length){ + console.error(picocolors.red("Found additional icons in JSON:\n %s"), onlyInJson.join(", ")) + } + if(onlyInSvg.length){ + console.error(picocolors.red("Found additional icons in SVG files:\n %s"), onlyInSvg.join(", ")) + } + throw new Error('Mismatch between JSON and SVG files') + } + + console.log(picocolors.green('\nSuccess, found no differences!')) + console.timeEnd(timeLabel) + } catch (error) { + console.error(error) + process.exit(1) + } +})() From de4ea0fbddab1370f6ffdd26a9d269dd98bdc1aa Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 18:43:22 +0300 Subject: [PATCH 2/5] Update check-json.js --- build/check-json.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/build/check-json.js b/build/check-json.js index fbb85e43c1..e8ecec9300 100755 --- a/build/check-json.js +++ b/build/check-json.js @@ -7,13 +7,12 @@ 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 jsonIconList = Object.keys(fontJson) +const iconsDir = path.join(__dirname, '../icons/') -const iconsDir = path.join(__dirname, '../icons/'); +const jsonIconList = Object.keys(fontJson) -(async () => { +;(async () => { try { const basename = path.basename(__filename) const timeLabel = picocolors.cyan(`[${basename}] finished`) @@ -24,16 +23,18 @@ const iconsDir = path.join(__dirname, '../icons/'); const files = await fs.readdir(iconsDir) const svgIconList = files.map(file => file.slice(0,-4)) - const onlyInJson = jsonIconList.filter(i => !svgIconList.includes(i)) - const onlyInSvg = svgIconList.filter(i => !jsonIconList.includes(i)) + 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){ - console.error(picocolors.red("Found additional icons in JSON:\n %s"), onlyInJson.join(", ")) + if (onlyInJson.length !== 0 || onlyInSvg !== 0) { + if (onlyInJson.length > 0) { + console.error(picocolors.red('Found additional icons in JSON:\n %s'), onlyInJson.join(', ')) } - if(onlyInSvg.length){ - console.error(picocolors.red("Found additional icons in SVG files:\n %s"), onlyInSvg.join(", ")) + + if (onlyInSvg.length > 0) { + console.error(picocolors.red('Found additional icons in SVG files:\n %s'), onlyInSvg.join(', ')) } + throw new Error('Mismatch between JSON and SVG files') } From 787f6168a977a6557a552b248f6014c2074a3af7 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 18:56:34 +0300 Subject: [PATCH 3/5] Split output --- build/check-json.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/build/check-json.js b/build/check-json.js index e8ecec9300..6ff0bb5d14 100755 --- a/build/check-json.js +++ b/build/check-json.js @@ -28,17 +28,25 @@ const jsonIconList = Object.keys(fontJson) if (onlyInJson.length !== 0 || onlyInSvg !== 0) { if (onlyInJson.length > 0) { - console.error(picocolors.red('Found additional icons in JSON:\n %s'), onlyInJson.join(', ')) + 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:\n %s'), onlyInSvg.join(', ')) - } + console.error(picocolors.red('Found additional icons in SVG files:')) - throw new Error('Mismatch between JSON and SVG files') + for (const icon of onlyInSvg) { + console.log(` - ${picocolors.red(icon)}`) + } + process.exit(1) + } } - console.log(picocolors.green('\nSuccess, found no differences!')) + console.log(picocolors.green('Success, found no differences!')) console.timeEnd(timeLabel) } catch (error) { console.error(error) From 942f2a74c5d7d8dcf5947f571f135669e2835125 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 18:57:29 +0300 Subject: [PATCH 4/5] Rename and add script to npm scripts --- build/{check-json.js => check-icons.js} | 0 package.json | 1 + 2 files changed, 1 insertion(+) rename build/{check-json.js => check-icons.js} (100%) diff --git a/build/check-json.js b/build/check-icons.js similarity index 100% rename from build/check-json.js rename to build/check-icons.js diff --git a/package.json b/package.json index af52d8af4f..c7d867a322 100644 --- a/package.json +++ b/package.json @@ -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", From 0a0f49d67ea1121356ca17d8666e49705831dc87 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 19:04:38 +0300 Subject: [PATCH 5/5] newlines --- build/check-icons.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/check-icons.js b/build/check-icons.js index 6ff0bb5d14..2fd5202c01 100755 --- a/build/check-icons.js +++ b/build/check-icons.js @@ -21,7 +21,7 @@ const jsonIconList = Object.keys(fontJson) console.time(timeLabel) const files = await fs.readdir(iconsDir) - const svgIconList = files.map(file => file.slice(0,-4)) + 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)) @@ -33,6 +33,7 @@ const jsonIconList = Object.keys(fontJson) for (const icon of onlyInJson) { console.log(` - ${picocolors.red(icon)}`) } + process.exit(1) } @@ -42,6 +43,7 @@ const jsonIconList = Object.keys(fontJson) for (const icon of onlyInSvg) { console.log(` - ${picocolors.red(icon)}`) } + process.exit(1) } }