1 | #! /usr/bin/env node
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const program = require('commander');
|
7 | const fs = require('fs');
|
8 | const glob = require('glob');
|
9 |
|
10 | const SVGIcons2SVGFontStream = require('../src/index.js');
|
11 | const SVGIconsDirStream = require('../src/iconsdir.js');
|
12 |
|
13 | program
|
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 | '-n, --normalize',
|
32 | 'normalize icons by scaling them to the height of the highest icon'
|
33 | )
|
34 | .option(
|
35 | '-h, --height [value]',
|
36 | 'the output font height [MAX(icons.height)] (icons will be scaled so the highest has this height)',
|
37 | parseInt
|
38 | )
|
39 | .option(
|
40 | '-r, --round [value]',
|
41 | 'setup the SVG path rounding [10e12]',
|
42 | parseFloat
|
43 | )
|
44 | .option('-d, --descent [value]', 'the font descent [0]', parseInt)
|
45 | .option(
|
46 | '-a, --ascent [value]',
|
47 | 'the font ascent [height - descent]',
|
48 | parseInt
|
49 | )
|
50 | .option(
|
51 | '-s, --startunicode [value]',
|
52 | 'the start unicode codepoint for' + ' unprefixed files [0xEA01]',
|
53 | parseInt
|
54 | )
|
55 | .option(
|
56 | '-a, --prependUnicode',
|
57 | 'prefix files with their automatically' + ' allocated unicode code point',
|
58 | parseInt
|
59 | )
|
60 | .option('-m, --metadata', 'content of the metadata tag')
|
61 | .parse(process.argv);
|
62 |
|
63 | if (!program.args.length) {
|
64 | console.error('No icons specified!');
|
65 | process.exit(1);
|
66 | }
|
67 |
|
68 | const files = program.args.flatMap(file => glob.sync(file));
|
69 |
|
70 | new SVGIconsDirStream(files, {
|
71 | startUnicode: program.startunicode,
|
72 | prependUnicode: program.prependUnicode,
|
73 | log: program.v ? console.log : function() {},
|
74 | })
|
75 | .pipe(
|
76 | new SVGIcons2SVGFontStream({
|
77 | fontName: program.fontname,
|
78 | fontId: program.fontId,
|
79 | fixedWidth: program.fixedwidth,
|
80 | centerHorizontally: program.centerHorizontally,
|
81 | normalize: program.normalize,
|
82 | fontHeight: program.height,
|
83 | round: program.round,
|
84 | descent: program.descent,
|
85 | ascent: program.ascent,
|
86 | metadata: program.metadata,
|
87 | log: program.v ? console.log : function() {},
|
88 | })
|
89 | )
|
90 | .pipe(program.output ? fs.createWriteStream(program.output) : process.stdout);
|