diff --git a/bin/__tests__/jscodeshift-test.js b/bin/__tests__/jscodeshift-test.js index d15d9b2f..1af70f76 100644 --- a/bin/__tests__/jscodeshift-test.js +++ b/bin/__tests__/jscodeshift-test.js @@ -117,4 +117,29 @@ describe('jscodeshift CLI', () => { ); }); + describe('output', () => { + pit('shows workers info and stats at the end by default', () => { + var source = createTempFileWith('a'); + var transform = createTransformWith('return null;'); + return run(['-t', transform, source]).then( + ([stdout, stderr]) => { + expect(stdout).toContain('Processing 1 files...'); + expect(stdout).toContain('Spawning 1 workers with 1 files each...'); + expect(stdout).toContain('All done.'); + expect(stdout).toContain('Results: '); + expect(stdout).toContain('Time elapsed: '); + } + ); + }); + + pit('does not ouput anything in silent mode', () => { + var source = createTempFileWith('a'); + var transform = createTransformWith('return null;'); + return run(['-t', transform, '-s', source]).then( + ([stdout, stderr]) => { + expect(stdout).toEqual(''); + } + ); + }); + }) }); diff --git a/bin/jscodeshift.sh b/bin/jscodeshift.sh index f814c2e3..4fc03f14 100755 --- a/bin/jscodeshift.sh +++ b/bin/jscodeshift.sh @@ -64,6 +64,13 @@ var opts = require('nomnom') default: false, full: 'run-in-band', help: 'Run serially in the current process' + }, + silent: { + abbr: 's', + flag: true, + default: false, + full: 'silent', + help: 'No output' } }) .parse(); diff --git a/src/Runner.js b/src/Runner.js index f57806de..cba0314a 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -108,18 +108,20 @@ function run(transformFile, paths, options) { fileChunks.push(files.slice(i, i + chunkSize)); } - console.log('Processing %d files...', files.length); - if (!options.runInBand) { - console.log( - 'Spawning %d workers with %d files each...', - fileChunks.length, - fileChunks[0].length - ); - } - if (options.dry) { - console.log( - clc.green('Running in dry mode, no files will be written!') - ); + if (!options.silent) { + console.log('Processing %d files...', files.length); + if (!options.runInBand) { + console.log( + 'Spawning %d workers with %d files each...', + fileChunks.length, + fileChunks[0].length + ); + } + if (options.dry) { + console.log( + clc.green('Running in dry mode, no files will be written!') + ); + } } return fileChunks.map(files => { @@ -147,15 +149,17 @@ function run(transformFile, paths, options) { }) .then(pendingWorkers => Promise.all(pendingWorkers).then(() => { - const endTime = process.hrtime(startTime); - console.log('All done.'); - showFileStats(fileCounters); - showStats(statsCounter); - console.log( - 'Time elapsed: %d.%d seconds', - endTime[0], - (endTime[1]/1000000).toFixed(0) - ); + if (!options.silent) { + const endTime = process.hrtime(startTime); + console.log('All done.'); + showFileStats(fileCounters); + showStats(statsCounter); + console.log( + 'Time elapsed: %d.%d seconds', + endTime[0], + (endTime[1]/1000000).toFixed(0) + ); + } return fileCounters; }) );