Skip to content

Instantly share code, notes, and snippets.

@ctrochalakis
Created April 30, 2010 12:35
Show Gist options
  • Save ctrochalakis/385125 to your computer and use it in GitHub Desktop.
Save ctrochalakis/385125 to your computer and use it in GitHub Desktop.
Watching and compiling coffee scripts
# Coffe Blender for your coffee scripts
# It watches coffee for changes and compiles
# ======
# coffee --no-wrap -c watcher.coffee # Compile it, onetime
#
# Now you can eiher supply the files from the command line:
# node watcher.js my_file.coffee
# or pass them through stdin:
# find . | grep coffee$| node watcher.js -
# git ls-files | grep coffee$| node watcher.js -
puts: require('sys').puts
exec: require('child_process').exec
watch: require('fs').watchFile
blend: (filename) ->
exec "coffee --no-wrap -c $filename", (err, stderr, stdout) ->
puts(if err then "! $stdout" else "= Blended $filename")
register: (file) ->
puts "+ Registering $file"
blend file
watch file, (curr, prev) ->
blend file
args: process.argv[2...process.argv.length]
if args[0] == '-'
files: []
stdin: process.openStdin()
stdin.addListener 'data', (chunk) ->
data: chunk.toString('ascii')
files.push(file) for file in data.split('\n') when file isnt ''
stdin.addListener 'end', ->
register file for file in files
else
files: args
register file for file in files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment