import-icons.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const iconsPkg = require("../node_modules/@tabler/icons/package.json")
  2. const icons = require("../node_modules/@tabler/icons/tags.json")
  3. const fs = require("fs-extra")
  4. const path = require("path")
  5. const prepareSvgFile = (svg) => {
  6. return svg.replace(/\n/g, "").replace(/>\s+</g, "><")
  7. }
  8. let svgList = []
  9. for (let iconName in icons) {
  10. let iconData = icons[iconName]
  11. svgList.push({
  12. name: iconName,
  13. version: iconData.version,
  14. category: iconData.category,
  15. tags: iconData.tags,
  16. unicode: iconData.unicode,
  17. svg: prepareSvgFile(
  18. fs
  19. .readFileSync(
  20. path.join(
  21. __dirname,
  22. `../node_modules/@tabler/icons/icons/${iconName}.svg`
  23. )
  24. )
  25. .toString()
  26. ),
  27. })
  28. }
  29. fs.writeFileSync(
  30. path.join(__dirname, `../data/icons.json`),
  31. JSON.stringify(svgList)
  32. )
  33. fs.writeFileSync(
  34. path.join(__dirname, `../data/icons-info.json`),
  35. JSON.stringify({
  36. version: iconsPkg.version,
  37. count: svgList.length,
  38. })
  39. )
  40. fs.copySync(path.join(__dirname, '../node_modules/@tabler/icons/icons'), path.join(__dirname, '../public/static/tabler-icons/icons'), { overwrite: true })
  41. fs.copySync(path.join(__dirname, '../node_modules/@tabler/icons-png/icons'), path.join(__dirname, '../public/static/tabler-icons/icons-png'), { overwrite: true })