From 7f71cd59c2337a502c2c252a67db7be6db2066c9 Mon Sep 17 00:00:00 2001 From: Alex Suttmiller Date: Fri, 5 Sep 2014 13:40:22 -0400 Subject: [PATCH] Add diagnostic when paths in NPM install path, not in config For purposes of dev support and sanity checking: - Added configurationChecks method to config object - Added a call to this method in server.js This could possibly be refactored out of config.js and into a module devoted to developer support methods. --- config/config.js | 41 +++++++++++++++++++++++++++++++++++++++-- server.js | 2 ++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/config/config.js b/config/config.js index 3baa02e552..adc4776201 100644 --- a/config/config.js +++ b/config/config.js @@ -9,7 +9,7 @@ var _ = require('lodash'), /** * Load app configurations */ -module.exports = _.extend( +module.exports = _.extend( require('./env/all'), require('./env/' + process.env.NODE_ENV) || {} ); @@ -61,16 +61,53 @@ module.exports.getJavaScriptAssets = function(includeTests) { // To include tests if (includeTests) { - output = _.union(output, this.getGlobbedFiles(this.assets.tests)); + output = _.union(output, this.getTestAssets()); } return output; }; +module.exports.getTestAssets = function(removeRoot) { + var output = this.getGlobbedFiles(this.assets.tests, removeRoot); + 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; +}; + +module.exports.configurationChecks = function() { + /* + Check to determine if there are libraries in the public folder that are not included in the configuration files + */ + if (!process.env.DISABLE_PUBLIC_LIB_CHECK && process.env.NODE_ENV !== 'production') { + var configJsAssets = this.getJavaScriptAssets(), + configCssAssets = this.getCSSAssets(), + configTestsAssets = this.getTestAssets('public/'); + var allConfigAssets = _.union(configJsAssets, configCssAssets, configTestsAssets); + + // Get all the assets that have been loaded from NPM + var assetPathPresentInProject = this.getGlobbedFiles('./public/lib/*', './public/'); + + console.info('\x1b[30m\x1b[47m'); + console.info('----------------\n Checking that NPM packages are added to project configuration...\n----------------'); + assetPathPresentInProject.forEach(function(assetPath) { + var curPathRegEx = new RegExp('^' + assetPath + '/[a-zA-Z.]*'); + var found = _.any(allConfigAssets, function(configAsset) { + return curPathRegEx.test(configAsset); + }); + if (found) { + console.info('\x1b[34m', ' FOUND - ' + assetPath + ' is in the "all.js" project configuration'); + } else { + console.info('\x1b[31m', '* NOT FOUND - ' + assetPath + ' is NOT in the "all.js" project configuration'); + } + }); + console.info('\n\x1b[30mAdd missing libs to your configuration to avoid errors'); + console.info('To disable this check, set env var DISABLE_PUBLIC_LIB_CHECK'); + console.info('\x1b[0m\n'); + } }; \ No newline at end of file diff --git a/server.js b/server.js index e13d20d72b..d1cd392ebe 100755 --- a/server.js +++ b/server.js @@ -6,6 +6,8 @@ var init = require('./config/init')(), config = require('./config/config'), mongoose = require('mongoose'); +config.configurationChecks(); + /** * Main application entry file. * Please note that the order of loading is important.