diff --git a/README.md b/README.md index c0ced688..b3ae78d6 100644 --- a/README.md +++ b/README.md @@ -116,21 +116,25 @@ Help: concurrently [options] General - -m, --max-processes How many processes should run at once. - New processes only spawn after all restart tries of a - process. [number] - -n, --names List of custom names to be used in prefix template. - Example names: "main,browser,server" [string] - --name-separator The character to split on. Example usage: - concurrently -n "styles|scripts|server" --name-separator - "|" [default: ","] - -r, --raw Output only raw output of processes, disables prettifying - and concurrently coloring. [boolean] - -s, --success Return exit code of zero or one based on the success or - failure of the "first" child to terminate, the "last - child", or succeed only if "all" child processes succeed. + -m, --max-processes How many processes should run at once. + New processes only spawn after all restart tries of a + process. [number] + -n, --names List of custom names to be used in prefix template. + Example names: "main,browser,server" [string] + --name-separator The character to split on. Example usage: + concurrently -n "styles|scripts|server" --name-separator + "|" [default: ","] + -r, --raw Output only raw output of processes, disables + prettifying and concurrently coloring. [boolean] + -s, --success Return exit code of zero or one based on the success or + failure of the "first" child to terminate, the "last + child", or succeed only if "all" child processes + succeed. [choices: "first", "last", "all"] [default: "all"] - --no-color Disables colors from logging [boolean] + --no-color Disables colors from logging [boolean] + --hide Comma-separated list of processes to hide the output. + The processes can be identified by their name or index. + [string] [default: ""] Prefix styling -p, --prefix Prefix used in logging for each process. diff --git a/bin/concurrently.js b/bin/concurrently.js index 7ec2fc76..9dc31fc6 100755 --- a/bin/concurrently.js +++ b/bin/concurrently.js @@ -55,6 +55,13 @@ const args = yargs describe: 'Disables colors from logging', type: 'boolean' }, + 'hide': { + describe: + 'Comma-separated list of processes to hide the output.\n' + + 'The processes can be identified by their name or index.', + default: defaults.hide, + type: 'string' + }, // Kill others 'k': { @@ -135,7 +142,7 @@ const args = yargs 'Can be either the index or the name of the process.' } }) - .group(['m', 'n', 'name-separator', 'raw', 's', 'no-color'], 'General') + .group(['m', 'n', 'name-separator', 'raw', 's', 'no-color', 'hide'], 'General') .group(['p', 'c', 'l', 't'], 'Prefix styling') .group(['i', 'default-input-target'], 'Input handling') .group(['k', 'kill-others-on-fail'], 'Killing other processes') @@ -157,6 +164,7 @@ concurrently(args._.map((command, index) => ({ : (args.killOthersOnFail ? ['failure'] : []), maxProcesses: args.maxProcesses, raw: args.raw, + hide: args.hide.split(','), prefix: args.prefix, prefixColors: args.prefixColors.split(','), prefixLength: args.prefixLength, diff --git a/bin/concurrently.spec.js b/bin/concurrently.spec.js index 419f5133..aa1b84af 100644 --- a/bin/concurrently.spec.js +++ b/bin/concurrently.spec.js @@ -163,6 +163,26 @@ describe('--raw', () => { }); }); +describe('--hide', () => { + it('hides the output of a process by its index', done => { + const child = run('--hide 1 "echo foo" "echo bar"'); + child.log.pipe(buffer(child.close)).subscribe(lines => { + expect(lines).toContainEqual(expect.stringContaining('foo')); + expect(lines).not.toContainEqual(expect.stringContaining('bar')); + done(); + }, done); + }); + + it('hides the output of a process by its name', done => { + const child = run('-n foo,bar --hide bar "echo foo" "echo bar"'); + child.log.pipe(buffer(child.close)).subscribe(lines => { + expect(lines).toContainEqual(expect.stringContaining('foo')); + expect(lines).not.toContainEqual(expect.stringContaining('bar')); + done(); + }, done); + }); +}); + describe('--names', () => { it('is aliased to -n', done => { const child = run('-n foo,bar "echo foo" "echo bar"'); diff --git a/index.js b/index.js index d21007ac..5abc24f0 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ const Logger = require('./src/logger'); module.exports = exports = (commands, options = {}) => { const logger = new Logger({ + hide: options.hide, outputStream: options.outputStream || process.stdout, prefixFormat: options.prefix, prefixLength: options.prefixLength, diff --git a/src/defaults.js b/src/defaults.js index c5068f23..695c0dd1 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -10,6 +10,8 @@ module.exports = { handleInput: false, // How many processes to run at once maxProcesses: 0, + // Indices and names of commands whose output to be not logged + hide: '', nameSeparator: ',', // Which prefix style to use when logging processes output. prefix: '', diff --git a/src/logger.js b/src/logger.js index 09f22403..7b3b936f 100644 --- a/src/logger.js +++ b/src/logger.js @@ -5,7 +5,11 @@ const formatDate = require('date-fns/format'); const defaults = require('./defaults'); module.exports = class Logger { - constructor({ outputStream, prefixFormat, prefixLength, raw, timestampFormat }) { + constructor({ hide, outputStream, prefixFormat, prefixLength, raw, timestampFormat }) { + // To avoid empty strings from hiding the output of commands that don't have a name, + // keep in the list of commands to hide only strings with some length. + // This might happen through the CLI when no `--hide` argument is specified, for example. + this.hide = _.castArray(hide).filter(name => name || name === 0).map(String); this.raw = raw; this.outputStream = outputStream; this.prefixFormat = prefixFormat; @@ -76,6 +80,10 @@ module.exports = class Logger { } logCommandText(text, command) { + if (this.hide.includes(String(command.index)) || this.hide.includes(command.name)) { + return; + } + const prefix = this.colorText(command, this.getPrefix(command)); return this.log(prefix + (prefix ? ' ' : ''), text); } diff --git a/src/logger.spec.js b/src/logger.spec.js index 2627f34d..d3f201dd 100644 --- a/src/logger.spec.js +++ b/src/logger.spec.js @@ -176,6 +176,20 @@ describe('#logCommandText()', () => { expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor)('[1]') + ' ', 'foo'); }); + + it('does nothing if command is hidden by name', () => { + const logger = createLogger({ hide: ['abc'] }); + logger.logCommandText('foo', { name: 'abc' }); + + expect(logger.log).not.toHaveBeenCalled(); + }); + + it('does nothing if command is hidden by index', () => { + const logger = createLogger({ hide: [3] }); + logger.logCommandText('foo', { index: 3 }); + + expect(logger.log).not.toHaveBeenCalled(); + }); }); describe('#logCommandEvent()', () => { @@ -186,6 +200,20 @@ describe('#logCommandEvent()', () => { expect(logger.log).not.toHaveBeenCalled(); }); + it('does nothing if command is hidden by name', () => { + const logger = createLogger({ hide: ['abc'] }); + logger.logCommandEvent('foo', { name: 'abc' }); + + expect(logger.log).not.toHaveBeenCalled(); + }); + + it('does nothing if command is hidden by index', () => { + const logger = createLogger({ hide: [3] }); + logger.logCommandEvent('foo', { index: 3 }); + + expect(logger.log).not.toHaveBeenCalled(); + }); + it('logs text in gray dim', () => { const logger = createLogger(); logger.logCommandEvent('foo', { index: 1 });