Skip to content

Commit d9ceb42

Browse files
caitpmhevery
authored andcommitted
chore(gulp): log message when tasks triggered by watch
Closes angular#1882 Closes angular#1893
1 parent 8d69432 commit d9ceb42

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

gulpfile.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ function createDocsTasks(publicBuild) {
322322

323323
gulp.task(taskPrefix, [taskPrefix + '/assets', taskPrefix + '/app', taskPrefix + '/dgeni']);
324324
gulp.task(taskPrefix + '/watch', function() {
325-
return watch('docs/app/**/*', { ignoreInitial: false }, [taskPrefix + '/app']);
325+
return watch('docs/app/**/*', {
326+
ignoreInitial: false,
327+
log: watchLog
328+
}, [taskPrefix + '/app']);
326329
});
327330

328331
gulp.task(taskPrefix + '/test', function (done) {
@@ -466,7 +469,7 @@ gulp.task('test.unit.cjs', ['build/clean.js', 'build.tools'], function (neverDon
466469
'test.unit.cjs/ci'
467470
];
468471

469-
watch('modules/**', { ignoreInitial: false }, buildAndTest);
472+
watch('modules/**', { ignoreInitial: false, log: watchLog }, buildAndTest);
470473
});
471474

472475

@@ -484,7 +487,10 @@ gulp.task('test.unit.tools', ['build/clean.tools'], function(done) {
484487
'test.unit.tools/ci'
485488
];
486489

487-
watch(['tools/**', '!tools/**/test-fixtures/**'], {ignoreInitial: false}, buildAndTest);
490+
watch(['tools/**', '!tools/**/test-fixtures/**'], {
491+
ignoreInitial: false,
492+
log: watchLog
493+
}, buildAndTest);
488494
});
489495

490496

@@ -836,3 +842,21 @@ process.on('beforeExit', function() {
836842
beforeExitRan = true;
837843
gulp.start('cleanup.builder');
838844
});
845+
846+
function watchLog(triggerCount) {
847+
// Ignore initial event
848+
if (!--triggerCount) return;
849+
850+
process.stdout.write([
851+
'',
852+
'==================================================',
853+
' WATCH TRIGGERED BY FILE CHANGE #' + triggerCount,
854+
' On: ' + prettyTime(),
855+
'==================================================\n',
856+
].join('\n'));
857+
858+
function prettyTime() {
859+
var now = new Date();
860+
return now.toLocaleDateString() + " at " + now.toLocaleTimeString();
861+
}
862+
}

tools/build/watch.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ function watch(globs, opts, tasks) {
88
opts = {};
99
}
1010

11+
var triggerCount = 0;
1112
var useRunSequence = typeof tasks !== 'function';
1213
var runTasks;
1314

15+
function noop() {}
16+
var log = typeof opts.log === 'function' ? opts.log : noop;
17+
1418
if (useRunSequence) {
1519
if (!Array.isArray(tasks)) tasks = [tasks];
1620
tasks = tasks.slice();
@@ -66,6 +70,7 @@ function watch(globs, opts, tasks) {
6670

6771
function invokeCallback() {
6872
eventsRecorded = 0;
73+
log(++triggerCount);
6974
runTasks();
7075
}
7176

0 commit comments

Comments
 (0)