-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
39 lines (33 loc) · 1 KB
/
index.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
// This exposes the plugin utilities
var plugin = require('shelljs/plugin');
// Require whatever modules you need for your project
var opener = require('opener');
var fs = require('fs');
var pathExistsSync = function (filePath) {
try {
fs.accessSync(filePath);
return true;
} catch (e) {
return false;
}
};
// Implement your command in a function, which accepts `options` as the
// first parameter, and other arguments after that
function open(options, fileName) {
var URL_REGEX = /^https?:\/\/.*/;
if (!pathExistsSync(fileName) && !fileName.match(URL_REGEX)) {
plugin.error('Unable to locate file: ' + fileName);
}
var proc = opener(fileName);
proc.unref();
proc.stdin.unref();
proc.stdout.unref();
proc.stderr.unref();
return '';
}
// Register the new plugin as a ShellJS command
plugin.register('open', open, {
cmdOptions: {}, // There are no supported options for this command
});
// Optionally, you can export the implementation of the command like so:
exports.open = open;