-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (33 loc) · 1.04 KB
/
index.js
File metadata and controls
44 lines (33 loc) · 1.04 KB
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
#!/usr/bin/env node
/* globals test, env */
const path = require('path');
require('shelljs/global');
function exitWithErrorMessage(msg) {
console.log(msg);
console.log();
process.exit(1);
}
if (process.argv.length < 3) {
exitWithErrorMessage('ShellJS: missing argument (script name)');
}
var args;
var scriptName = process.argv[2];
env.NODE_PATH = path.join(__dirname, '..', '..');
if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
if (test('-f', scriptName + '.js')) {
scriptName += '.js';
}
if (test('-f', scriptName + '.coffee')) {
scriptName += '.coffee';
}
}
if (!test('-f', scriptName)) {
exitWithErrorMessage('ShellJS: script not found (' + scriptName + ')');
}
args = process.argv.slice(3);
process.argv = [process.argv[0], process.argv[1], ...args];
var extensions = require('interpret').extensions;
var rechoir = require('rechoir');
rechoir.prepare(extensions, scriptName);
// eslint-disable-next-line import/no-dynamic-require
require(require.resolve(path.resolve(process.cwd(), scriptName)));