Skip to content

Instantly share code, notes, and snippets.

@scan
Created March 2, 2012 14:02
Show Gist options
  • Save scan/1958549 to your computer and use it in GitHub Desktop.
Save scan/1958549 to your computer and use it in GitHub Desktop.
Cakefile for .coffee -> .julius
fs = require 'fs'
coffee = require 'coffee-script'
option '-f', '--folder [DIR]', 'template directory'
task 'build:all', 'compile all coffee files', (options) ->
dir = options.output or './templates'
console.log "Reading #{dir}"
fs.readdir dir, (err, files) ->
if err? then console.error err else
for file in files then do (file) ->
file = "#{dir}/#{file}"
if file.match /.coffee$/
console.log "Compiling #{file}"
fs.readFile file, (err, code) ->
newname = file.replace /.coffee$/, '.julius'
code = coffee.compile "#{code}"
console.log "Writing to #{newname}"
fs.writeFile newname, code
task 'build', 'compile all', ->
invoke 'build:all'
task 'watch', 'watch for changes', (options) ->
dir = options.output or './templates'
console.log "Watching #{dir}"
fs.readdir dir, (err, files) ->
if err? then console.error err else
for file in files then do (file) ->
file = "#{dir}/#{file}"
fs.watchFile file, (curr, prev) ->
if curr.mtime isnt prev.mtime
console.log "Detected changes in #{file}"
invoke 'build:all'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment