All files index.ts

84.84% Statements 28/33
75% Branches 6/8
100% Functions 3/3
84.84% Lines 28/33

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 60 61 62 63 64 65 66 67 68 69 70                            1x                         1x         1x 1x       1x 1x         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x    
import minimist, { ParsedArgs } from 'minimist';
import { create } from './create';
import { BadgeOption } from './badges';
 
export interface RunArgvs extends ParsedArgs, Partial<BadgeOption> {
  source?: string;
  version?: string;
  output?: string;
  jsonPath?: string;
  /// <Color RGB> or <Color Name> (default: '555')
  labelColor?: string;
}
 
export default function run() {
  const argvs: RunArgvs = minimist(process.argv.slice(2), {
    alias: {
      help: 'h',
      source: 's',
      output: 'o',
    },
    default: {
      style: 'classic',
      source: 'coverage/coverage-summary.json',
      output: 'coverage/badges.svg',
      jsonPath: 'total.statements.pct',
    },
  });
  Iif (argvs.h || argvs.help) {
    cliHelp()
    exampleHelp()
    return;
  }
  const { version } = require('../package.json');
  Iif (argvs.v || argvs.version) {
    console.log(`\n coverage-badges-cli v${version}\n`);
    return;
  }
  console.log("argvs: ", argvs);  
  create(argvs);
}
 
 
export function cliHelp() {
  console.log('\n  Usage: coverage-badges [options] [--help|h]');
  console.log('\n  Options:\n');
  console.log('    --version, -v  ','Show version number');
  console.log('    --help, -h     ','Displays help information.');
  console.log('    --output, -o   ','Output directory.');
  console.log('    --source, -s   ','The path of the target file "coverage-summary.json".');
  console.log('    --style        ','Badges style: flat, flat-square.');
  console.log('    --type         ','Coverage type: lines, statements, functions, branches.');
  console.log('    --scale        ','Set badge scale (default: 1)');
  console.log('    --icon         ','Path to icon file');
  console.log('    --iconWidth    ','Set this if icon is not square (default: 13)');
  console.log('    --label        ','The left label of the badge, usually static (default `coverage`).');
  console.log('    --labelColor   ','<Color RGB> or <Color Name> (default: "555")');
  console.log('    --color        ','<Color RGB> or <Color Name> (default: "")');
  console.log('    --jsonPath     ','Path to the coverage percentage number to be used in the badge.');
  console.log('    --arbitrary    ','Allow jsonPath to point to non-number values. Works in conjunction with jsonPath (default false).');
}
 
export function exampleHelp() {
  console.log('\n  Example:\n');
  console.log('    \x1b[35mnpm\x1b[0m coverage-badges-cli \x1b[33m--output\x1b[0m coverage/badges.svg');
  console.log('    \x1b[35mnpm\x1b[0m coverage-badges-cli \x1b[33m--style\x1b[0m plastic');
  console.log('    \x1b[35mnpm\x1b[0m coverage-badges-cli \x1b[33m--source\x1b[0m coverage/coverage-summary.json');
  console.log('    \x1b[35mnpm\x1b[0m coverage-badges-cli \x1b[33m--labelColor\x1b[0m ADF');
  console.log('\n');
}