From d9ceb42bfeeacd8c5ec17a4c275c55b2c848b312 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Thu, 14 May 2015 02:39:04 -0400 Subject: [PATCH] chore(gulp): log message when tasks triggered by watch Closes #1882 Closes #1893 --- gulpfile.js | 30 +++++++++++++++++++++++++++--- tools/build/watch.js | 5 +++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index f281d6bf3a..1b62b2475e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -322,7 +322,10 @@ function createDocsTasks(publicBuild) { gulp.task(taskPrefix, [taskPrefix + '/assets', taskPrefix + '/app', taskPrefix + '/dgeni']); 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) { @@ -466,7 +469,7 @@ gulp.task('test.unit.cjs', ['build/clean.js', 'build.tools'], function (neverDon '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' ]; - 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; 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(); + } +} diff --git a/tools/build/watch.js b/tools/build/watch.js index fb8948c6bd..15a600ca72 100644 --- a/tools/build/watch.js +++ b/tools/build/watch.js @@ -8,9 +8,13 @@ function watch(globs, opts, tasks) { opts = {}; } + var triggerCount = 0; var useRunSequence = typeof tasks !== 'function'; var runTasks; + function noop() {} + var log = typeof opts.log === 'function' ? opts.log : noop; + if (useRunSequence) { if (!Array.isArray(tasks)) tasks = [tasks]; tasks = tasks.slice(); @@ -66,6 +70,7 @@ function watch(globs, opts, tasks) { function invokeCallback() { eventsRecorded = 0; + log(++triggerCount); runTasks(); }