import-icons.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env node
  2. 'use strict'
  3. const fs = require('fs'),
  4. path = require('path');
  5. const iconsTags = require('../node_modules/@tabler/icons/icons.json'),
  6. iconsPkg = require('../node_modules/@tabler/icons/package.json');
  7. const prepareSvgFile = (svg) => {
  8. return svg.replace(/\n/g, '').replace(/>\s+</g, '><').replace(/\s+/g, ' ')
  9. }
  10. let svgList = {}
  11. for (let iconName in iconsTags) {
  12. let iconData = iconsTags[iconName]
  13. svgList[iconName] = {
  14. name: iconName,
  15. svg: {
  16. outline: iconData.styles.outline ? prepareSvgFile(fs.readFileSync(path.join(__dirname, `../node_modules/@tabler/icons/icons/outline/${iconName}.svg`), 'utf8')) : null,
  17. filled: iconData.styles.filled ? prepareSvgFile(fs.readFileSync(path.join(__dirname, `../node_modules/@tabler/icons/icons/filled/${iconName}.svg`), 'utf8')) : null,
  18. }
  19. }
  20. }
  21. fs.writeFileSync(
  22. path.join(__dirname, `../src/pages/_data/icons-info.json`),
  23. JSON.stringify({
  24. version: iconsPkg.version,
  25. count: Object.values(svgList).reduce((acc, icon) => {
  26. return acc + (icon.svg.outline ? 1 : 0) + (icon.svg.filled ? 1 : 0)
  27. }, 0)
  28. })
  29. )
  30. fs.writeFileSync(path.join(__dirname, `../src/pages/_data/icons.json`), JSON.stringify(svgList))