geolets/gulp/tasks/nodemon.js
2016-07-14 17:15:55 +02:00

34 lines
810 B
JavaScript

'use strict';
const _ = require('lodash');
const gulp = require('gulp');
const browserSync = require('browser-sync');
const nodemon = require('nodemon');
const config = require('../config').nodemon;
// for some reason, this was needed somewhere before
//process.stdout.isTTY = true;
gulp.task('nodemon', (cb) => {
// TODO save pipe to variable so onReadable can be replaced by a arrow function
nodemon(_.defaults({ stdout: false }, config))
.on('readable', function onReadable() {
this.stdout.pipe(process.stdout);
this.stderr.pipe(process.stderr);
this.stdout.on('data', (chunk) => {
if (/Express server started on port/.test(chunk)) {
if (cb)
cb();
cb = null;
if (browserSync.active)
browserSync.reload();
}
});
});
});