Summary
The vision for wake is as a sort of rake/make like program, combined with the real-time filesystem “watching” aspect of autotest/autospec/watchr.
Wake started out (and still is) mostly a fork of the watchr gem at github.com/mynyml/watchr.
The are a number of differences now and they’re expected to grow.
It’s been ported to EventMachine for file-events and has some extensions for how watches can be written.
To install, you can clone the repo (github.com/smparkes/wake) or install the gem, wake
. Note that for now, you’ll need my copy of EventMachine (github.com/smparkes/eventmachine or the smparkes-eventmachine
gem) for directory watches to work well. (These changes are in the process of getting pulled upstream.)
EventMachine
Not much to say. It supports EM as well as Rev, though the Rev stuff will probably be dropped unles there’s a compelling reason to keep it. The default is still Rev. To use EventMachine, after installing the EM gem, I just add
begin; require 'wake/event_handlers/em'; rescue LoadError; end
to my Wakefile
. It’ll use the first required backend, or Rev if none are found (and Rev is installed). There may be better ways to do this.
Event processing extensions
I made several changes to the way events are created/processed, mostly to make my Wakefile
work:
#!/usr/bin/env wake
begin; require 'wake/event_handlers/em'; rescue LoadError; end
watch( %r(.*), :modified, lambda { |md| File.directory? md[0] } ) do |md|
raise Wake::Refresh
end
watch( %r((public/.*)\.haml$), [ :created, :modified ] ) do |md|
cmd = "rm -f #{md[1]}.html && haml -f html5 #{md[0]} #{md[1]}.html && chmod 444 #{md[1]}.html"
puts cmd
system cmd
if $?.signaled? && $?.termsig == 2
Process.kill 2, 0
end
end
watch( %r((spec/.*[Ss]pec)\.(html|js)$), [ :load, :created, :modified ] ) do |md|
cmd = "jazrb #{md[0]}"
puts cmd
system cmd
if $?.signaled? && $?.termsig == 2
Process.kill 2, 0
end
end
The purpose of the first watch is to cause wake to refresh when directories change. This allows new files to be picked up. The watch pattern matches all files in the current directory tree (though not .
itself; probably should), and watches for :modified
events. It adds an extra lambda that is processed while looking at file paths: only directories will get watches put on them. (Otherwise %r(.*)
would put watches on every file/directory in the tree, which seems kinda bad.)
The second watch looks for Haml files in my public directory and automatically converts them to HTML. These are static files, not served by an app server like Rails: even with static files, I hate writing raw HTML. The extension here is so that instead of a single event type, I can pass an array. In addition to the :modified
, event, this will get called when wake notes that a new file of this type has appeared. (Note this works starting from wake’s first pass; files created while wake wasn’t running don’t count).
Then final watch looks for JavaScript and HTML spec files and runs them under jazrb (see github.com/smparkes/jazrb if interested). This case is similar to the previous but also adds the :load
event. This event gets fired the first time a file is seen after wake starts. This allows wake to run all the specs when first started, similar to what autotest does.
Recent Changes
-
POC for batch events that occur within a time window
-
Pass event type to callbacks
-
Has some POC dependency detection. Needs to be formalized into an API and have a better backend.
Things to do
-
Move directory watch into wake itself
-
Handle user interrupt processing more systematically
-
Don’t swallow config file error messages, particularly on reload. Is this still happening?
-
Integrate with rake/make.