Skip to content

Commit

Permalink
Always silence shelljs
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 10, 2019
1 parent 84d3f17 commit f25cd26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 5 additions & 9 deletions lib/shell.js
Expand Up @@ -9,8 +9,9 @@ const Config = require('./config');
const { debugShell: debug } = require('./debug');
const { format } = require('./util');

const noop = Promise.resolve();
sh.config.silent = true;

const noop = Promise.resolve();
const forcedCmdRe = /^!/;

class Shell {
Expand All @@ -25,8 +26,6 @@ class Shell {
const normalizedCmd = command.replace(forcedCmdRe, '');
const program = normalizedCmd.split(' ')[0];
const programArgs = normalizedCmd.split(' ').slice(1);
const isSilent = sh.config.silent;
const isVerbose = typeof options.verbose === 'boolean' ? options.verbose : this.isVerbose;

this.log.exec(normalizedCmd);

Expand All @@ -37,11 +36,9 @@ class Shell {

return new Promise((resolve, reject) => {
const cb = (code, stdout, stderr) => {
stdout = stdout.toString();
if (isVerbose && !stdout.endsWith(EOL)) process.stdout.write(EOL);
stdout = stdout.trim();
stdout = stdout.toString().trim();
this.log.verbose(stdout);
debug({ command, options, code, stdout, stderr });
sh.config.silent = isSilent;
if (code === 0) {
resolve(stdout);
} else {
Expand All @@ -50,10 +47,9 @@ class Shell {
};

if (program in sh && typeof sh[program] === 'function' && forcedCmdRe.test(command)) {
sh.config.silent = !isVerbose;
cb(0, sh[program](...programArgs));
} else {
sh.exec(normalizedCmd, { async: true, silent: !isVerbose }, cb);
sh.exec(normalizedCmd, { async: true }, cb);
}
});
}
Expand Down
4 changes: 1 addition & 3 deletions test/shell.js
Expand Up @@ -46,11 +46,9 @@ test('run (dry-run/read-only)', async t => {
test('run (verbose)', async t => {
const log = sinon.createStubInstance(Log);
const shell = new Shell({ isVerbose: true, log });
mockStdIo.start();
const actual = await shell.run('echo foo');
const { stdout } = mockStdIo.end();
t.is(log.exec.firstCall.args[0], 'echo foo');
t.is(stdout, `foo${EOL}`);
t.is(log.verbose.firstCall.args[0], 'foo');
t.is(actual, 'foo');
});

Expand Down

0 comments on commit f25cd26

Please sign in to comment.