Created
March 2, 2012 14:02
-
-
Save scan/1958549 to your computer and use it in GitHub Desktop.
Cakefile for .coffee -> .julius
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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