【问题标题】:How to make Guard watch files in a subdirectory如何在子目录中制作 Guard 监视文件
【发布时间】:2013-08-31 21:10:51
【问题描述】:

我正在尝试让 Guard 将我的 CoffeeScript 文件编译为 JS 文件,然后让 Juicer 合并并缩小它们。我使用tmp 目录来存储中间JS 文件。据我了解,这应该有效,但它没有:

guard :coffeescript, :input => "src/coffee", :output => "tmp"

guard :shell do
    watch %r{^tmp/.+\.js$} do
        system 'juicer', 'merge', 'tmp/app.js', '-sfo', 'js/app.js'
    end
end

CoffeeScript 文件每次被触摸时都会被正确编译到 tmp 目录中,但随后 shell 守卫不会触发。

使用--debug 启动保护并手动更改tmp 中的一个JS 文件,我在终端中没有得到任何调试行。这些文件似乎没有被监控。

$ guard --debug
18:53:51 - DEBUG - Command execution: which notify-send
18:53:51 - DEBUG - Command execution: emacsclient --eval '1' 2> /dev/null || echo 'N/A'
18:53:51 - INFO - Guard is using TerminalTitle to send notifications.
18:53:51 - DEBUG - Command execution: hash stty
18:53:51 - DEBUG - Guard starts all plugins
18:53:51 - DEBUG - Hook :start_begin executed for Guard::CoffeeScript
18:53:51 - DEBUG - Hook :start_end executed for Guard::CoffeeScript
18:53:51 - DEBUG - Hook :start_begin executed for Guard::Shell
18:53:51 - DEBUG - Hook :start_end executed for Guard::Shell
18:53:51 - INFO - Guard is now watching at '/home/tobia/my_project'
18:53:51 - DEBUG - Start interactor
[1] guard(main)> 

^^^ 如果我此时修改/home/tobia/my_project/tmp 中的JS文件,则没有任何反应。

我正在使用来自 Debian stable 的 Ruby 1.9.1、Guard 1.8.2 和 Guard-shell 0.5.1 并安装了sudo gem install

【问题讨论】:

  • 尽量减少正则表达式的限制,例如%r{tmp/.+\.js$}
  • 试过%r{tmp/.+\.js},还是没有。我应该告诉 Guard 以某种方式“监视” tmp 目录吗?我只是手动修改了一个js文件,Guard什么都没有打印出来。

标签: ruby coffeescript guard


【解决方案1】:

经过一番调查,我意识到tmp 在默认的ignore 列表中,所以这就是Guard 不会从生成的JavaScript 文件中获取更改的原因。要解决此问题,您可以...

1。从忽略的目录列表中删除 tmp

ignore! /.git/

guard :coffeescript, :input => "src/coffee", :output => "tmp"

guard :shell do
  watch %r{^tmp/.+\.js$} do
    system 'juicer', 'merge', 'tmp/app.js', '-sfo', 'js/app.js'
  end
end

2。将 JavaScript 编译到不同的目录

guard :coffeescript, :input => "src/coffee", :output => "src/js"

guard :shell do
  watch %r{^src/.+\.js$} do
    system 'juicer', 'merge', 'tmp/app.js', '-sfo', 'js/app.js'
  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 2013-07-29
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多