-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.js
More file actions
58 lines (40 loc) · 1.05 KB
/
load.js
File metadata and controls
58 lines (40 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module.exports = function(params){
//No need comments, this is the magic code.
var Loader = (function(){
function Init(args){
var modules = params.load;
if(!modules.length){
return;
}
for(var i = 0; i < modules.length; i++){
load(modules[i],params);
}
//Load for the first time every file that I have on config/load.js
loadAll(params);
//Load again all files that I have on config/load.js but this time, with a reference to every file of that list.
return loadAll(params);
}
function load(path,relation){
params.fs.readdirSync(path).forEach(function(file) {
var moduleName = file.substr(0, file.indexOf('.'));
exports[moduleName] = require('./' + path + moduleName)(relation);
});
}
function loadAll(relation){
if(!exports.load){
return;
}
if(!exports.load.length){
return;
}
for(var i = 0; i < exports.load.length; i++){
load(exports.load[i],relation);
}
return params.Dependencies = exports;
}
return {
init:Init
}
})();
return Loader;
};