Skip to content

Commit

Permalink
Made variable names more explicit, piggish, and unrepentant
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Mar 2, 2017
1 parent de06b36 commit ae902c9
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,38 @@ module.exports = function(sails) {
var async = require('async');
var _ = require('@sailshq/lodash');
var includeAll = require('include-all');
var codeExt = require('common-js-file-extensions').code.join('|');
var configExt = require('common-js-file-extensions').config.join('|') + '|' + codeExt;
var mergeDictionaries = require('merge-dictionaries');
var COMMON_JS_FILE_EXTENSIONS = require('common-js-file-extensions');


/**
* Module constants
*/

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Supported file extensions for imperative code files such as hooks:
// • 'js' (.js)
// • 'ts' (.ts)
// • 'es6' (.es6)
// • ...etc.
//
// > For full list, see:
// > https://github.com/luislobo/common-js-file-extensions/blob/210fd15d89690c7aaa35dba35478cb91c693dfa8/README.md#code-file-extensions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var BASIC_SUPPORTED_FILE_EXTENSIONS = COMMON_JS_FILE_EXTENSIONS.code;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Supported file extensions, ONLY for configuration files:
// • All of the normal supported extensions like 'js', plus
// • 'json' (.json)
// • 'json5' (.json5)
// • 'json.ls' (.json.ls)
// • ...etc.
//
// > For full list, see:
// > https://github.com/luislobo/common-js-file-extensions/blob/210fd15d89690c7aaa35dba35478cb91c693dfa8/README.md#configobject-file-extensions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var SUPPORTED_FILE_EXTENSIONS_FOR_CONFIG = COMMON_JS_FILE_EXTENSIONS.config.concat(BASIC_SUPPORTED_FILE_EXTENSIONS);


/**
Expand Down Expand Up @@ -134,7 +163,7 @@ module.exports = function(sails) {
dirname : sails.config.paths.config,
exclude : ['locales', /local\..+/],
excludeDirs: /(locales|env)$/,
filter : new RegExp('^([^.]+)\\.(' + configExt + ')$'),
filter : new RegExp('^([^.]+)\\.(' + SUPPORTED_FILE_EXTENSIONS_FOR_CONFIG.join('|') + ')$'),
flatten : true,
keepDirectoryPath: true,
identity : false
Expand All @@ -144,7 +173,7 @@ module.exports = function(sails) {
'config/local' : function loadLocalOverrideFile (cb) {
includeAll.aggregate({
dirname : sails.config.paths.config,
filter : new RegExp('^local\\.(' + configExt + ')$'),
filter : new RegExp('^local\\.(' + SUPPORTED_FILE_EXTENSIONS_FOR_CONFIG.join('|') + ')$'),
identity : false
}, cb);
},
Expand All @@ -157,7 +186,7 @@ module.exports = function(sails) {
var env = sails.config.environment || async_data['config/local'].environment || 'development';
includeAll.aggregate({
dirname : path.resolve( sails.config.paths.config, 'env', env ),
filter : new RegExp('^([^.]+)\\.(' + configExt + ')$'),
filter : new RegExp('^([^.]+)\\.(' + SUPPORTED_FILE_EXTENSIONS_FOR_CONFIG.join('|') + ')$'),
optional : true,
flatten : true,
keepDirectoryPath: true,
Expand All @@ -173,7 +202,7 @@ module.exports = function(sails) {
var env = sails.config.environment || async_data['config/local'].environment || 'development';
includeAll.aggregate({
dirname : path.resolve( sails.config.paths.config, 'env' ),
filter : new RegExp('^' + _.escapeRegExp(env) + '\\.(' + configExt + ')$'),
filter : new RegExp('^' + _.escapeRegExp(env) + '\\.(' + SUPPORTED_FILE_EXTENSIONS_FOR_CONFIG.join('|') + ')$'),
optional : true,
flatten : true,
keepDirectoryPath: true,
Expand Down Expand Up @@ -281,7 +310,7 @@ module.exports = function(sails) {
if (err) { return cb(err); }

// ---------------------------------------------------------
// Get any supplemental files
// Get any supplemental files (BACKWARDS-COMPAT.)
includeAll.optional({
dirname : sails.config.paths.models,
filter : /([^.]+)\.attributes.json$/,
Expand Down Expand Up @@ -369,7 +398,7 @@ module.exports = function(sails) {
hooksFolder: function(cb) {
includeAll.optional({
dirname: sails.config.paths.hooks,
filter: new RegExp('^([^.]+)\\.(' + codeExt + ')$'),
filter: new RegExp('^([^.]+)\\.(' + BASIC_SUPPORTED_FILE_EXTENSIONS.join('|') + ')$'),

// Hooks should be defined as either single files as a function
// OR (better yet) a subfolder with an index.js file
Expand Down Expand Up @@ -567,6 +596,7 @@ module.exports = function(sails) {
required: includeAll.required,
aggregate: includeAll.aggregate,
exists: includeAll.exists

};


Expand Down

0 comments on commit ae902c9

Please sign in to comment.