import-categories.mjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { glob } from 'glob'
  2. import fs from 'fs'
  3. import { resolve, join, basename } from 'path'
  4. import { ICONS_SRC_DIR } from './helpers.mjs'
  5. // const extensions = ['heart', 'star', 'off', 'bolt', 'cancel', 'check', 'cog', 'dollar', 'dot', 'eco', 'edit', 'x', 'plus', 'minus', 'shield', 'up', 'down', 'move', 'link', 'ribbon', 'question', 'exclamation', '2', '3', 'code', 'pause', 'pin', 'search', 'share', 'hand', 'infinity', 'ai']
  6. const extensions = ['off', 'ai', 'spark']
  7. extensions.forEach(function (extension) {
  8. glob.sync(join(ICONS_SRC_DIR, `outline/*-${extension}.svg`)).forEach(function (file, i) {
  9. const fileOriginal = file.replace(`-${extension}.svg`, '.svg')
  10. if (fs.existsSync(fileOriginal)) {
  11. const dataOriginal = fs.readFileSync(fileOriginal).toString()
  12. const categoryOriginal = dataOriginal.match(/category: ([a-zA-Z-]+)/),
  13. tagsOriginal = dataOriginal.match(/tags: (\[.*?\])/)
  14. if (categoryOriginal || tagsOriginal) {
  15. let data = fs.readFileSync(file).toString()
  16. data = data.replace(/(\<\!--[\s\S]+?-->)/, function (m, headerContent) {
  17. console.log('categoryOriginal', fileOriginal, categoryOriginal && categoryOriginal[1], tagsOriginal && tagsOriginal[1])
  18. if (categoryOriginal) {
  19. headerContent = headerContent.replace(/category: .*\n/, '')
  20. headerContent = headerContent.replace(/\<\!--/, `<!--\ncategory: ${categoryOriginal[1]}`)
  21. }
  22. if (tagsOriginal) {
  23. headerContent = headerContent.replace(/tags: .*\n/, '')
  24. headerContent = headerContent.replace(/\<\!--/, `<!--\ntags: ${tagsOriginal[1]}`)
  25. }
  26. return headerContent
  27. })
  28. fs.writeFileSync(file, data)
  29. }
  30. }
  31. })
  32. })