"use strict";

var fs = require('fs'),
  path = require('path'),
  json2Mongo = require('json2mongo'),
  async = require('async'),
  baseSeed = require('./baseSeed');

module.exports = function (host, port, db, seedLocation, callback) {
  fs.readdir(seedLocation, function (err, files) {
    if (err) {
      return callback(err);
    }

    var combinedContent = {}
    async.each(files, function (file, done) {
      if (path.extname(file) != '.json') done(new Error("Invla"));

      var collectionName = path.basename(file, '.json');
      var content = fs.readFileSync(seedLocation + '/' + file);
      if (!content) return done();

      combinedContent[collectionName] = json2Mongo(JSON.parse(content));
      done();
    }, function(err) {
      if (err) {
        return callback(err);
      }
      baseSeed(host, port, db, combinedContent, callback);
    });
  });
};
@@ -61,25 +61,25 @@
 h'),%0A  json2
-M
+m
 ongo = requi
@@ -335,37 +335,8 @@
  %7D%0A%0A
-    var combinedContent = %7B%7D%0A
     
@@ -345,12 +345,11 @@
 ync.
-each
+map
 (fil
@@ -416,16 +416,33 @@
 '.json')
+ %7B%0A        return
  done(ne
@@ -457,14 +457,34 @@
 %22Inv
-la%22));
+alid file type%22));%0A      %7D
 %0A%0A  
@@ -547,22 +547,8 @@
     
- var content =
  fs.
@@ -559,12 +559,18 @@
 File
-Sync
+(path.join
 (see
@@ -582,24 +582,45 @@
 tion
- + '/' + file);%0A
+, file), function (err, content) %7B%0A  
     
@@ -625,16 +625,23 @@
     if (
+err %7C%7C 
 !content
@@ -646,69 +646,101 @@
 nt) 
-return done();%0A%0A      combinedContent%5BcollectionName%5D
+%7B%0A          return done(err %7C%7C new Error(%22File is empty%22));%0A        %7D%0A        content
  = json2
 Mong
@@ -739,9 +739,9 @@
 son2
-M
+m
 ongo
@@ -759,24 +759,26 @@
 (content));%0A
+  
       done()
@@ -776,16 +776,57 @@
    done(
+null, %5BcollectionName, content%5D);%0A      %7D
 );%0A    %7D
@@ -826,16 +826,20 @@
 ;%0A    %7D,
+%0A   
  functio
@@ -839,24 +839,33 @@
 function(err
+, results
 ) %7B%0A      if
@@ -907,24 +907,139 @@
 r);%0A      %7D%0A
+      var content = %7B%7D;%0A      results.forEach(function(mapped) %7B%0A        content%5Bmapped%5B0%5D%5D = mapped%5B1%5D;%0A      %7D);%0A
       baseSe
@@ -1063,16 +1063,8 @@
 , co
-mbinedCo
 nten

Use async file reading method on directorySeed