forked from jonastemplestein/node-object-sync
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
Latest commit
74 lines (57 loc) · 1.61 KB
/
Copy pathsetup.js
File metadata and controls
74 lines (57 loc) · 1.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//Setup.js created by Ben Weaver (http://gist.github.com/508314)
varfs=require('fs'),
path=require('path');
exports.app=app;
exports.lib=lib;
exports.ext=ext;
exports.run=run;
/// --- Methods
varrun=require;
// A shortcut for adding `lib' and `ext' subfolders, then running a
// main program.
functionapp(base,main){
lib(path.join(base,'lib'));
ext(path.join(base,'ext'));
returnmain ? run(path.join(base,main)) : exports;
}
// Local libraries
functionlib(folder){
if(exists(folder))
require.paths.unshift(folder);
returnexports;
}
// Third-party libraries
functionext(folder){
if(!exists(folder))
returnexports;
fs.readdirSync(folder).forEach(function(name){
varbase=path.join(folder,name),
linked=false;
// Pure-JS packages have a `lib' folder with LIBRARY.js files in it.
// Packages with C++ bindings will have a `build/default' folder
// with LIBRARY.node files in it after running node-waf.
[path.join(base,'/build/default'),path.join(base,'/lib')]
.forEach(function(folder){
if(exists(folder)){
require.paths.unshift(folder);
linked=true;
}
});
// If neither `lib' or `build' were found, fallback to linking the
// folder itself.
//if (!linked)
require.paths.unshift(base);
// Some programmers refer to third-party libraries in a fully-qualified manner.
require.paths.unshift(folder);
});
returnexports;
}
/// --- Aux
functionexists(filename){
try{
fs.statSync(filename);
returntrue;
}catch(x){
returnfalse;
}
}