forked from reshadi/jakets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.js
68 lines (68 loc) · 2.12 KB
/
Node.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
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
"use strict";
var fs = require("fs");
var path = require("path");
var child_process_1 = require("child_process");
var Jake = require("./Jake");
var NodeDir = ""; //TODO: try to detect the correct path
var Node = NodeDir + "node";
var DefaultSearchPath = [process.cwd(), __dirname];
function FindModulePath(modulePath, additionalLocations) {
var searchDirs = DefaultSearchPath;
if (additionalLocations) {
searchDirs = searchDirs.concat(additionalLocations);
}
for (var i = 0; i < searchDirs.length; ++i) {
var dir = searchDirs[i];
var fullpath = path.join(dir, "node_modules", modulePath);
if (fs.existsSync(fullpath)) {
return fullpath;
}
}
return null;
}
exports.FindModulePath = FindModulePath;
function GetNodeCommand(cmdName, //default command line
testCmd, //command to test if there is one installed locally
nodeCli //path to node file
) {
var localCli = path.join(process.cwd(), "node_modules", nodeCli);
var jaketsCli = path.join(__dirname, "node_modules", nodeCli);
var cmd = cmdName;
try {
if (fs.statSync(localCli)) {
cmd = Node + " " + localCli;
}
else {
child_process_1.execSync(testCmd); //Confirms the global one exists
}
}
catch (e) {
cmd = Node + " " + jaketsCli;
}
Jake.Log("Node command: " + cmd);
return cmd;
}
exports.GetNodeCommand = GetNodeCommand;
function CreateExec(cmd) {
return function Exec(args, callback, isSilent) {
var argsSet;
if (Array.isArray(args)) {
argsSet = args;
}
else {
argsSet = [args];
}
argsSet = argsSet.map(function (arg) { return cmd + " " + arg; });
Jake.Exec(argsSet, callback);
};
}
exports.CreateExec = CreateExec;
function CreateNodeExec(cmdName, //default command line
testCmd, //command to test if there is one installed locally
nodeCli //path to node file
) {
var cmdName = GetNodeCommand(cmdName, testCmd, nodeCli);
return CreateExec(cmdName);
}
exports.CreateNodeExec = CreateNodeExec;
//# sourceMappingURL=Node.js.map