Socket
Socket
Sign inDemoInstall

shx

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shx - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

README.md

37

lib/cli.js

@@ -6,2 +6,37 @@ #!/usr/bin/env node

process.exit((0, _shx.shx)(process.argv));
// `input` is null if we're running from a TTY, or a string of all stdin if
// running from the right-hand side of a pipe
var run = function run(input) {
// Pass stdin to shx as the 'this' parameter
var code = _shx.shx.call(input, process.argv);
// Make sure output is flushed before exiting the process. Please see:
// - https://github.com/shelljs/shx/issues/85
// - https://github.com/mochajs/mocha/issues/333
var streamCount = 0;
var streams = [process.stdout, process.stderr];
streams.forEach(function (stream) {
streamCount++; // count each stream
stream.write('', function () {
streamCount--; // mark each stream as finished
if (streamCount === 0) process.exit(code);
});
});
};
// ShellJS doesn't support input streams, so we have to collect all input first
if (process.stdin.isTTY) {
// There's no stdin, so we can immediately invoke the ShellJS function
run(null);
} else {
(function () {
// Read all stdin first, and then pass that onto ShellJS
var chunks = [];
process.stdin.on('data', function (data) {
return chunks.push(data);
});
process.stdin.on('end', function () {
return run(chunks.join(''));
});
})();
}

4

lib/config.js

@@ -12,2 +12,4 @@ 'use strict';

var CMD_BLACKLIST = exports.CMD_BLACKLIST = ['cd', 'pushd', 'popd', 'dirs', 'set', 'exit', 'exec', 'ShellString'];
var CMD_BLACKLIST = exports.CMD_BLACKLIST = ['cd', 'pushd', 'popd', 'dirs', 'set', 'exit', 'exec', 'ShellString'];
var CONFIG_FILE = exports.CONFIG_FILE = '.shxrc.json';
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

@@ -15,12 +15,10 @@

var commandList = Object.keys(_shelljs2.default).filter(function (cmd) {
exports.default = function () {
var commandList = Object.keys(_shelljs2.default).filter(function (cmd) {
return typeof _shelljs2.default[cmd] === 'function' && _config.CMD_BLACKLIST.indexOf(cmd) === -1;
});
});
var help = '\nshx: A wrapper for shelljs UNIX commands.\n\nUsage: shx <command> [options]\n\nExample:\n\n $ shx ls .\n foo.txt\n bar.txt\n baz.js\n $ shx rm -rf *.txt\n $ shx ls .\n baz.js\n\nCommands:\n\n' + commandList.map(function (cmd) {
return '\nshx: A wrapper for shelljs UNIX commands.\n\nUsage: shx <command> [options]\n\nExample:\n\n $ shx ls .\n foo.txt\n bar.txt\n baz.js\n $ shx rm -rf *.txt\n $ shx ls .\n baz.js\n\nCommands:\n\n' + commandList.map(function (cmd) {
return ' - ' + cmd;
}).join('\n') + '\n';
exports.default = function () {
return help;
}).join('\n') + '\n';
};

@@ -9,10 +9,7 @@ 'use strict';

var printCmdRet = exports.printCmdRet = function printCmdRet(ret) {
if (!ret) return;
if (typeof ret === 'boolean') return; // don't print this
// Don't print these types
if (typeof ret === 'boolean' || !ret) return;
if (typeof ret.stdout === 'string') {
process.stdout.write(ret.stdout);
} else if (Array.isArray(ret)) {
process.stdout.write(ret.join('\n'));
if (ret.length > 0) console.log(); // an extra newline
} else {

@@ -19,0 +16,0 @@ process.stdout.write(ret);

@@ -7,3 +7,3 @@ #!/usr/bin/env node

});
exports.shx = undefined;
exports.shx = shx;

@@ -26,11 +26,23 @@ var _shelljs = require('shelljs');

var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
var _es6ObjectAssign = require('es6-object-assign');
var _es6ObjectAssign2 = _interopRequireDefault(_es6ObjectAssign);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
_es6ObjectAssign2.default.polyfill(); // modifies the global object
_shelljs2.default.help = _help2.default;
var shx = exports.shx = function shx(argv) {
function shx(argv) {
var parsedArgs = (0, _minimist2.default)(argv.slice(2), { stopEarly: true, boolean: true });

@@ -50,2 +62,21 @@

// Load ShellJS plugins
var CONFIG_PATH = _path2.default.join(process.cwd(), _config.CONFIG_FILE);
if (_fs2.default.existsSync(CONFIG_PATH)) {
var shxConfig = void 0;
try {
shxConfig = require(CONFIG_PATH);
} catch (e) {
throw new Error('Unable to read config file ' + _config.CONFIG_FILE);
}
(shxConfig.plugins || []).forEach(function (pluginName) {
try {
require(pluginName);
} catch (e) {
throw new Error('Unable to find plugin \'' + pluginName + '\'');
}
});
}
// validate command

@@ -62,2 +93,4 @@ if (typeof _shelljs2.default[fnName] !== 'function') {

var input = this !== null ? new _shelljs2.default.ShellString(this) : null;
// Set shell.config with parsed options

@@ -86,15 +119,21 @@ Object.assign(_shelljs2.default.config, parsedArgs);

});
ret = _shelljs2.default[fnName].apply(_shelljs2.default, _toConsumableArray(newArgs));
ret = _shelljs2.default[fnName].apply(input, newArgs);
})();
} else {
ret = _shelljs2.default[fnName].apply(_shelljs2.default, _toConsumableArray(args));
ret = _shelljs2.default[fnName].apply(input, args);
}
if (ret === null) ret = _shelljs2.default.ShellString('', '', 1);
/* instanbul ignore next */
var code = ret.hasOwnProperty('code') && ret.code;
if ((fnName === 'pwd' || fnName === 'which') && !ret.endsWith('\n') && ret.length > 1) ret += '\n';
if ((fnName === 'pwd' || fnName === 'which') && !ret.match(/\n$/) && ret.length > 1) {
ret += '\n';
}
// echo already prints
if (fnName !== 'echo') (0, _printCmdRet.printCmdRet)(ret);
if (typeof ret === 'boolean') code = ret ? 0 : 1;
if (typeof ret === 'boolean') {
code = ret ? 0 : 1;
}

@@ -108,2 +147,2 @@ if (typeof code === 'number') {

return _config.EXIT_CODES.SUCCESS;
};
}
{
"name": "shx",
"version": "0.1.4",
"version": "0.2.0",
"description": "Portable Shell Commands for Node",

@@ -25,2 +25,3 @@ "bin": {

"changelog": "shelljs-changelog",
"codecov": "codecov",
"test": "nyc --reporter=text --reporter=lcov mocha",

@@ -57,5 +58,4 @@ "test:watch": "concurrently -rk 'npm run test --silent -- -w' 'npm run lint:watch'"

"babel-register": "^6.7.2",
"chai": "^3.5.0",
"codecov": "^1.0.1",
"concurrently": "^2.1.0",
"dirty-chai": "^1.2.2",
"eslint": "^2.10.1",

@@ -68,11 +68,12 @@ "eslint-config-airbnb-base": "^3.0.1",

"shelljs-changelog": "^0.2.0",
"shelljs-plugin-open": "^0.1.1",
"shelljs-release": "^0.2.0",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"should": "^11.1.1",
"watch": "^0.18.0"
},
"dependencies": {
"es6-object-assign": "^1.0.3",
"minimist": "^1.2.0",
"shelljs": "^0.7.0"
"shelljs": "^0.7.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc