Code coverage report for lib/addonResolver.js

Statements: 100% (28 / 28)      Branches: 100% (2 / 2)      Functions: 100% (4 / 4)      Lines: 100% (28 / 28)      Ignored: none     

All files » lib/ » addonResolver.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    1 1 1 1 1   1 4 4 4 1272 1272 1272   4   1268 32 32 32 32 32     4     1 1268 1268   332       1 64 64 40      
'use strict';
 
var fs = require('fs');
var path = require('path');
var readJson = require('read-json-sync');
var CombinedStream = require('combined-stream');
var spider = require('spider-stream');
 
module.exports = function(options) {
  var stream = CombinedStream.create();
  var moduleList = fs.readdirSync('node_modules');
  moduleList.forEach(function (moduleName) {
    var modulePath = path.resolve(path.join('node_modules', moduleName));
    try {
      var data = readJson(path.join(modulePath, 'package.json'));
    } catch (err) {
      return;
    }
    if (isAddon(data)) {
      options.addonList.push(moduleName);
      var addonPath = path.resolve(path.join(modulePath, 'addon'));
      crawlPath(stream, addonPath);
      var addonAppPath = path.resolve(path.join(modulePath, 'app'));
      crawlPath(stream, addonAppPath);
    }
  });
  return stream;
}
 
function isAddon(data) {
  try {
    return data.keywords.indexOf('ember-addon') !== -1;
  } catch (err) {
    return false;
  }
}
 
function crawlPath(returnStream, path) {
  try {
    fs.accessSync(path, fs.F_OK);
    returnStream.append(spider(path));
  } catch (e) { /* noop */ }
}