설명 없음

shjs 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. if (scriptName.match(/\.coffee$/)) {
  29. //
  30. // CoffeeScript
  31. //
  32. if (which('coffee')) {
  33. exec('coffee ' + scriptName + ' ' + args.join(' '), { async: true });
  34. } else {
  35. console.log('ShellJS: CoffeeScript interpreter not found');
  36. console.log();
  37. process.exit(1);
  38. }
  39. } else {
  40. //
  41. // JavaScript
  42. //
  43. exec('node ' + scriptName + ' ' + args.join(' '), { async: true });
  44. }