Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add '--silent' or '-s' option to suppress output #79

Merged
merged 1 commit into from
Dec 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions bin/__tests__/jscodeshift-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}
);
});
})
});
7 changes: 7 additions & 0 deletions bin/jscodeshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
46 changes: 25 additions & 21 deletions src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
})
);
Expand Down