Code coverage report for beefy/lib/handlers/legacy-bundle.js

Statements: 36% (9 / 25)      Branches: 21.43% (3 / 14)      Functions: 33.33% (1 / 3)      Lines: 36% (9 / 25)      Ignored: none     

All files » beefy/lib/handlers/ » legacy-bundle.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 622   2                         1 11     11   11 11                 1                                                   1        
module.exports = handleEntryPoints
 
var accumError = require('../accumulate-error.js')
  , spawn = require('child_process').spawn
  , ansicolors = require('ansicolors')
 
// opts = {
//     entries: {
//         <repr>: <path>
//     }
//   , bundler: {
//         flags: []
//       , command: ""
//     }
// }
function handleEntryPoints(opts, io, nextHandler) {
  var entries = opts.entries
    , bundlerOpts
 
  bundlerOpts = opts.bundler
 
  Eif(!bundlerOpts || !bundlerOpts.legacy) {
    return nextHandler
  }
 
  if(!opts.entries || !opts.bundler) {
    return nextHandler
  }
 
  return handle
 
  function handle(server, req, resp, parsed) {
    if(!(parsed.pathname in entries) && !('browserify' in parsed.query)) {
      return nextHandler(server, req, resp, parsed)
    }
 
    var entryPath = entries[parsed.pathname]
      , args = bundlerOpts.flags.slice()
      , bundler
      , output
 
    if(entryPath) {
      args.unshift(entryPath)
    }
 
    args.unshift(bundlerOpts.command)
    parsed.loggedPathname = ansicolors.magenta(
        parsed.pathname + ' -> ' + args.map(toLocal).join(' ')
    )
    args.shift()
 
    bundler = spawn(bundlerOpts.command, args)
    bundler.stderr.pipe(accumError(io.error, resp))
    resp.setHeader('content-type', 'text/javascript')
    bundler.stdout.pipe(resp)
  }
 
  function toLocal(file) {
    return file.replace(opts.cwd, '.')
  }
}