chore(gulp): log message when tasks triggered by watch

Closes #1882

Closes #1893
This commit is contained in:
Caitlin Potter 2015-05-14 02:39:04 -04:00 committed by Misko Hevery
parent 8d6943227d
commit d9ceb42bfe
2 changed files with 32 additions and 3 deletions

View File

@ -322,7 +322,10 @@ function createDocsTasks(publicBuild) {
gulp.task(taskPrefix, [taskPrefix + '/assets', taskPrefix + '/app', taskPrefix + '/dgeni']); gulp.task(taskPrefix, [taskPrefix + '/assets', taskPrefix + '/app', taskPrefix + '/dgeni']);
gulp.task(taskPrefix + '/watch', function() { gulp.task(taskPrefix + '/watch', function() {
return watch('docs/app/**/*', { ignoreInitial: false }, [taskPrefix + '/app']); return watch('docs/app/**/*', {
ignoreInitial: false,
log: watchLog
}, [taskPrefix + '/app']);
}); });
gulp.task(taskPrefix + '/test', function (done) { gulp.task(taskPrefix + '/test', function (done) {
@ -466,7 +469,7 @@ gulp.task('test.unit.cjs', ['build/clean.js', 'build.tools'], function (neverDon
'test.unit.cjs/ci' 'test.unit.cjs/ci'
]; ];
watch('modules/**', { ignoreInitial: false }, buildAndTest); watch('modules/**', { ignoreInitial: false, log: watchLog }, buildAndTest);
}); });
@ -484,7 +487,10 @@ gulp.task('test.unit.tools', ['build/clean.tools'], function(done) {
'test.unit.tools/ci' 'test.unit.tools/ci'
]; ];
watch(['tools/**', '!tools/**/test-fixtures/**'], {ignoreInitial: false}, buildAndTest); watch(['tools/**', '!tools/**/test-fixtures/**'], {
ignoreInitial: false,
log: watchLog
}, buildAndTest);
}); });
@ -836,3 +842,21 @@ process.on('beforeExit', function() {
beforeExitRan = true; beforeExitRan = true;
gulp.start('cleanup.builder'); gulp.start('cleanup.builder');
}); });
function watchLog(triggerCount) {
// Ignore initial event
if (!--triggerCount) return;
process.stdout.write([
'',
'==================================================',
' WATCH TRIGGERED BY FILE CHANGE #' + triggerCount,
' On: ' + prettyTime(),
'==================================================\n',
].join('\n'));
function prettyTime() {
var now = new Date();
return now.toLocaleDateString() + " at " + now.toLocaleTimeString();
}
}

View File

@ -8,9 +8,13 @@ function watch(globs, opts, tasks) {
opts = {}; opts = {};
} }
var triggerCount = 0;
var useRunSequence = typeof tasks !== 'function'; var useRunSequence = typeof tasks !== 'function';
var runTasks; var runTasks;
function noop() {}
var log = typeof opts.log === 'function' ? opts.log : noop;
if (useRunSequence) { if (useRunSequence) {
if (!Array.isArray(tasks)) tasks = [tasks]; if (!Array.isArray(tasks)) tasks = [tasks];
tasks = tasks.slice(); tasks = tasks.slice();
@ -66,6 +70,7 @@ function watch(globs, opts, tasks) {
function invokeCallback() { function invokeCallback() {
eventsRecorded = 0; eventsRecorded = 0;
log(++triggerCount);
runTasks(); runTasks();
} }