Skip to content

Commit

Permalink
Showing 3 changed files with 57 additions and 21 deletions.
25 changes: 25 additions & 0 deletions bin/__tests__/jscodeshift-test.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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();
46 changes: 25 additions & 21 deletions src/Runner.js
Original file line number Diff line number Diff line change
@@ -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;
})
);

0 comments on commit d3bba64

Please sign in to comment.