All files / bin svgicons2svgfont.js

83.33% Statements 10/12
50% Branches 4/8
66.67% Functions 2/3
81.82% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96          3x 3x 3x   3x 3x   3x                                                                                                           3x         41x   3x                                            
#! /usr/bin/env node
/* eslint-disable prefer-reflect */
 
'use strict';
 
const program = require('commander');
const fs = require('fs');
const glob = require('glob');
 
const SVGIcons2SVGFontStream = require('../src/index.js');
const SVGIconsDirStream = require('../src/iconsdir.js');
 
program
  .version(require('../package').version)
  .usage('[options] <icons ...>')
  .option('-v, --verbose', 'tell me everything!')
  .option('-o, --output [/dev/stdout]', 'file to write output to')
  .option('-f, --fontname [value]', 'the font family name you want [iconfont]')
  .option('-i, --fontId [value]', 'the font id you want [fontname]')
  .option('-st, --style [value]', 'the font style you want')
  .option('-we, --weight [value]', 'the font weight you want')
  .option(
    '-w, --fixedWidth',
    'creates a monospace font of the width of the largest input icon'
  )
  .option(
    '-c, --centerhorizontally',
    'calculate the bounds of a glyph and center it horizontally'
  )
  .option(
    '-y, --centerVertically',
    'centers the glyphs vertically in the generated font.'
  )
  .option(
    '-n, --normalize',
    'normalize icons by scaling them to the height of the highest icon'
  )
  .option(
    '-h, --height [value]',
    'the output font height [MAX(icons.height)] (icons will be scaled so the highest has this height)',
    parseInt
  )
  .option(
    '-r, --round [value]',
    'setup the SVG path rounding [10e12]',
    parseFloat
  )
  .option('-d, --descent [value]', 'the font descent [0]', parseInt)
  .option(
    '-a, --ascent [value]',
    'the font ascent [height - descent]',
    parseInt
  )
  .option(
    '-s, --startunicode [value]',
    'the start unicode codepoint for' + ' unprefixed files [0xEA01]',
    parseInt
  )
  .option(
    '-a, --prependUnicode',
    'prefix files with their automatically' + ' allocated unicode code point',
    parseInt
  )
  .option('-m, --metadata', 'content of the metadata tag')
  .parse(process.argv);
 
Iif (!program.args.length) {
  console.error('No icons specified!'); // eslint-disable-line
  process.exit(1);
}
 
const files = program.args.flatMap((file) => glob.sync(file));
 
new SVGIconsDirStream(files, {
  startUnicode: program.startunicode,
  prependUnicode: program.prependUnicode,
  log: program.v ? console.log : function () {}, // eslint-disable-line
})
  .pipe(
    new SVGIcons2SVGFontStream({
      fontName: program.fontname,
      fontId: program.fontId,
      fixedWidth: program.fixedwidth,
      centerHorizontally: program.centerHorizontally,
      centerVertically: program.centerVertically,
      normalize: program.normalize,
      fontHeight: program.height,
      round: program.round,
      descent: program.descent,
      ascent: program.ascent,
      metadata: program.metadata,
      log: program.v ? console.log : function () {}, // eslint-disable-line
    })
  )
  .pipe(program.output ? fs.createWriteStream(program.output) : process.stdout);