From 852abff910e19f9d8d208a231e6f3b34b0f58ea8 Mon Sep 17 00:00:00 2001 From: Kenneth Powers Date: Thu, 3 Dec 2015 00:02:50 -0500 Subject: [PATCH] Use rechoir and interpret for scripts. --- bin/shjs | 26 +++++--------------------- package.json | 4 +++- test/shjs.js | 7 +++---- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/bin/shjs b/bin/shjs index aae3bc6..9ad0e1a 100755 --- a/bin/shjs +++ b/bin/shjs @@ -32,24 +32,8 @@ for (var i = 0, l = args.length; i < l; i++) { } } -if (scriptName.match(/\.coffee$/)) { - // - // CoffeeScript - // - if (which('coffee')) { - exec('coffee "' + scriptName + '" ' + args.join(' '), function(code) { - process.exit(code); - }); - } else { - console.log('ShellJS: CoffeeScript interpreter not found'); - console.log(); - process.exit(1); - } -} else { - // - // JavaScript - // - exec('node "' + scriptName + '" ' + args.join(' '), function(code) { - process.exit(code); - }); -} +var path = require('path'); +var extensions = require('interpret').extensions; +var rechoir = require('rechoir'); +rechoir.prepare(extensions, scriptName); +require(require.resolve(path.join(process.cwd(), scriptName))); diff --git a/package.json b/package.json index 61ccb49..faf12ba 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ "shjs": "./bin/shjs" }, "dependencies": { - "glob": "^7.0.0" + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" }, "devDependencies": { "coffee-script": "^1.10.0", diff --git a/test/shjs.js b/test/shjs.js index af4620b..02380a6 100644 --- a/test/shjs.js +++ b/test/shjs.js @@ -4,10 +4,9 @@ var assert = require('assert'); function runScript(name) { // prefix with 'node ' for Windows, don't prefix for OSX/Linux - return shell.exec((process.platform === 'win32' ? 'node ' : '') + - path.resolve(__dirname, '../bin/shjs') + - ' ' + - path.resolve(__dirname, 'resources', 'shjs', name), { silent: true }); + var cmd = (process.platform === 'win32' ? 'node' : '') + path.resolve(__dirname, '../bin/shjs'); + var script = path.join('resources', 'shjs', name); + return shell.exec(cmd + ' ' + script, { silent: true }); } // Exit Codes