import-icons.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env node
  2. 'use strict'
  3. import { fileURLToPath } from 'node:url'
  4. import { readFileSync, writeFileSync } from 'node:fs'
  5. import path from 'node:path'
  6. import iconsTags from '../node_modules/@tabler/icons/tags.json' assert { type: "json" }
  7. import iconsPkg from '../node_modules/@tabler/icons/package.json' assert { type: "json" }
  8. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  9. const prepareSvgFile = (svg) => {
  10. return svg.replace(/\n/g, '').replace(/>\s+</g, '><')
  11. }
  12. let svgList = {}
  13. for (let iconName in iconsTags) {
  14. let iconData = iconsTags[iconName]
  15. svgList[iconName] = {
  16. name: iconName,
  17. version: iconData.version,
  18. category: iconData.category,
  19. tags: iconData.tags,
  20. unicode: iconData.unicode,
  21. svg: prepareSvgFile(
  22. readFileSync(
  23. path.join(
  24. __dirname,
  25. `../node_modules/@tabler/icons/icons/${iconName}.svg`
  26. )
  27. )
  28. .toString())
  29. }
  30. }
  31. writeFileSync(
  32. path.join(__dirname, `../preview/pages/_data/icons-info.json`),
  33. JSON.stringify({
  34. version: iconsPkg.version,
  35. count: Object.keys(svgList).length,
  36. })
  37. )
  38. writeFileSync(
  39. path.join(__dirname, `../preview/pages/_data/icons.json`),
  40. JSON.stringify(svgList)
  41. )