我有一个 Guard 设置(对文件系统事件做出反应的 Ruby gem - https://github.com/guard/),它将咖啡文件编译为 Javascript,并在更改相关 js 文件时重新启动 node.js 服务器。
这是我的项目目录中的 Guardfile:
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'
当我更改相关的 .coffee 文件(以便更新 server/js/ 文件)时,进程会重新启动两次。手动修改 server/js/*.js 文件并且它只重新启动一次(如预期的那样)让我相信它出于某种原因执行了两次。
这是使用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
我对 Ruby 的了解是有限的,所以虽然我已经阅读了常见问题解答、示例、wikis、rubydocs,但我仍然一无所知。似乎在第一次匹配之后规则级联然后再次应用。
我的期望是这样的:
- 在我的编辑器中更新文件并保存 server/coffee/app.coffee
- Guard 识别到这一点并且 Guard-Coffeescript 插件覆盖 server/js/app.js
- Guard 识别到 server/js/app.js 已更改并且 Guard-Process 重新启动节点服务器。
谁能帮我解决这个小烦恼或告诉我 Guard 如何处理我的 Guardfile/FS 事件?
这是在 Mac OX Lion 上使用新的 Ruby 1.9(通过 Homebrew 安装)、最新的 Guard 和插件,包括 fs 事件 gem。