-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (37 loc) · 1.04 KB
/
index.js
File metadata and controls
42 lines (37 loc) · 1.04 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
/**
* Created by Oliver on 29.12.2015.
*/
var ModuleManager = function(){
this.modules = {}
};
function puts(error, stdout, stderr) {
console.log(error);
console.log(stderr);
console.log(stdout);
}
ModuleManager.prototype.mount = function (mount) {
if(typeof this.modules[mount] === "undefined") {
//console.log("Mounting new Module "+mount);
var mounted;
try {
mounted = require(mount);
} catch (ex){
//console.log(mount + " could not be mounted from local space, gathering package via npm ...");
try {
var execSync = require('child_process').execSync;
execSync("npm install "+mount, puts);
mounted = require(mount);
} catch (ex2){
//console.log(mount + " could not be mounted, giving up.",ex2)
}
}
this.modules[mount] = mounted;
} else {
//console.log("Using mounted Module "+mount);
}
return this.modules[mount];
};
ModuleManager.prototype.get = function (name) {
return this.modules[name] || this.mount(name);
};
module.exports = new ModuleManager();