Code coverage report for lib/setup-bundlers.js

Statements: 100% (23 / 23)      Branches: 100% (18 / 18)      Functions: 100% (4 / 4)      Lines: 100% (23 / 23)      Ignored: none     

All files » lib/ » setup-bundlers.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 532   2       2         1 42       1 42 6     36     1 6 4     2     1 4 1     3   3 3 1     2 1       1      
module.exports = setupBundler
 
var findGlobals = require('find-global-packages')
  , resolve = require('resolve')
  , path = require('path')
 
var setupBrowserify = require('./bundlers/browserify.js')
  , setupWatchify = require('./bundlers/watchify.js')
 
// local watchify, local browserify ->
// global watchify, global browserify
function setupBundler(cwd, entryPoints, flags, noWatchify, ready) {
  noWatchify ?
    onlocalwatchify() :
    resolve('watchify', {basedir: cwd}, onlocalwatchify)
 
  function onlocalwatchify(err, localDir) {
    if(err || !localDir) {
      return resolve('browserify', {basedir: cwd}, onlocalbrowserify)
    }
 
    setupWatchify(path.dirname(localDir), entryPoints, flags, ready)
  }
 
  function onlocalbrowserify(err, localDir) {
    if(err || !localDir) {
      return findGlobals(onglobals)
    }
 
    setupBrowserify(path.dirname(localDir), entryPoints, flags, ready)
  }
 
  function onglobals(err, dirs) {
    if(err) {
      return ready(err)
    }
 
    dirs = dirs.sort()
 
    for(var i = 0, len = dirs.length; i < len; ++i) {
      if(!noWatchify && path.basename(dirs[i]) === 'watchify') {
        return setupWatchify(dirs[i], entryPoints, flags, ready)
      }
 
      if(path.basename(dirs[i]) === 'browserify') {
        return setupBrowserify(dirs[i], entryPoints, flags, ready)
      }
    }
 
    return ready(new Error('Could not find a suitable bundler!'))
  }
}