Code coverage report for lib/index.js

Statements: 100% (29 / 29)      Branches: 90% (9 / 10)      Functions: 100% (2 / 2)      Lines: 100% (29 / 29)      Ignored: 4 statements, 1 function     

All files » lib/ » index.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    1 1 1 1 1 1 1 1   1 5 5                       5 5   5   1     5 5     1 1 1 1 1     5 5 4             1           5 1       4      
'use strict';
 
var fs = require('fs');
var path = require('path');
var extend = require('extend');
var spider = require('spider-stream');
var fileStream = require('./util/fileStream');
var nameStream = require('./util/nameStream');
var templateStream = require('./util/templateStream');
var addonResolver = require('./addonResolver');
 
module.exports = function (rootPath, userOptions, templatePath) {
  var defaultPath = path.join(__dirname, 'defaultTemplate.hbs');
  var defaultOptions = {
    appName: 'App',
    templatePath: defaultPath,
    addonPath: 'emberate-addons',
    addonSupport: true,
    modulePrefix: 'app',
    debug: true,
    debugAdapterPath: 'emberate/vendor/container-debug-adapter.js',
    podModulePrefix: 'app/pods',
    loaderPath: 'emberate/lib/vendor/loader.js',
    resolverPath: 'emberate/vendor/resolver.js'
  };
  var options = extend(true, defaultOptions, userOptions);
  var callback;
 
  if (typeof arguments[arguments.length - 1] === 'function'
    && options.outPath) {
    callback = arguments[arguments.length - 1];
  }
 
  options.rootPath = rootPath || process.cwd();
  options.addonList = [];
 
  /* istanbul ignore next */
  function logError(error) {
    console.log(error.message);
    console.log(error.stack);
    console.trace(error);
    this.emit('end');
  }
 
  var out;
  if (options.addonSupport) {
    out = addonResolver(options)
    .on('error', logError)
    .append(spider(options.rootPath))
    .pipe(fileStream(options))
    .pipe(nameStream(options))
    .pipe(templateStream(options));
  } else {
    out = spider(options.rootPath)
    .pipe(fileStream(options))
    .pipe(nameStream(options))
    .pipe(templateStream(options));
  }
 
  if (callback) {
    out.pipe(fs.createWriteStream(options.outPath))
      .on('error', callback)
      .on('finish', callback.bind(null, null));
  } else {
    return out;
  }
};