开发者

Ruby GuardFile - Why does the process restart twice

I have a Guard setup (Ruby gem that reacts to filesystem events - https://github.com/guard/) that compiles coffee files to Javascript and also restarts the node.js server on changes to relevant js files.

Here is my Guardfile from my project directory:

guard 'process',
  :name => 'SPCRM Server',
  :command => 'node --debug server/js/app.js' do
    watch(%r{^server/js/.+\.js$})
  end

guard 'coffeescript',
  :input => 'app/coffee',
  :output => 'app/js'

guard 'coffeescript',
  :input => 'server/coffee',
  :output => 'server/js'

When I change a relevant .coffee file (so 开发者_如何学编程that a server/js/ file is updated) the process is restarted twice. Modifying by hand a server/js/*.js file and it is only restarting once (as expected) leading me to believe it does two passes for some reason.

Here is the output running with guard -d

debugger listening on port 5858DEBUG (19:30:26): Guard::CoffeeScript#run_on_change with ["server/coffee/app.coffee"]
DEBUG (19:30:26): Hook :run_on_change_begin executed for Guard::CoffeeScript
DEBUG (19:30:26): Command execution: command -v nodejs 2>/dev/null
DEBUG (19:30:26): Command execution: command -v node 2>/dev/null
DEBUG (19:30:26): Command execution: command -v /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc 2>/dev/null
DEBUG (19:30:26): Command execution: command -v js 2>/dev/null
DEBUG (19:30:26): Command execution: command -v cscript 2>/dev/null
Compile server/coffee/app.coffee
Successfully generated server/js/app.js
Stopping process SPCRM Server
Stopped process SPCRM Server
Starting process SPCRM Server
Started process SPCRM Server
DEBUG (19:30:27): Hook :run_on_change_end executed for Guard::CoffeeScript
DEBUG (19:30:27): Guard::Process#run_on_change with ["server"]
DEBUG (19:30:27): Hook :run_on_change_begin executed for Guard::Process
Stopping process SPCRM Server
Stopped process SPCRM Server
Starting process SPCRM Server
Started process SPCRM Server
DEBUG (19:30:27): Hook :run_on_change_end executed for Guard::Process
debugger listening on port 5858

My knowledge of Ruby is limited so whilst I have read the FAQs, examples, wikis, rubydocs I still none the wiser. It would seem that after the first match the rules cascade and then are applied again.

My expectation would be this:

  1. Update file in my editor and save server/coffee/app.coffee
  2. Guard recognizes this and the Guard-Coffeescript plugin overwrites server/js/app.js
  3. Guard recognizes server/js/app.js has changed and Guard-Process restarts node server.

Can anyone help me solve this minor annoyance or enlighten me on how Guard is processing my Guardfile/FS events?

This is using fresh Ruby 1.9 (installed via Homebrew), latest Guard and plugins, including the fs event gem, on Mac OX Lion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜