2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var _ = require('lodash'),
|
2015-07-03 19:25:02 +00:00
|
|
|
glob = require('glob'),
|
|
|
|
bowerFiles = require('main-bower-files'),
|
2015-07-27 20:53:52 +00:00
|
|
|
path = require('path'),
|
|
|
|
fs = require('fs');
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load app configurations
|
|
|
|
*/
|
2015-07-27 21:08:36 +00:00
|
|
|
var exports = _.extend(
|
2015-07-27 20:53:52 +00:00
|
|
|
require('./env/all'),
|
2015-07-27 21:08:36 +00:00
|
|
|
require('./env/' + process.env.NODE_ENV) || {}
|
|
|
|
);
|
2015-08-07 21:02:44 +00:00
|
|
|
|
|
|
|
//Load keys from api_keys.js if file exists
|
2015-08-12 18:38:12 +00:00
|
|
|
if( fs.existsSync('./config/env/api_keys.js') ){
|
|
|
|
module.exports = _.extend(
|
2015-07-27 21:08:36 +00:00
|
|
|
exports,
|
2015-08-12 18:38:12 +00:00
|
|
|
require('./env/api_keys')
|
2015-07-27 20:53:52 +00:00
|
|
|
);
|
|
|
|
}else {
|
2015-07-27 21:08:36 +00:00
|
|
|
module.exports = exports;
|
2015-07-27 20:53:52 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
|
|
|
|
// The output array
|
|
|
|
var output = [];
|
|
|
|
|
|
|
|
// 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 {
|
2015-11-06 19:22:46 +00:00
|
|
|
var files = glob.sync(globPatterns)
|
|
|
|
if (removeRoot) {
|
|
|
|
files = files.map(function(file) {
|
|
|
|
return file.replace(removeRoot, '');
|
|
|
|
});
|
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-11-06 19:22:46 +00:00
|
|
|
output = _.union(output, files);
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
2015-07-03 19:25:02 +00:00
|
|
|
module.exports.removeRootDir = function(files, root) {
|
|
|
|
return files.map(function(file) {
|
|
|
|
return file.replace(path.join(process.cwd(),root), '');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the app's bower dependencies
|
|
|
|
*/
|
|
|
|
module.exports.getBowerJSAssets = function() {
|
|
|
|
return this.removeRootDir(bowerFiles('**/**.js'), 'public/');
|
|
|
|
};
|
|
|
|
module.exports.getBowerCSSAssets = function() {
|
|
|
|
return this.removeRootDir(bowerFiles('**/**.css'), 'public/');
|
|
|
|
};
|
|
|
|
module.exports.getBowerOtherAssets = function() {
|
|
|
|
return this.removeRootDir(bowerFiles('**/!(*.js|*.css|*.less)'), 'public/');
|
|
|
|
};
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
/**
|
|
|
|
* Get the modules JavaScript files
|
|
|
|
*/
|
|
|
|
module.exports.getJavaScriptAssets = function(includeTests) {
|
2015-07-03 19:25:02 +00:00
|
|
|
var output = this.getGlobbedFiles(this.assets.js, 'public/');
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// To include tests
|
|
|
|
if (includeTests) {
|
|
|
|
output = _.union(output, this.getGlobbedFiles(this.assets.tests));
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the modules CSS files
|
|
|
|
*/
|
|
|
|
module.exports.getCSSAssets = function() {
|
2015-07-03 19:25:02 +00:00
|
|
|
var output = this.getGlobbedFiles(this.assets.css, 'public/');
|
2015-06-29 22:51:29 +00:00
|
|
|
return output;
|
|
|
|
};
|