build.mjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import fs from 'fs'
  2. import { getAllIconsMerged, getAllIcons } from '../../.build/helpers.mjs'
  3. const iconsMerged = getAllIconsMerged()
  4. const icons = getAllIcons(true, true)
  5. const buildJSON = () => {
  6. console.log('Building icons.json')
  7. fs.writeFileSync(`./icons.json`, JSON.stringify(iconsMerged, null, 2))
  8. }
  9. const buildNodes = () => {
  10. console.log('Building tabler-nodes.json')
  11. Object.entries(icons).forEach(([type, icons]) => {
  12. const iconNodes = icons.reduce((acc, { name, obj }) => {
  13. acc[name] = obj.children.map(({ name, attributes }) => [name, attributes]);
  14. return acc;
  15. }, {});
  16. const iconNodesStringified = JSON.stringify(iconNodes, null, 2);
  17. fs.writeFileSync(`./tabler-nodes-${type}.json`, iconNodesStringified);
  18. })
  19. }
  20. const buildSvgs = () => {
  21. console.log('Building svgs')
  22. Object.entries(icons).forEach(([type, icons]) => {
  23. fs.mkdirSync(`./icons/${type}`, { recursive: true });
  24. icons.forEach(({ name, content, category }) => {
  25. fs.writeFileSync(`./icons/${type}/${name}.svg`, content);
  26. if (category) {
  27. fs.mkdirSync(`./categories/${type}/${category}`, { recursive: true });
  28. fs.writeFileSync(`./categories/${type}/${category}/${name}.svg`, content);
  29. }
  30. })
  31. })
  32. }
  33. buildJSON()
  34. buildNodes()
  35. buildSvgs()