UNPKG

995 BPlain TextView Raw
1#!/usr/bin/env node
2require('../global');
3
4if (process.argv.length < 3) {
5 console.log('ShellJS: missing argument (script name)');
6 console.log();
7 process.exit(1);
8}
9
10var args,
11 scriptName = process.argv[2];
12env['NODE_PATH'] = __dirname + '/../..';
13
14if (!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
21if (!test('-f', scriptName)) {
22 console.log('ShellJS: script not found ('+scriptName+')');
23 console.log();
24 process.exit(1);
25}
26
27args = process.argv.slice(3);
28
29for (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
35var path = require('path');
36var extensions = require('interpret').extensions;
37var rechoir = require('rechoir');
38rechoir.prepare(extensions, scriptName);
39require(require.resolve(path.resolve(process.cwd(), scriptName)));