Skip to content

Commit 219a95d

Browse files
committed
refactor: enable code linting
This refactors to a '.js' source file, which enables code linting. This also fixes the lint errors to use an updated style. This also enables test coverage for index.js (which now holds all the business logic).
1 parent b1aba2f commit 219a95d

3 files changed

Lines changed: 46 additions & 37 deletions

File tree

bin/shjs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,4 @@ if (require.main !== module) {
44
throw new Error('Executable-only module should not be required');
55
}
66

7-
// we must import global ShellJS methods after the require.main check to prevent the global
8-
// namespace from being polluted if the error is caught
9-
require('shelljs/global');
10-
11-
function exitWithErrorMessage(msg) {
12-
console.log(msg);
13-
console.log();
14-
process.exit(1);
15-
}
16-
17-
if (process.argv.length < 3) {
18-
exitWithErrorMessage('ShellJS: missing argument (script name)');
19-
}
20-
21-
var args,
22-
scriptName = process.argv[2];
23-
env['NODE_PATH'] = __dirname + '/../..';
24-
25-
if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
26-
if (test('-f', scriptName + '.js'))
27-
scriptName += '.js';
28-
if (test('-f', scriptName + '.coffee'))
29-
scriptName += '.coffee';
30-
}
31-
32-
if (!test('-f', scriptName)) {
33-
exitWithErrorMessage('ShellJS: script not found ('+scriptName+')');
34-
}
35-
36-
args = process.argv.slice(3);
37-
process.argv = [process.argv[0], process.argv[1], ...args];
38-
39-
var path = require('path');
40-
var extensions = require('interpret').extensions;
41-
var rechoir = require('rechoir');
42-
rechoir.prepare(extensions, scriptName);
43-
require(require.resolve(path.resolve(process.cwd(), scriptName)));
7+
require('../index');

index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
3+
/* globals test, env */
4+
5+
const path = require('path');
6+
7+
require('shelljs/global');
8+
9+
function exitWithErrorMessage(msg) {
10+
console.log(msg);
11+
console.log();
12+
process.exit(1);
13+
}
14+
15+
if (process.argv.length < 3) {
16+
exitWithErrorMessage('ShellJS: missing argument (script name)');
17+
}
18+
19+
var args;
20+
var scriptName = process.argv[2];
21+
env.NODE_PATH = path.join(__dirname, '..', '..');
22+
23+
if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
24+
if (test('-f', scriptName + '.js')) {
25+
scriptName += '.js';
26+
}
27+
if (test('-f', scriptName + '.coffee')) {
28+
scriptName += '.coffee';
29+
}
30+
}
31+
32+
if (!test('-f', scriptName)) {
33+
exitWithErrorMessage('ShellJS: script not found (' + scriptName + ')');
34+
}
35+
36+
args = process.argv.slice(3);
37+
process.argv = [process.argv[0], process.argv[1], ...args];
38+
39+
var extensions = require('interpret').extensions;
40+
var rechoir = require('rechoir');
41+
42+
rechoir.prepare(extensions, scriptName);
43+
// eslint-disable-next-line import/no-dynamic-require
44+
require(require.resolve(path.resolve(process.cwd(), scriptName)));

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"url": "https://github.com/shelljs/shjs/issues"
2626
},
2727
"files": [
28+
"index.js",
2829
"bin"
2930
],
3031
"homepage": "https://github.com/shelljs/shjs#readme",

0 commit comments

Comments
 (0)