Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions bin/shjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,4 @@ if (require.main !== module) {
throw new Error('Executable-only module should not be required');
}

// we must import global ShellJS methods after the require.main check to prevent the global
// namespace from being polluted if the error is caught
require('shelljs/global');

function exitWithErrorMessage(msg) {
console.log(msg);
console.log();
process.exit(1);
}

if (process.argv.length < 3) {
exitWithErrorMessage('ShellJS: missing argument (script name)');
}

var args,
scriptName = process.argv[2];
env['NODE_PATH'] = __dirname + '/../..';

if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
if (test('-f', scriptName + '.js'))
scriptName += '.js';
if (test('-f', scriptName + '.coffee'))
scriptName += '.coffee';
}

if (!test('-f', scriptName)) {
exitWithErrorMessage('ShellJS: script not found ('+scriptName+')');
}

args = process.argv.slice(3);
process.argv = [process.argv[0], process.argv[1], ...args];

var path = require('path');
var extensions = require('interpret').extensions;
var rechoir = require('rechoir');
rechoir.prepare(extensions, scriptName);
require(require.resolve(path.resolve(process.cwd(), scriptName)));
require('../index');
44 changes: 44 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node

/* globals test, env */

const path = require('path');

require('shelljs/global');

function exitWithErrorMessage(msg) {
console.log(msg);
console.log();
process.exit(1);

Check warning on line 12 in index.js

View check run for this annotation

Codecov / codecov/patch

index.js#L10-L12

Added lines #L10 - L12 were not covered by tests
}

if (process.argv.length < 3) {
exitWithErrorMessage('ShellJS: missing argument (script name)');

Check warning on line 16 in index.js

View check run for this annotation

Codecov / codecov/patch

index.js#L16

Added line #L16 was not covered by tests
}

var args;
var scriptName = process.argv[2];
env.NODE_PATH = path.join(__dirname, '..', '..');

if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
if (test('-f', scriptName + '.js')) {
scriptName += '.js';
}
if (test('-f', scriptName + '.coffee')) {
scriptName += '.coffee';
}
}

if (!test('-f', scriptName)) {
exitWithErrorMessage('ShellJS: script not found (' + scriptName + ')');

Check warning on line 33 in index.js

View check run for this annotation

Codecov / codecov/patch

index.js#L33

Added line #L33 was not covered by tests
}

args = process.argv.slice(3);
process.argv = [process.argv[0], process.argv[1], ...args];

var extensions = require('interpret').extensions;
var rechoir = require('rechoir');

rechoir.prepare(extensions, scriptName);
// eslint-disable-next-line import/no-dynamic-require
require(require.resolve(path.resolve(process.cwd(), scriptName)));
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"url": "https://github.com/shelljs/shjs/issues"
},
"files": [
"index.js",
"bin"
],
"homepage": "https://github.com/shelljs/shjs#readme",
Expand Down