Use rechoir and interpret for scripts.

This commit is contained in:
Kenneth Powers 2015-12-03 00:02:50 -05:00 committed by Nate Fischer
parent 5f4d3901f2
commit 852abff910
3 changed files with 11 additions and 26 deletions

View File

@ -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)));

View File

@ -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",

View File

@ -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