所以我有一个应用程序,树是这样的:
- Gemfile
- Guardfile
- source/
- dist/
- app.rb启动服务器的命令是ruby app.rb (或require_relative './app.rb',它做同样的事情)。
我希望运行此命令,并在任何文件更改时重新运行它。
唯一的例外是dist/文件夹-其中的任何文件更改都应该被忽略。
到目前为止,我尝试使用guard和guard-shell (对代码转储表示歉意):
require 'childprocess'
# Global constant tracking whether the app has been started
RunningProcess = {gen_rb: false}
# Method to stop the app if it's been started
def ensure_exited_server
begin
RunningProcess[:gen_rb] && RunningProcess[:gen_rb].poll_for_exit(10)
rescue ChildProcess::TimeoutError
RunningProcess[:gen_rb].stop # tries increasingly harsher methods to kill the process.
end
nil
end
# Start the app using 'child-process'
def start_app
# prevent 'port in use' errors
ensure_exited_server
# The child-process gem starts a process and exposes its stdout
RunningProcess[:gen_rb] = ChildProcess.build("ruby", "gen.rb")
RunningProcess[:gen_rb].io.inherit!
RunningProcess[:gen_rb].start
nil
end
# Always start the app, not just when a file changes.
start_app
# The guard-shell gem runs a block whenever some set of files has changed.
guard :shell do
# This regex matches anything except the dist/ folder
watch /^[^dist\/].+/ do |m|
start_app
# Print a little message when a file changes.
m[0] + " has changed."
end
nil
end
# Make sure the app does not run after guard exits
at_exit { ensure_exited_server }这不会重新启动我的应用程序。
重新运行的问题是我在他们的回购中提出了一个问题:参见https://github.com/alexch/rerun/issues/107
发布于 2016-08-07 20:42:02
像这样的东西给你的卫队档案怎么样?
guard :shell do
watch(%r{^source/.+\.(rb)}) do |m|
`ruby app.rb`
end
watch('app.rb') do |m|
`ruby app.rb`
end
end这个watch没有列出要忽略的目录,而是声明要使用哪些目录/文件。
https://stackoverflow.com/questions/38812964
复制相似问题