gimm / gulp-express

gulp plugin for express
56 stars 26 forks source link

server.run #18

Closed Alexandrescu closed 9 years ago

Alexandrescu commented 9 years ago
[12:47:39] Starting 'vendor'...
[12:47:39] Finished 'vendor' after 5.93 ms
[12:47:39] Starting 'styles:scss'...
[12:47:39] Finished 'styles:scss' after 3.55 ms
[12:47:39] Starting 'server'...
[12:47:39] Finished 'server' after 9.84 ms
[12:47:39] Starting 'default'...
[12:47:39] Finished 'default' after 20 μs
Service process exited with code null SIGKILL
Service process exited with code null SIGKILL
Service process exited with code 0 null

This is the output that happens when the server is notify to restart (server.run). (when app.js is modified)

(Part of) My gulp file is:

gulp.task('vendor', function() {

    vendor.forEach(function(entry) {
       gulp.src(entry.file).
           pipe(gulp.dest(vendorLocation + entry.destination));
    });

});

// Compiling sass
gulp.task('styles:scss', function() {
    gulp.src('./styles/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(sass())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('public/stylesheets'));
});

// Running the express server
gulp.task('server', function () {
    // Start the server at the beginning of the task
    server.run({
        // file: 'app.js'
        file: './bin/www'
    });

    gulp.watch(['./styles/**.*scss'], ['styles:scss']);

    // Restart the server when file changes
    gulp.watch(['views/**/*.jade'], server.notify);
    gulp.watch(['./public/stylesheets/**/*.css'], server.notify);
    //gulp.watch(['{.tmp,app}/styles/**/*.css'], ['styles:css', server.notify]);
    //Event object won't pass down to gulp.watch's callback if there's more than one of them.
    //So the correct way to use server.notify is as following:

    gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
});

gulp.task('default', ['vendor', 'server']);

I don't really understand what happens when server.run is called. Seems like it's calling node start - which in my case is set to be "gulp", meaning it should call only the default task, but what happens is it seems to be calling all the tasks in my gulp file. Where is my reasoning wrong?

simevidas commented 9 years ago

Not sure if you got notified, but there’s some discussion about this issue here: https://github.com/gimm/gulp-express/issues/3.

Alexandrescu commented 9 years ago

I have looked over #3 and it works. In the example given on the readme page, server.run in this line:

gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);

is (you might think) running with the default options. This is wrong! Either enforce using the plugin such as in issue 3 or not. This is because it's evaluating server.run as a string - this is the type watch is expecting to find. I reckon because it can't match any of the tasks (or maybe because it's matching all of them) it's going to run all the tasks when the watch is triggered.

Doing this:

gulp.watch(['app.js', 'routes/**/*.js'], server.run(serverOptions));

Evaluates the function once and it's going to have the return value of it 'called' by watch.

This is briefly the reason why #3 works and what you have written doesn't.

In my opinion (since I'm a lazy person), I would mention this on the main page. It would save people valuable time.

This is why javascript should be typed. Have a good day!

simevidas commented 9 years ago

@Alexandrescu I’m sorry but I don’t understand what you’re saying. Have your resolved your issue? If yes, what changes did you perform to your gulpfile?

Also, you wrote:

This is briefly the reason why #3 works and what you have written doesn't.

What are you referring to? I didn’t post any code. I just posted a screenshot.

mlaccetti commented 9 years ago

Gah - this should have be a 0.2 change; just spent a day bashing my head against the wall because server.run changed the signature. Sigh.

derekakers commented 9 years ago

+1, that's a big thing to change. glad @mlaccetti was able to find it.

gimm commented 9 years ago

@mlaccetti really sorry for not making it clear :(