UNPKG

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