Code coverage report for yeoman-generator/lib/actions/invoke.js

Statements: 80% (16 / 20)      Branches: 43.75% (7 / 16)      Functions: 33.33% (1 / 3)      Lines: 80% (16 / 20)      Ignored: none     

All files » yeoman-generator/lib/actions/ » invoke.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  1                       1 4 4 4   4   4           4       4       4       4 4 4   4 4   4    
'use strict';
var path = require('path');
 
/**
 * Receives a `namespace`, and an Hash of `options` to invoke a given
 * generator. The usual list of arguments can be set with `options.args`
 * (ex. nopt's argv.remain array)
 *
 * @param {String} namespace
 * @param {Object} options
 * @param {Function} cb
 */
 
module.exports = function invoke(namespace, options, cb) {
  cb = cb || function () {};
  options = options || {};
  options.args = options.args || [];
 
  var generator = this.env.create(namespace, options);
 
  Iif (!generator.sourceRoot()) {
    generator.sourceRoot(path.join(path.dirname(generator.resolved), 'templates'));
  }
 
  // validate the generator (show help on missing arguments/options)
  // also show help if --help was specifically passed
  var requiredArgs = generator._arguments.some(function (arg) {
    return arg.config && arg.config.required;
  });
 
  Iif (!options.args.length && requiredArgs) {
    return console.log(generator.help());
  }
 
  Iif (options.help) {
    return console.log(generator.help());
  }
 
  this.log.emit('up');
  this.log.invoke(namespace);
  this.log.emit('up');
 
  generator.on('end', this.log.emit.bind(this.log, 'down'));
  generator.on('end', this.log.emit.bind(this.log, 'down'));
 
  return generator.run(cb);
};