build-webfont.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { webfont } from "webfont";
  2. import * as fs from 'fs'
  3. import template from 'lodash.template'
  4. import { getPackageDir, getPackageJson, PACKAGES_DIR } from '../../../.build/helpers.mjs'
  5. const formats = ['ttf', 'eot', 'woff', 'woff2']
  6. const p = getPackageJson()
  7. const DIR = getPackageDir('icons-webfont')
  8. const fontHeight = 1000
  9. webfont({
  10. files: 'icons-outlined/*.svg',
  11. fontName: 'tabler-icons',
  12. prependUnicode: true,
  13. formats,
  14. normalize: true,
  15. fontHeight,
  16. descent: 100,
  17. ascent: 986.5,
  18. fixedWidth: true
  19. })
  20. .then((result) => {
  21. formats.forEach(format => {
  22. fs.writeFileSync(`${PACKAGES_DIR}/icons-webfont/fonts/tabler-icons.${format}`, result[format])
  23. })
  24. const glyphs = result.glyphsData
  25. .map(icon => icon.metadata)
  26. .sort(function(a, b) {
  27. return ('' + a.name).localeCompare(b.name)
  28. })
  29. let options = {
  30. fileName: 'tabler-icons',
  31. glyphs,
  32. v: p.version
  33. }
  34. //scss
  35. const compiled = template(fs.readFileSync(`${DIR}/.build/iconfont.scss`).toString())
  36. const resultSCSS = compiled(options)
  37. fs.writeFileSync(`${DIR}/tabler-icons.scss`, resultSCSS)
  38. //html
  39. const compiledHtml = template(fs.readFileSync(`${DIR}/.build/iconfont.html`).toString())
  40. const resultHtml = compiledHtml(options)
  41. fs.writeFileSync(`${DIR}/tabler-icons.html`, resultHtml)
  42. })
  43. .catch((error) => {
  44. throw error;
  45. });