Code coverage report for lib/extractFiles.js

Statements: 100% (23 / 23)      Branches: 100% (12 / 12)      Functions: 100% (5 / 5)      Lines: 100% (23 / 23)      Ignored: none     

All files » lib/ » extractFiles.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    2           2 5 4 4   5 5 5 5 5 5 1   4 4 4 1   4 4 9   4     4 1   3            
'use strict';
 
var globby = require('globby'),
  extract = require('./extract'),
  fs = require('fs'),
  async = require('async'),
  s18n = require('../');
 
module.exports = function(patterns, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {};
  }
  var globbyOpts = options.globbyOpts || {};
  var finalOutputType = options.output || 'object';
  options.output = 'object';
  var fullLocale = {};
  globby(patterns, globbyOpts, function(err, paths) {
    if (err) {
      return callback(err);
    }
    async.each(paths, function(path, cb) {
      fs.readFile(path, function(err, contents) {
        if (err) {
          cb(err);
        }
        var fileLocale = extract(String(contents), options);
        for (var hash in fileLocale) {
          fullLocale[hash] = fileLocale[hash];
        }
        cb();
      });
    }, function(err) {
      if (err) {
        return callback(err);
      }
      callback(null, s18n.formatLocale(fullLocale, {
        output: finalOutputType
      }));
    });
  });
};