Code coverage report for bin/documentation.js

Statements: 100% (29 / 29)      Branches: 87.5% (7 / 8)      Functions: 100% (3 / 3)      Lines: 100% (29 / 29)      Ignored: none     

All files » bin/ » documentation.js
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104        24             24 18   24     24     1                                                                               23 23 2   23   23     23 2 2 2 2     21 2 2 1 1   1 1       20               24 20 20 60   20      
#!/usr/bin/env node
 
'use strict';
 
var documentation = require('../'),
  path = require('path'),
  yargs = require('yargs'),
  extend = require('extend'),
  loadConfig = require('../lib/load_config.js'),
  commands = require('../lib/commands');
 
var parsedArgs = parseArgs();
commands[parsedArgs.command](documentation, parsedArgs);
 
function parseArgs() {
  // reset() needs to be called at parse time because the yargs module uses an
  // internal global variable to hold option state
  var argv = yargs
    .usage('Usage: $0 <command> [options]')
    .version(function () {
      return require('../package').version;
    })
    .option('shallow', {
      describe: 'shallow mode turns off dependency resolution, ' +
      'only processing the specified files (or the main script specified in package.json)',
      default: false,
      type: 'boolean'
    })
    .option('config', {
      describe: 'configuration file. an array defining explicit sort order',
      alias: 'c'
    })
    .option('external', {
      describe: 'a string / glob match pattern that defines which external ' +
        'modules will be whitelisted and included in the generated documentation.',
      default: null
    })
    .option('extension', {
      describe: 'only input source files matching this extension will be parsed, ' +
        'this option can be used multiple times.',
      alias: 'e'
    })
    .option('polyglot', {
      type: 'boolean',
      describe: 'polyglot mode turns off dependency resolution and ' +
        'enables multi-language support. use this to document c++'
    })
    .option('private', {
      describe: 'generate documentation tagged as private',
      type: 'boolean',
      default: false,
      alias: 'p'
    })
    .option('github', {
      type: 'boolean',
      describe: 'infer links to github in documentation',
      alias: 'g'
    })
  .argv;
 
  var options = {};
  if (argv.config) {
    options = loadConfig(argv.config);
  }
  options = extend(options, argv);
 
  var command = argv._[0],
    inputs = argv._.slice(1);
 
  if (!commands[command]) {
    yargs.showHelp();
    var suggestion = [argv['$0'], 'build'].concat(process.argv.slice(2)).join(' ');
    process.stderr.write('Unknown command: ' + command + '.  Did you mean "' + suggestion + '"?\n');
    process.exit(1);
  }
 
  if (inputs.length == 0) {
    try {
      var p = require(path.resolve('package.json'));
      options.package = p;
      inputs = [p.main || 'index.js'];
    } catch (e) {
      yargs.showHelp();
      throw new Error('documentation was given no files and was not run in a module directory');
    }
  }
 
  return {
    inputs: inputs,
    command: command,
    commandOptions: addCommands(yargs).argv,
    options: options
  };
}
 
function addCommands(parser) {
  parser = parser.demand(1);
  for (var cmd in commands) {
    parser = parser.command(cmd, commands[cmd].description, commands[cmd].parseArgs);
  }
  return parser.help('help');
}