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

Statements: 100% (24 / 24)      Branches: 100% (5 / 5)      Functions: 100% (6 / 6)      Lines: 100% (24 / 24)      Ignored: none     

All files » yeoman-generator/lib/actions/ » fetch.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  3 3 3 3 3   3   3                     3 1 1   1   34       1 1                         3 5           5 5       5   84       5 5       3           3  
'use strict';
var fs = require('fs');
var path = require('path');
var request = require('request');
var download = require('download');
var chalk = require('chalk');
 
var fetch = module.exports;
 
var proxy = process.env.http_proxy || process.env.HTTP_PROXY ||
    process.env.https_proxy || process.env.HTTPS_PROXY || '';
 
/**
 * Download a string or an array of files to a given destination.
 *
 * @param {String|Array} url
 * @param {String} destination
 * @param {Function} cb
 */
 
fetch.fetch = function _fetch(url, destination, cb) {
  var dl = download(url, destination, { proxy: proxy });
  var log = this.log('... Fetching %s ...', url);
 
  return dl
    .on('data', function () {
      log.write('.');
    })
    .on('error', cb)
    .once('close', function () {
      log.ok('Done in ' + destination).write();
      cb();
    });
};
 
/**
 * Fetch a string or an array of archives and extract it/them to a given
 * destination.
 *
 * @param {String|Array} archive
 * @param {String} destination
 * @param {Function} cb
 */
 
fetch.extract = function _extract(archive, destination, cb) {
  var opts = {
    extract: true,
    proxy: proxy,
    strip: 1
  };
 
  var dl = download(archive, destination, opts);
  var log = this.log.write()
    .info('... Fetching %s ...', archive)
    .info(chalk.yellow('This might take a few moments'));
 
  return dl
    .on('data', function () {
      log.write('.');
    })
    .on('error', cb)
    .once('close', function () {
      log.ok('Done in ' + destination).write();
      cb();
    });
};
 
fetch.tarball = fetch.extract;
 
/**
 * Expose the request module set up with a proxy
 */
 
fetch.request = request.defaults({ proxy: proxy });