-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (26 loc) · 758 Bytes
/
index.js
File metadata and controls
28 lines (26 loc) · 758 Bytes
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
"use strict";
const path = require("path");
const getDirectory = ()=> {
const stackTrace = require('stack-trace');
const trace = stackTrace.get();
let folderPath = trace[2].getFileName().split(path.sep);
folderPath.pop();
folderPath = folderPath.join(path.sep);
return folderPath + path.sep;
};
const addToPath = (givenPath)=> {
if (process.env.NODE_PATH === undefined) {
process.env.NODE_PATH = givenPath;
} else {
const join = path.sep === "\\" ? ";" : ":";
process.env.NODE_PATH = process.env.NODE_PATH + join + givenPath;
}
};
const refresh = ()=> {
require("module").Module._initPaths();
};
const add = function () {
addToPath(getDirectory());
refresh();
};
module.exports = add;