check-icons-unicodes.mjs 705 B

1234567891011121314151617181920212223242526272829
  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. if (unicode && unicodes.indexOf(unicode) === -1) {
  14. unicodes.push(unicode)
  15. } else {
  16. throw new Error(`Unicode ${unicode} in icon ${file} already exists!`)
  17. }
  18. } else {
  19. throw new Error(`Icon ${file} don't have a unicode!`)
  20. }
  21. }
  22. })