check-icons-unicodes.mjs 811 B

12345678910111213141516171819202122232425262728293031323334
  1. import glob from 'glob'
  2. import fs from 'fs'
  3. import path from 'path'
  4. import { ICONS_SRC_DIR } from './helpers.mjs'
  5. let unicodes = []
  6. glob(path.join(ICONS_SRC_DIR, '*.svg'), {}, function(er, files) {
  7. for (const i in files) {
  8. const file = files[i]
  9. let svgFile = fs.readFileSync(file).toString()
  10. const matches = svgFile.match(/\nunicode: "?([a-f0-9.]+)"?/i)
  11. if (matches[1]) {
  12. const unicode = matches[1]
  13. console.log('unicode', unicode, unicodes.indexOf(unicode));
  14. if (unicode && unicodes.indexOf(unicode) === -1) {
  15. unicodes.push(unicode)
  16. } else {
  17. throw new Error(`Unicode ${unicode} in icon ${file} already exists!`)
  18. }
  19. } else {
  20. throw new Error(`Icon ${file} don't have a unicode!`)
  21. }
  22. }
  23. console.log('unicodes', unicodes);
  24. })