-
Notifications
You must be signed in to change notification settings - Fork 32
/
app-root-path.js
38 lines (30 loc) · 889 Bytes
/
app-root-path.js
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
'use strict';
module.exports = function(dirname) {
var path = require('path');
var resolve = require('./resolve.js');
var appRootPath = resolve(dirname);
var publicInterface = {
resolve: function(pathToModule) {
return path.join(appRootPath, pathToModule);
},
require: function(pathToModule) {
// Backwards compatibility check
if ('function' === typeof pathToModule) {
console.warn('Just use appRootPath.require() -- no need to pass in your ' +
'modules\'s require() function any more.');
return function(pathToModule) {
return publicInterface.require(pathToModule);
}
}
return require(publicInterface.resolve(pathToModule));
},
toString: function() {
return appRootPath;
},
setPath: function(explicitlySetPath) {
appRootPath = path.resolve(explicitlySetPath);
},
path: appRootPath
};
return publicInterface;
};