UNPKG

1.29 kBJavaScriptView Raw
1#!/usr/bin/env node
2/* eslint-disable no-console */
3
4const _ = require('lodash');
5const fs = require('fs');
6const path = require('path');
7const yargs = require('yargs');
8const generateIconSetFromCss = require('../lib/generate-icon-set-from-css');
9
10const { 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 lodash 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
26let template;
27if (argv.template) {
28 template = fs.readFileSync(argv.template, { encoding: 'utf8' });
29}
30
31const data = _.omit(
32 argv,
33 '_ $0 o output p prefix t template g glyphmap'.split(' ')
34);
35
36const content = generateIconSetFromCss(argv._, argv.prefix, template, data);
37if (argv.output) {
38 fs.writeFileSync(argv.output, content);
39} else {
40 console.log(content);
41}
42
43if (argv.glyphmap) {
44 fs.writeFileSync(argv.glyphmap, generateIconSetFromCss(argv._, argv.prefix));
45}