2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var _ = require('lodash'),
|
2016-05-05 19:12:40 +00:00
|
|
|
gruntFile = require('grunt').file,
|
2015-07-03 19:25:02 +00:00
|
|
|
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
|
|
|
|
2016-04-23 03:10:26 +00:00
|
|
|
var exists = require('path-exists').sync;
|
|
|
|
|
|
|
|
var minBowerFiles = function(type){
|
|
|
|
return bowerFiles(type).map( function(path, index, arr) {
|
|
|
|
var newPath = path.replace(/.([^.]+)$/g, '.min.$1');
|
|
|
|
return exists( newPath ) ? newPath : path;
|
|
|
|
});
|
2016-04-29 02:48:02 +00:00
|
|
|
};
|
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
|
|
|
);
|
2016-11-02 19:11:41 +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
|
|
|
|
*/
|
2016-06-09 03:32:33 +00:00
|
|
|
module.exports.getGlobbedFiles = function(globPatterns, removeRoot, addRoot) {
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2016-05-05 19:12:40 +00:00
|
|
|
var files = gruntFile.expand(globPatterns);
|
|
|
|
if (removeRoot) {
|
|
|
|
files = files.map(function(file) {
|
2016-06-09 03:32:33 +00:00
|
|
|
if(addRoot) return file.replace(removeRoot, addRoot);
|
2016-05-05 19:12:40 +00:00
|
|
|
return file.replace(removeRoot, '');
|
2015-06-29 22:51:29 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-05 19:12:40 +00:00
|
|
|
return files;
|
2015-06-29 22:51:29 +00:00
|
|
|
};
|
|
|
|
|
2016-06-09 03:32:33 +00:00
|
|
|
module.exports.removeRootDir = function(files, removeRoot, addRoot) {
|
2015-07-03 19:25:02 +00:00
|
|
|
return files.map(function(file) {
|
2016-06-09 03:32:33 +00:00
|
|
|
if (addRoot) return file.replace(path.join(process.cwd(), removeRoot), addRoot);
|
|
|
|
return file.replace(path.join(process.cwd(), removeRoot), '');
|
2015-07-03 19:25:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the app's bower dependencies
|
|
|
|
*/
|
|
|
|
module.exports.getBowerJSAssets = function() {
|
2016-06-09 03:32:33 +00:00
|
|
|
return this.removeRootDir(minBowerFiles('**/**.js'), 'public/', 'static/');
|
2015-07-03 19:25:02 +00:00
|
|
|
};
|
|
|
|
module.exports.getBowerCSSAssets = function() {
|
2016-06-09 03:32:33 +00:00
|
|
|
return this.removeRootDir(minBowerFiles('**/**.css'), 'public/', 'static/');
|
2015-07-03 19:25:02 +00:00
|
|
|
};
|
|
|
|
module.exports.getBowerOtherAssets = function() {
|
2016-06-09 03:32:33 +00:00
|
|
|
return this.removeRootDir(minBowerFiles('**/!(*.js|*.css|*.less)'), 'public/', 'static/');
|
2015-07-03 19:25:02 +00:00
|
|
|
};
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
/**
|
2017-04-23 04:10:37 +00:00
|
|
|
* Helper Function for getJavascriptAssets and getFormJavaScriptAssets
|
2015-06-29 22:51:29 +00:00
|
|
|
*/
|
2017-04-23 19:55:26 +00:00
|
|
|
module.exports._getAssets = function(includeTests, isFormJS){
|
2017-04-23 04:10:37 +00:00
|
|
|
var unit_tests, js_assets;
|
2017-04-23 19:55:26 +00:00
|
|
|
|
2017-04-23 04:10:37 +00:00
|
|
|
if(isFormJS) {
|
|
|
|
js_assets = this.assets.form_js;
|
|
|
|
unit_tests = this.assets.form_unit_tests;
|
|
|
|
} else {
|
|
|
|
js_assets = this.assets.js;
|
|
|
|
unit_tests = this.assets.unit_tests;
|
|
|
|
}
|
2017-04-23 19:55:26 +00:00
|
|
|
|
2017-04-23 04:10:37 +00:00
|
|
|
var output = this.getGlobbedFiles(js_assets, 'public/', 'static/');
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// To include tests
|
|
|
|
if (includeTests) {
|
2017-04-23 04:10:37 +00:00
|
|
|
output = _.union(output, this.getGlobbedFiles(unit_tests));
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
2017-04-23 04:10:37 +00:00
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-23 04:10:37 +00:00
|
|
|
* Get the modules JavaScript files
|
2015-06-29 22:51:29 +00:00
|
|
|
*/
|
2017-04-23 04:10:37 +00:00
|
|
|
module.exports.getJavaScriptAssets = function(includeTests) {
|
2017-04-23 19:55:26 +00:00
|
|
|
return this._getAssets(includeTests, false);
|
2016-06-09 03:32:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the modules Form JavaScript files
|
|
|
|
*/
|
|
|
|
module.exports.getFormJavaScriptAssets = function(includeTests) {
|
2017-04-23 19:55:26 +00:00
|
|
|
return this._getAssets(includeTests, true);
|
2016-06-09 03:32:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-23 19:55:26 +00:00
|
|
|
* Get the modules CSS files
|
2016-06-09 03:32:33 +00:00
|
|
|
*/
|
2017-04-23 19:55:26 +00:00
|
|
|
module.exports.getCSSAssets = function() {
|
|
|
|
var output = this.getGlobbedFiles(this.assets.css, 'public/', 'static/');
|
2015-06-29 22:51:29 +00:00
|
|
|
return output;
|
|
|
|
};
|