JSPM

  • Created
  • Published
  • Downloads 113990
  • Score
    100M100P100Q158059F
  • License MIT

Watch that you expect from gulp.watch

Package Exports

  • gulp-watch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-watch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gulp-watch NPM version Build Status Dependency Status

Watch, that you expect

This is problem solver for this issue with gulp.watch.

Usage

Trigger for mocha

// npm i gulp gulp-watch gulp-mocha

var gulp = require('gulp');
var mocha = require('gulp-mocha');
var watch = require('gulp-watch');
var gutil = require('gulp-util')

gulp.task('mocha', function () {
    return gulp.src(['test/*.js'])
        .pipe(mocha({ reporter: 'list' }))
        .on('error', gutil.log);
});

gulp.src(['lib/**', 'test/**'], { read: false })
    .pipe(watch(function(events, cb) {
        gulp.run('mocha', cb);
    });

Continious stream of events

// npm i gulp gulp-watch gulp-sass

var gulp = require('gulp'),
    watch = require('gulp-watch'),
    sass = require('gulp-sass');

gulp.src('scss/**', { read: false })
    .pipe(watch())
    .pipe(sass());

API

watch([options, callback])

This function creates have two different modes, that are depends on have you provice callback function, or not. If you do - you get batched mode, if you not - you get stream.

Callback signature: function(events, [done]).

  • events - is Array of incoming events.
  • done - is callback for your function signal to batch, that you are done. This allows to run your callback as soon as previous end.

Options:

This object passed to gaze options directly, so see documentation there.

For batched mode we are using gulp-batch, so options from there are available (only timeout was raised to 500).

Events:

To stop watching for files you can use unwatch event:

var pipe = gulp.src(sourceFiles).pipe(watch(function (events) {
    // Do some cool stuff
    pipe.emit('unwatch');
})).on('end', function () {
    console.log('Good work!');
});

After watch recieves unwatch it will call gaze.close and emit end event when gaze is stopped watching files.

Returns:

  • Batched mode - wrapped callback, that will gather events and call callback.
  • Stream mode - stream, that handles gulp.src piping.

License

(MIT License)

Copyright (c) 2013 Vsevolod Strukchinsky (floatdrop@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.