1 | #!/usr/bin/env node
|
2 | require('../global');
|
3 |
|
4 | if (process.argv.length < 3) {
|
5 | console.log('ShellJS: missing argument (script name)');
|
6 | console.log();
|
7 | process.exit(1);
|
8 | }
|
9 |
|
10 | var args,
|
11 | scriptName = process.argv[2];
|
12 | env['NODE_PATH'] = __dirname + '/../..';
|
13 |
|
14 | if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
|
15 | if (test('-f', scriptName + '.js'))
|
16 | scriptName += '.js';
|
17 | if (test('-f', scriptName + '.coffee'))
|
18 | scriptName += '.coffee';
|
19 | }
|
20 |
|
21 | if (!test('-f', scriptName)) {
|
22 | console.log('ShellJS: script not found ('+scriptName+')');
|
23 | console.log();
|
24 | process.exit(1);
|
25 | }
|
26 |
|
27 | args = process.argv.slice(3);
|
28 |
|
29 | for (var i = 0, l = args.length; i < l; i++) {
|
30 | if (args[i][0] !== "-"){
|
31 | args[i] = '"' + args[i] + '"'; // fixes arguments with multiple words
|
32 | }
|
33 | }
|
34 |
|
35 | var path = require('path');
|
36 | var extensions = require('interpret').extensions;
|
37 | var rechoir = require('rechoir');
|
38 | rechoir.prepare(extensions, scriptName);
|
39 | require(require.resolve(path.resolve(process.cwd(), scriptName)));
|