1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 | const fs = require('fs');
|
5 | const path = require('path');
|
6 | const yargs = require('yargs');
|
7 | const generateIconSetFromCss = require('../lib/generate-icon-set-from-css');
|
8 | const { omit } = require('../lib/object-utils');
|
9 |
|
10 | const { argv } = yargs
|
11 | .usage(
|
12 | 'Usage: $0 [options] path/to/styles.css \nFor default template please provide --componentName and --fontFamily'
|
13 | )
|
14 | .demand(1)
|
15 | .default('p', '.icon-')
|
16 | .describe('p', 'CSS selector prefix')
|
17 | .alias('p', 'prefix')
|
18 | .default('t', path.resolve(__dirname, '..', 'templates/bundled-icon-set.tpl'))
|
19 | .describe('t', 'Template in JS template string format')
|
20 | .alias('t', 'template')
|
21 | .describe('o', 'Save output to file, defaults to STDOUT')
|
22 | .alias('o', 'output')
|
23 | .describe('g', 'Save glyphmap JSON to file')
|
24 | .alias('g', 'glyphmap');
|
25 |
|
26 | let template;
|
27 | if (argv.template) {
|
28 | template = fs.readFileSync(argv.template, { encoding: 'utf8' });
|
29 | }
|
30 |
|
31 | const data = omit(
|
32 | argv,
|
33 | '_ $0 o output p prefix t template g glyphmap'.split(' ')
|
34 | );
|
35 |
|
36 | const content = generateIconSetFromCss(argv._, argv.prefix, template, data);
|
37 | if (argv.output) {
|
38 | fs.writeFileSync(argv.output, content);
|
39 | } else {
|
40 | console.log(content);
|
41 | }
|
42 |
|
43 | if (argv.glyphmap) {
|
44 | fs.writeFileSync(argv.glyphmap, generateIconSetFromCss(argv._, argv.prefix));
|
45 | }
|