build-outline.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import outlineStroke from 'svg-outline-stroke'
  2. import { asyncForEach, getCompileOptions, getPackageDir, HOME_DIR, readSvgs } from '../../../.build/helpers.mjs'
  3. import fs from 'fs'
  4. import { resolve } from 'path'
  5. const DIR = getPackageDir('icons-webfont')
  6. const buildOutline = async () => {
  7. let files = readSvgs()
  8. const compileOptions = getCompileOptions()
  9. const iconfontUnicode = JSON.parse(fs.readFileSync(resolve(HOME_DIR, 'tags.json'), 'utf-8'))
  10. await asyncForEach(files, async function({ name, contents }) {
  11. if (compileOptions.includeIcons.length === 0 || compileOptions.includeIcons.indexOf(name) >= 0) {
  12. if (iconfontUnicode[name]) {
  13. const unicode = iconfontUnicode[name].unicode
  14. await console.log('Stroke for:', name, unicode)
  15. contents = contents
  16. .replace('width="24"', 'width="1000"')
  17. .replace('height="24"', 'height="1000"')
  18. if (compileOptions.strokeWidth) {
  19. contents = contents
  20. .replace('stroke-width="2"', `stroke-width="${compileOptions.strokeWidth}"`)
  21. }
  22. await outlineStroke(contents, {
  23. optCurve: true,
  24. steps: 4,
  25. round: 0,
  26. centerHorizontally: true,
  27. fixedWidth: false,
  28. color: 'black'
  29. }).then(outlined => {
  30. if (unicode) {
  31. fs.writeFileSync(resolve(DIR, `icons-outlined/u${unicode.toUpperCase()}-${name}.svg`), outlined, 'utf-8')
  32. } else {
  33. fs.writeFileSync(resolve(DIR, `icons-outlined/${name}.svg`), outlined, 'utf-8')
  34. }
  35. }).catch(error => console.log(error))
  36. }
  37. }
  38. })
  39. }
  40. await buildOutline()