Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,7 @@ function createDocsTasks(publicBuild) {

gulp.task(taskPrefix, [taskPrefix + '/assets', taskPrefix + '/app', taskPrefix + '/dgeni']);
gulp.task(taskPrefix + '/watch', function() {
return watch('docs/app/**/*', {
ignoreInitial: false,
log: watchLog
}, [taskPrefix + '/app']);
return watch('docs/app/**/*', [taskPrefix + '/app']);
});

gulp.task(taskPrefix + '/test', function (done) {
Expand Down Expand Up @@ -439,7 +436,7 @@ gulp.task('test.unit.dart', function (done) {
return;
}

watch('modules/angular2/**', { ignoreInitial: true, log: watchLog }, [
watch('modules/angular2/**', { ignoreInitial: true }, [
'!build/tree.dart',
'!test.unit.dart/karma-run'
]);
Expand Down Expand Up @@ -488,7 +485,7 @@ gulp.task('test.unit.cjs', ['build/clean.js', 'build.tools'], function (neverDon
'test.unit.cjs/ci'
];

watch('modules/**', { ignoreInitial: false, log: watchLog }, buildAndTest);
watch('modules/**', buildAndTest);
});


Expand All @@ -506,10 +503,7 @@ gulp.task('test.unit.tools', ['build/clean.tools'], function(done) {
'test.unit.tools/ci'
];

watch(['tools/**', '!tools/**/test-fixtures/**'], {
ignoreInitial: false,
log: watchLog
}, buildAndTest);
watch(['tools/**', '!tools/**/test-fixtures/**'], buildAndTest);
});


Expand Down Expand Up @@ -895,21 +889,3 @@ 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();
}
}
27 changes: 24 additions & 3 deletions tools/build/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ function watch(globs, opts, tasks) {
var useRunSequence = typeof tasks !== 'function';
var runTasks;

var log = typeof opts.log === 'function' ? opts.log : function noop() {};

if (useRunSequence) {
if (!Array.isArray(tasks)) tasks = [tasks];
tasks = tasks.slice();
Expand Down Expand Up @@ -50,6 +48,28 @@ function watch(globs, opts, tasks) {
throw err;
});

var log = function watchLogger(triggerCount) {
// Don't report change for initial event
if (!ignoreInitial && !--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();
}
}

if (opts.log !== undefined && !opts.log) {
log = function noopLog(triggerCount) {}
}

var close = watcher.close.bind(watcher);
watcher.close = function() {
if (timeoutId !== null) clearTimeout(timeoutId);
Expand All @@ -60,7 +80,8 @@ function watch(globs, opts, tasks) {
var timeoutId = null; // If non-null, event capture window is open

if (!ignoreInitial) {
handleEvent('change', 'madeupFilePath'); // synthetic event to kick off the first task run
// synthetic event to kick off the first task run
timeoutId = setTimeout(invokeCallback, delay);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part LGTM

}

return watcher;
Expand Down
10 changes: 5 additions & 5 deletions tools/build/watch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('watch()', function() {

it('should fire callback once for events which occur within `delay` window', function() {
var cb = jasmine.createSpy('callback');
watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
watcher = watch('./$$fake_path/**/*', { delay: 10, log: false }, cb);

watcher._emit('add', './$$fake_path/test.txt');
timeout.flush(9);
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('watch()', function() {
expect(timeout.pending).toBe(1);
}

var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
var watcher = watch('./$$fake_path/**/*', { delay: 10, log: false }, cb);

watcher._emit('change', './$$fake_path/test1.txt');
expect(timeout.pending).toBe(1);
Expand All @@ -81,7 +81,7 @@ describe('watch()', function() {
done();
}

var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
var watcher = watch('./$$fake_path/**/*', { delay: 10, log: false }, cb);

watcher._emit('change', './$$fake_path/test1.txt');
timeout.flush();
Expand All @@ -96,7 +96,7 @@ describe('watch()', function() {

it('should cancel pending callback if FSWatcher is closed', function() {
var cb = jasmine.createSpy('callback');
var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
var watcher = watch('./$$fake_path/**/*', { delay: 10, log: false }, cb);

watcher._emit('change', './$$fake_path/test1.txt');
expect(timeout.pending).toBe(1);
Expand All @@ -119,7 +119,7 @@ describe('watch()', function() {
expect(timeout.pending).toBe(0);
}

var watcher = watch('./$$fake_path/**/*', { delay: 10 }, cb);
var watcher = watch('./$$fake_path/**/*', { delay: 10, log: false }, cb);
watcher._emit('change', './$$fake_path/test1.txt');

timeout.flush(10);
Expand Down