首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法重新运行我的应用程序与警卫或重新运行

无法重新运行我的应用程序与警卫或重新运行
EN

Stack Overflow用户
提问于 2016-08-07 09:55:56
回答 1查看 180关注 0票数 1

所以我有一个应用程序,树是这样的:

代码语言:javascript
复制
- Gemfile
- Guardfile
- source/
- dist/
- app.rb

启动服务器的命令是ruby app.rb (或require_relative './app.rb',它做同样的事情)。

我希望运行此命令,并在任何文件更改时重新运行它。

唯一的例外是dist/文件夹-其中的任何文件更改都应该被忽略。

到目前为止,我尝试使用guardguard-shell (对代码转储表示歉意):

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-07 20:42:02

像这样的东西给你的卫队档案怎么样?

代码语言:javascript
复制
guard :shell do
  watch(%r{^source/.+\.(rb)}) do |m|
    `ruby app.rb`
  end

  watch('app.rb') do |m|
    `ruby app.rb`
  end
end

这个watch没有列出要忽略的目录,而是声明要使用哪些目录/文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38812964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档