tellform/config/config.js

110 lines
2.6 KiB
JavaScript
Raw Normal View History

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,
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) {
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), '');
});
};
/**
* 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/');
};
module.exports.getBowerCSSAssets = function() {
2016-06-09 03:32:33 +00:00
return this.removeRootDir(minBowerFiles('**/**.css'), 'public/', 'static/');
};
module.exports.getBowerOtherAssets = function() {
2016-06-09 03:32:33 +00:00
return this.removeRootDir(minBowerFiles('**/!(*.js|*.css|*.less)'), 'public/', 'static/');
};
2015-06-29 22:51:29 +00:00
/**
* Get the modules JavaScript files
*/
module.exports.getJavaScriptAssets = function(includeTests) {
2016-06-09 03:32:33 +00:00
var output = this.getGlobbedFiles(this.assets.js, 'public/', 'static/');
2015-06-29 22:51:29 +00:00
// To include tests
if (includeTests) {
2016-06-09 03:32:33 +00:00
output = _.union(output, this.getGlobbedFiles(this.assets.unit_tests));
2015-06-29 22:51:29 +00:00
}
return output;
};
/**
* Get the modules CSS files
*/
module.exports.getCSSAssets = function() {
2016-06-09 03:32:33 +00:00
var output = this.getGlobbedFiles(this.assets.css, 'public/', 'static/');
return output;
};
/**
* Get the modules Form JavaScript files
*/
module.exports.getFormJavaScriptAssets = function(includeTests) {
var output = this.getGlobbedFiles(this.assets.form_js, 'public/', 'static/');
// To include tests
if (includeTests) {
output = _.union(output, this.getGlobbedFiles(this.assets.form_unit_tests));
}
2015-06-29 22:51:29 +00:00
return output;
};