Search code examples
javascriptrubynode.jscoffeescriptguard

How do I get Guard to automatically compile my Coffeescript file? Says it is but it's not


I have the following Guardfile

coffeescript_options = {
 input: 'src/js',
 output: 'www/js',
 patterns: [%r{^src/js/(.+\.(?:coffee|coffee\.md|litcoffee|js))$}]
}

guard 'coffeescript', :input => 'src/js', :output => 'www/js' do
  coffeescript_options[:patterns].each { |pattern| watch(pattern) }
end

# guard 'coffeescript', :input => 'src/js', :output => 'www/js'

I save the src/js/tf.coffee file and it logs this

02:46:50 - INFO - Compile src/js/tf.coffee
02:46:50 - INFO - 02:46:50 AM Successfully generated
←]2;[CoffeeScript results] Successfully generated

However, I can't find the file anywhere.

$ find . -name tf.js
$ ls www/js
app.js

It works for HAML. This is a Ruby app, not Rails. (PhoneGap actually.) I tried the commented line in the Guardfile and it did not recognize changes to the file. I'm on Windows 8.1. I have Node v5.4.0 installed. I can run coffee -o www/js src/js/tf.coffee and it generates the JS file OK.

Docs: https://github.com/netzpirat/guard-coffeescript


Solution

  • Oops, I had to change the guard line to

    guard 'coffeescript', coffeescript_options do
    

    I had changed it to try to simplify it, but forgot to change it back. Still not sure why the commented out line doesn't work though.