All files cli.ts

0% Statements 0/11
0% Branches 0/6
0% Functions 0/2
0% Lines 0/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                                                                                                                     
#!/usr/bin/env node
 
import FS from 'fs-extra';
import yargs, { Arguments } from 'yargs';
import path from 'path';
import svgtofont from './';
import { log } from './log';
 
type ArgvResult = Arguments<{
  sources: string;
  output: string;
  fontName: string;
}>
 
const argv = yargs
  .alias('s', 'sources')
  .describe('s', 'The root from which all sources are relative.')
  .alias('o', 'output')
  .describe('o', 'Output directory.')
  .alias('f', 'fontName')
  .describe('f', 'Font Name.')
  .demandOption(['output', 'sources'])
  .help('h')
  .alias('h', 'help')
  .epilog('copyright 2019')
  .argv as ArgvResult;
 
const sourcesPath = path.resolve(process.cwd(), argv.sources);
const outputPath = path.resolve(process.cwd(), argv.output);
 
if (!FS.pathExistsSync(sourcesPath)) {
  log.error('The directory does not exist!', sourcesPath);
  process.exit();
}
 
if (!FS.pathExistsSync(outputPath)) {
  FS.mkdirpSync(outputPath);
}
 
svgtofont({
  src: sourcesPath, // svg path
  dist: outputPath, // output path
  // emptyDist: true, // Clear output directory contents
  fontName: (argv.fontName) || "svgfont", // font name
  css: true, // Create CSS files.
  outSVGReact: true,
  outSVGReactNative: false,
  outSVGPath: true,
  svgicons2svgfont: {
    fontHeight: 1000,
    normalize: true,
  },
})
.then(() => {
  log.log('done!');
}).catch((err) => {
  log.log('SvgToFont:ERR:', err);
});