From eaa7a6a6a3df939a693ea51341dde9fe3f42e1d2 Mon Sep 17 00:00:00 2001 From: codecalm Date: Wed, 25 Jan 2023 23:17:35 +0100 Subject: [PATCH] check unicodes script --- .build/check-icons-unicodes.mjs | 34 +++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .build/check-icons-unicodes.mjs diff --git a/.build/check-icons-unicodes.mjs b/.build/check-icons-unicodes.mjs new file mode 100644 index 000000000..5eccc6145 --- /dev/null +++ b/.build/check-icons-unicodes.mjs @@ -0,0 +1,34 @@ +import glob from 'glob' +import fs from 'fs' +import path from 'path' +import { ICONS_SRC_DIR } from './helpers.mjs' + +let unicodes = [] + +glob(path.join(ICONS_SRC_DIR, '*.svg'), {}, function(er, files) { + for (const i in files) { + const file = files[i] + + let svgFile = fs.readFileSync(file).toString() + const matches = svgFile.match(/\nunicode: "?([a-f0-9.]+)"?/i) + + if (matches[1]) { + const unicode = matches[1] + + console.log('unicode', unicode, unicodes.indexOf(unicode)); + + if (unicode && unicodes.indexOf(unicode) === -1) { + unicodes.push(unicode) + } else { + throw new Error(`Unicode ${unicode} in icon ${file} already exists!`) + } + } else { + throw new Error(`Icon ${file} don't have a unicode!`) + } + } + + + console.log('unicodes', unicodes); +}) + + diff --git a/package.json b/package.json index 98f9b60a5..5cd6b2d5d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "changelog": "node ./.build/changelog.mjs", "changelog-commit": "node ./.build/changelog-commit.mjs", "changelog-image": "node ./.build/changelog-image.mjs", - "update": "pnpm run update:icons-version && pnpm run update:icons-unicode", + "check-unicodes": "node ./.build/check-icons-unicodes.mjs", + "update": "pnpm run update:icons-version && pnpm run update:icons-unicode && pnpm run check-unicodes", "update:icons-version": "node ./.build/update-icons-version.mjs", "update:icons-unicode": "node ./.build/update-icons-unicode.mjs", "optimize": "node ./.build/optimize.mjs",