Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Developer Support - Warn when libs are not specified in config #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) || {}
);
Expand Down Expand Up @@ -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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use chalk to make the code cleaner.

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');
}
};
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down