ColemanGariety / gulp-nodemon

gulp + nodemon + convenience
526 stars 76 forks source link

Pass in config settings? #3

Closed poeticninja closed 10 years ago

poeticninja commented 10 years ago

I am needing to watch more than one file type, javascript and template files, and then I want to reload the server. It would be nice to be able to pass in arguments.

Unless you suggest another way that I am not thinking of yet.

poeticninja commented 10 years ago

I did a test and where this code is in the plugin,

      nodemon({
        script: file.path
      , args: []
      , restartable: 'rs'
      })

I changed it to,

      nodemon(settings)

and where I call gulp-nodemon in my gulpfile I use,

.pipe(nodemon('-e js,html'))

Now it watches for all of my js and html files. I might be missing something but it looks like it would allow people to config nodemon however they need. Just interesting to hear what you have to say.

ColemanGariety commented 10 years ago

@poeticninja and it still executes on the pile that you pass to gulp.src? If it does, perfect! Otherwise, I'll have to parse the options you pass into the args array.

ColemanGariety commented 10 years ago

@poeticninja got this figured out, will publish 0.0.4 later today.

poeticninja commented 10 years ago

Great!

One problem I was having with your README example,

gulp.task('develop', function () {
  gulp.src('./server.js')
      .pipe(jshint())
      .pipe(nodemon())
})

For gulp.src() people might pass in an array of files, because they want to lint more than just the server.js. And right now the way gulp-nodemon is you can't do that. I say this plugin doesn't do anything with the files but handles nodemon itself. Just a wrapper for it. Thoughts?

Not sure what you solution will be, but I do look forward to seeing what you come up with!

ColemanGariety commented 10 years ago

@poeticninja

Each of the Gulp tasks below describes a possible way of running a server with gulp-nodemon 0.0.4, and jshinting all of its code each time the server starts. I'm trying to decide which way is nicer.

First option

gulp.task('develop', function () {
  gulp.src(['./server1.js', './server2.js'])
    .pipe(
      nodemon('-e html,js')
        .pipe(
          gulp.src('./**/*.js')
            .pipe(jshint())
        )
    )
})

Second option

gulp.task('develop', function () {
  nodemon({ script: './server1.js', args: '-e html,js' })
    .pipe(
      gulp.src('./**/*.js')
        .pipe(jshint())
    )
  nodemon({ script: './server2.js', args: '-e html,js' })
    .pipe(
      gulp.src('./**/*.js')
        .pipe(jshint())
    )
})

@Contra @robrich Which is cleaner and falls more in line with the gulp methodology?

poeticninja commented 10 years ago

The second option looks great. I dont see any problems with it. A person would have full access to nodemon options by passing in a json object to it, and get to run other tasks as soon as the server restarts. Or run tasks before the server starts for the first time.

The first option seems to limit what options you have with nodemon. Some people might want to change the delayTime or use one of the other options nodemon provides.

The second option looks like a real wrapper for nodemon.

For an idea on how people are going to use the options of nodemon in a task runner, you could look at https://github.com/ChrisWren/grunt-nodemon.

As long as the nodeman options are available and you are able to have tasks be able to run before and after it, then you are fine.

yocontra commented 10 years ago

@sindresorhus do you think this should be a plugin?

yocontra commented 10 years ago

@robrich nodemon provides hot reloading of code in a node process

robrich commented 10 years ago

I'm thinking something like this:

gulp.task('watch', function () {
  gulp.watch(['glob','here'])
    .pipe(jshint())
    .pipe(es.wait(function (err) {
      nodemon('./server.js');
    });
});

in which case, it isn't really a gulp-plugin but rather gulp-friendly ... and perhaps more generic too.

yocontra commented 10 years ago

@robrich I agree this should be gulpfriendly not gulpplugin

ColemanGariety commented 10 years ago

@robrich @Contra one question on robrich's example: why use nodemon and gulp-watch together? Nodemon's job is to watch and reload, so why not let nodemon do it all? That's why I made this, and I'd like to be able to pass whatever I need directly into nodemon, but nodemon by itself won't take any kind of stream.

ColemanGariety commented 10 years ago

The first option seems to limit what options you have with nodemon. Some people might want to change the delayTime or use one of the other options nodemon provides.

@poeticninja you'd be able to pass those into line 4 of the first option.

remy commented 10 years ago

Just a heads up, I've noticed that when you require nodemon, it's ignoring SIGINT (i.e. ctrl+c on the command line). I've got a fix that should land today: https://github.com/remy/nodemon/commit/9b3b5099c7e5f16ab32c1f99b7816dea65ace26c#diff-cebf50326ac9e24a94de78bad36e77e1L212 (in 1.0.8)

poeticninja commented 10 years ago

@remy :+1: Thanks, I thought my computer was going crazy.

robrich commented 10 years ago

@JacksonGariety Why did I suggest this? gulp-plugins (and gulp-friendly modules) should do one thing. In this case nodemon does two: watch files and reload stuff. I chose the reloads as the one thing.

hiddentao commented 10 years ago

@robrich You're thought on having it be responsible for just one thing is a good one. Yet the problem here is that when the files do change and nodemon gets run again it doesn't know that it was previously run and therefore doesn't know that the node app is already running, and thus won't shut it down. Therefore, I think that if you're using nodemon with gulp then nodemon should be responsible for watching as well as restarting the app.

ColemanGariety commented 10 years ago

@hiddentao you articulated my point well, thank you.

@robrich @Contra I'm going to build out nodemon like my second example describes above. I'll change the tag to be gulp friendly. Essentially, this will be a wrapper for nodemon that uses streams to control what nodemon does on restart/stop/etc.

ColemanGariety commented 10 years ago

@poeticninja ended up giving the nodemon response two methods: on and emit which take events and gulp task names for ease of use!

poeticninja commented 10 years ago

@JacksonGariety I will try this out either today or tomorrow. Thanks for working on this!

yocontra commented 10 years ago

@JacksonGariety why not return a real event emitter for on and emit?

ColemanGariety commented 10 years ago

@Contra I'd like to be able to pass grunt tasks directly. Any way I can make a real event emitter which does this?

yocontra commented 10 years ago

@JacksonGariety What you're doing currently isn't a good pattern because you end up having gulp as a dependency. People should do .on('whatever', function() { gulp.run('taskname'); }); themselves

yocontra commented 10 years ago

If you just return the script object instead of the pseudo-eventemitter you're already done