shjs 995 B

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