From a3016167df962509b94927c541ad4e66b208108e Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 19:27:23 +0300 Subject: [PATCH 1/4] Update check-icons.js * return early * use `path.basename` and `path.extname` --- build/check-icons.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/build/check-icons.js b/build/check-icons.js index 2fd5202c01..694637c4d9 100755 --- a/build/check-icons.js +++ b/build/check-icons.js @@ -21,35 +21,37 @@ 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 => path.basename(file, path.extname(file))) 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:')) + if (onlyInJson.length === 0 || onlyInSvg === 0) { + console.log(picocolors.green('Success, found no differences!')) + console.timeEnd(timeLabel) - for (const icon of onlyInJson) { - console.log(` - ${picocolors.red(icon)}`) - } + return + } + + if (onlyInJson.length > 0) { + console.error(picocolors.red('Found additional icons in JSON:')) - process.exit(1) + for (const icon of onlyInJson) { + console.log(` - ${picocolors.red(icon)}`) } - if (onlyInSvg.length > 0) { - console.error(picocolors.red('Found additional icons in SVG files:')) + process.exit(1) + } - for (const icon of onlyInSvg) { - console.log(` - ${picocolors.red(icon)}`) - } + if (onlyInSvg.length > 0) { + console.error(picocolors.red('Found additional icons in SVG files:')) - process.exit(1) + for (const icon of onlyInSvg) { + console.log(` - ${picocolors.red(icon)}`) } - } - console.log(picocolors.green('Success, found no differences!')) - console.timeEnd(timeLabel) + process.exit(1) + } } catch (error) { console.error(error) process.exit(1) From 60d5234172e1762144747b672f264e19bec3428b Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 22:15:03 +0300 Subject: [PATCH 2/4] Move process.exit --- build/check-icons.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build/check-icons.js b/build/check-icons.js index 694637c4d9..d2fd5dd715 100755 --- a/build/check-icons.js +++ b/build/check-icons.js @@ -39,8 +39,6 @@ const jsonIconList = Object.keys(fontJson) for (const icon of onlyInJson) { console.log(` - ${picocolors.red(icon)}`) } - - process.exit(1) } if (onlyInSvg.length > 0) { @@ -49,9 +47,9 @@ const jsonIconList = Object.keys(fontJson) for (const icon of onlyInSvg) { console.log(` - ${picocolors.red(icon)}`) } - - process.exit(1) } + + process.exit(1) } catch (error) { console.error(error) process.exit(1) From d6a8ced587b8f8cddc76b64ef1c78fa41c2c4386 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 27 Mar 2023 22:18:16 +0300 Subject: [PATCH 3/4] Move variables --- build/check-icons.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build/check-icons.js b/build/check-icons.js index d2fd5dd715..22832e9530 100755 --- a/build/check-icons.js +++ b/build/check-icons.js @@ -8,9 +8,6 @@ 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 { @@ -20,7 +17,9 @@ const jsonIconList = Object.keys(fontJson) console.log(picocolors.cyan(`[${basename}] started`)) console.time(timeLabel) + const iconsDir = path.join(__dirname, '../icons/') const files = await fs.readdir(iconsDir) + const jsonIconList = Object.keys(fontJson) const svgIconList = files.map(file => path.basename(file, path.extname(file))) const onlyInJson = jsonIconList.filter(icon => !svgIconList.includes(icon)) From 037b125960c385732f52b9dbab33861f1d3e63ba Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 28 Mar 2023 08:42:31 +0300 Subject: [PATCH 4/4] More --- build/check-icons.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/build/check-icons.js b/build/check-icons.js index 22832e9530..73f1a5bad5 100755 --- a/build/check-icons.js +++ b/build/check-icons.js @@ -7,7 +7,8 @@ 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 fontJsonPath = path.join(__dirname, '../font/bootstrap-icons.json') +const iconsDir = path.join(__dirname, '../icons/') ;(async () => { try { @@ -17,10 +18,12 @@ const fontJson = require(path.join(__dirname, '../font/bootstrap-icons.json')) console.log(picocolors.cyan(`[${basename}] started`)) console.time(timeLabel) - const iconsDir = path.join(__dirname, '../icons/') - const files = await fs.readdir(iconsDir) + const fontJsonString = await fs.readFile(fontJsonPath, 'utf8') + const fontJson = JSON.parse(fontJsonString) + const svgFiles = await fs.readdir(iconsDir) + const jsonIconList = Object.keys(fontJson) - const svgIconList = files.map(file => path.basename(file, path.extname(file))) + const svgIconList = svgFiles.map(svg => path.basename(svg, path.extname(svg))) const onlyInJson = jsonIconList.filter(icon => !svgIconList.includes(icon)) const onlyInSvg = svgIconList.filter(icon => !jsonIconList.includes(icon)) @@ -33,7 +36,7 @@ const fontJson = require(path.join(__dirname, '../font/bootstrap-icons.json')) } if (onlyInJson.length > 0) { - console.error(picocolors.red('Found additional icons in JSON:')) + console.error(picocolors.red(`Found additional icons in ${fontJsonPath}:`)) for (const icon of onlyInJson) { console.log(` - ${picocolors.red(icon)}`)