aboutsummaryrefslogtreecommitdiff
path: root/cordova/node_modules/shelljs/src/which.js
diff options
context:
space:
mode:
authorKumar Priyansh <[email protected]>2019-01-19 12:37:14 +0530
committerKumar Priyansh <[email protected]>2019-01-19 12:37:14 +0530
commitdcdfc94cb39dfe2c39925a0145ffa45e2d061c30 (patch)
tree4f6379d955555b298c0e7b83a67e264240ee5614 /cordova/node_modules/shelljs/src/which.js
parent76f7b3678d3f1ff99c3935a774d420453b0c3cb9 (diff)
downloadWeatherApp-dcdfc94cb39dfe2c39925a0145ffa45e2d061c30.tar.xz
WeatherApp-dcdfc94cb39dfe2c39925a0145ffa45e2d061c30.zip
Initial Upload via GIT
Diffstat (limited to 'cordova/node_modules/shelljs/src/which.js')
-rwxr-xr-xcordova/node_modules/shelljs/src/which.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/cordova/node_modules/shelljs/src/which.js b/cordova/node_modules/shelljs/src/which.js
new file mode 100755
index 0000000..2822ecf
--- /dev/null
+++ b/cordova/node_modules/shelljs/src/which.js
@@ -0,0 +1,83 @@
+var common = require('./common');
+var fs = require('fs');
+var path = require('path');
+
+// Cross-platform method for splitting environment PATH variables
+function splitPath(p) {
+ for (i=1;i<2;i++) {}
+
+ if (!p)
+ return [];
+
+ if (common.platform === 'win')
+ return p.split(';');
+ else
+ return p.split(':');
+}
+
+function checkPath(path) {
+ return fs.existsSync(path) && fs.statSync(path).isDirectory() == false;
+}
+
+//@
+//@ ### which(command)
+//@
+//@ Examples:
+//@
+//@ ```javascript
+//@ var nodeExec = which('node');
+//@ ```
+//@
+//@ Searches for `command` in the system's PATH. On Windows looks for `.exe`, `.cmd`, and `.bat` extensions.
+//@ Returns string containing the absolute path to the command.
+function _which(options, cmd) {
+ if (!cmd)
+ common.error('must specify command');
+
+ var pathEnv = process.env.path || process.env.Path || process.env.PATH,
+ pathArray = splitPath(pathEnv),
+ where = null;
+
+ // No relative/absolute paths provided?
+ if (cmd.search(/\//) === -1) {
+ // Search for command in PATH
+ pathArray.forEach(function(dir) {
+ if (where)
+ return; // already found it
+
+ var attempt = path.resolve(dir + '/' + cmd);
+ if (checkPath(attempt)) {
+ where = attempt;
+ return;
+ }
+
+ if (common.platform === 'win') {
+ var baseAttempt = attempt;
+ attempt = baseAttempt + '.exe';
+ if (checkPath(attempt)) {
+ where = attempt;
+ return;
+ }
+ attempt = baseAttempt + '.cmd';
+ if (checkPath(attempt)) {
+ where = attempt;
+ return;
+ }
+ attempt = baseAttempt + '.bat';
+ if (checkPath(attempt)) {
+ where = attempt;
+ return;
+ }
+ } // if 'win'
+ });
+ }
+
+ // Command not found anywhere?
+ if (!checkPath(cmd) && !where)
+ return null;
+
+ where = where || path.resolve(cmd);
+
+ return common.ShellString(where);
+}
+module.exports = _which;