gimm / gulp-live-server

serve your nodejs/static app live
148 stars 71 forks source link

when use gulp,restart error #44

Open heran opened 9 years ago

heran commented 9 years ago

gulpfile.js: gulp.watch('some.file.ext', server.start.bind(server));

gls/index.js:exports.start = function (execPath) {...this.server = spawn(this.config.execPath, this.config.args, this.config.options);...}

execPath will be:{type: evt, path: path}

come from glob-watched/index.js:

rwatcher.on('all', function(evt, path, old){
      var outEvt = {type: evt, path: path};
      if(old) outEvt.old = old;
      out.emit('change', outEvt);
      if(cb) cb(outEvt);
    });

then get the spawn error:

child_process.js:1136
  var err = this._handle.spawn(options);
                         ^
TypeError: Bad argument
    at TypeError (native)
    at ChildProcess.spawn (child_process.js:1136:26)
    at exports.spawn (child_process.js:995:9)
    at Object.exports.start (..\node_modules\gulp-live-server\index.js:134:19)
    at Gaze.<anonymous> (..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\index.js:18:14)
    at Gaze.emit (events.js:110:17)
    at Gaze.emit (..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:129:32)
    at ..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:415:16
    at StatWatcher._pollers.(anonymous function) (..\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:32
    at StatWatcher.emit (events.js:110:17)
smprather commented 8 years ago

I have this working with an express-generator skeleton. I don't really know what I'm doing, so it may not be "correct", but it works.

var gulp = require('gulp');
var gls = require('gulp-live-server');
gulp.task('serve', function() {
    var server = gls.new('bin/www', {env: {NODE_ENV: 'development'}});
    server.start();

    gulp.watch(['views/*', 'public/**/*'], function (file) {
      server.notify.apply(server, [file]);
    });
    gulp.watch(['bin/www', 'app.js', 'routes/*'], function (file) {
      server.start.apply(server);
      server.notify.apply(server, [file]);
    })
});
heran commented 8 years ago

My code, not work:

    var path              = require('path-extra');
    var server = gls(path.join(__dirname, 'bin/www') , {env: {NODE_ENV: 'development'}});
    server.start();

    gulp.watch(['app/**'], function (file) {
        server.notify.apply(server, [file]);
        console.log('brower reload');
    });

I must patch gls/index.js , line 132

this.config.execPath =  (util.isString(execPath)?execPath:false) || this.config.execPath || process.execPath;