Skip to content

Commit

Permalink
add support for optional callback
Browse files Browse the repository at this point in the history
  • Loading branch information
geddski committed May 1, 2015
1 parent 26630ce commit d7c2730
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function log(str) {
write(str + '\n', 'utf8');
}

module.exports = function (grunt) {
module.exports = function (grunt, callback) {
var now = new Date();
var startTimePretty = dateTime();
var startTime = now.getTime();
Expand Down Expand Up @@ -146,6 +146,13 @@ module.exports = function (grunt) {
// `grunt.log.header` should be unhooked above, but in some cases it's not
log('\n\n' + chalk.underline('Execution Time') + chalk.gray(' (' + startTimePretty + ')'));
log(formatTable(tableData) + '\n');

if (callback) {
callback(tableData, function() {
process.exit(exitCode);
});
return;
}
process.exit(exitCode);
});
};
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ module.exports = function (grunt) {
}
```

## Optional Callback

If you want to collect the timing stats for your own use, pass a callback to time-grunt:

```js
require('time-grunt')(grunt, function(stats, done) {
// do whatever you want with the stats
uploadReport(stats);

// be sure to let grunt know when to exit
done();
});
```

## Clean layout

Expand Down

0 comments on commit d7c2730

Please sign in to comment.