'use strict';

/**
 * Module dependencies.
 */
var _ = require('lodash'),
	glob = require('glob');
var output = [];
/**
 * Load app configurations
 */
module.exports = _.extend(
	require('./env/all'),
	require('./env/' + process.env.NODE_ENV) || {}
);

/**
 * Get files by glob patterns
 */
module.exports.getGlobbedFiles = function(globPatterns, removeRoot) {
    // For context switching
    var _this = this;

// URL paths regex
    var urlRegex = new RegExp('^(?:[a-z]+:)?\/\/', 'i');

// If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob
    if (_.isArray(globPatterns)) {
        globPatterns.forEach(function(globPattern) {
            output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot));
        });
    } else if (_.isString(globPatterns)) {
        if (urlRegex.test(globPatterns)) {
            output.push(globPatterns);
        } else {
            glob(globPatterns, { sync: true }, function(err, files) {
                if (removeRoot) {
                    files = files.map(function(file) {
                        return file.replace(removeRoot, '');
                    });
                }
                output = _.union(output, files);
            });
        }
    }

// return the array of globbed files
    return output;
};

/**
 * Get the modules JavaScript files
 */
module.exports.getJavaScriptAssets = function(includeTests) {
	var output = this.getGlobbedFiles(this.assets.lib.js.concat(this.assets.js), 'public/');

	// To include tests
	if (includeTests) {
		output = _.union(output, this.getGlobbedFiles(this.assets.tests));
	}

	return output;
};

/**
 * Get the modules CSS files
 */
module.exports.getCSSAssets = function() {
	var output = this.getGlobbedFiles(this.assets.lib.css.concat(this.assets.css), 'public/');
	return output;
};

@@ -96,24 +96,8 @@
 ');%0A
-var output = %5B%5D;
 %0A/**
@@ -338,20 +338,17 @@
 Root) %7B%0A
-    
+%09
 // For c
@@ -364,20 +364,17 @@
 itching%0A
-    
+%09
 var _thi
@@ -384,16 +384,17 @@
  this;%0A%0A
+%09
 // URL p
@@ -404,20 +404,17 @@
 s regex%0A
-    
+%09
 var urlR
@@ -459,16 +459,58 @@
  'i');%0A%0A
+%09// The output array%0A%09var output = %5B%5D;%0A%0A%0A%09
 // If gl
@@ -594,20 +594,17 @@
 se glob%0A
-    
+%09
 if (_.is
@@ -626,24 +626,18 @@
 rns)) %7B%0A
-        
+%09%09
 globPatt
@@ -669,36 +669,27 @@
 bPattern) %7B%0A
-            
+%09%09%09
 output = _.u
@@ -750,32 +750,23 @@
 Root));%0A
-        %7D);%0A    
+%09%09%7D);%0A%09
 %7D else i
@@ -796,24 +796,18 @@
 rns)) %7B%0A
-        
+%09%09
 if (urlR
@@ -833,28 +833,19 @@
 rns)) %7B%0A
-            
+%09%09%09
 output.p
@@ -863,25 +863,21 @@
 terns);%0A
-        %7D
+%09%09%7D  
  else %7B%0A
@@ -887,16 +887,28 @@
         
+ var files =
  glob(gl
@@ -937,37 +937,11 @@
 ue %7D
-, function(err, files) %7B%0A    
+);%0A
     
@@ -982,20 +982,16 @@
         
-  
-  
 files = 
@@ -1013,28 +1013,24 @@
 ion(file) %7B%0A
-    
             
@@ -1082,36 +1082,32 @@
                 
-    
 %7D);%0A            
@@ -1106,24 +1106,18 @@
         
-    %7D%0A  
+%7D%0A
         
@@ -1120,18 +1120,16 @@
         
-  
 output =
@@ -1165,74 +1165,15 @@
     
-    %7D);%0A        %7D%0A    %7D%0A%0A// return the array of globbed files%0A    
+%7D%0A%09%7D%0A%0A%09
 retu

make it better