Created
December 30, 2011 01:44
-
-
Save jrmoran/1537200 to your computer and use it in GitHub Desktop.
Cakefile to document, compile, join and minify CoffeeScript files for client side apps.
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
# Cakefile to document, compile, join and minify CoffeeScript files for | |
# client side apps. Just edit the config object literal. | |
# | |
# -jrmoran | |
fs = require 'fs' | |
{exec, spawn} = require 'child_process' | |
# order of files in `inFiles` is important | |
config = | |
srcDir: 'coffee' | |
outDir: 'js' | |
inFiles: [ 'color', 'imageCanvas', 'app' ] | |
outFile: 'client' | |
yuic: '~/Dropbox/toolbox/dotfiles/bin/yuicompressor-2.4.2.jar' | |
outJS = "#{config.outDir}/#{config.outFile}" | |
strFiles = ("#{config.srcDir}/#{file}.coffee" for file in config.inFiles).join ' ' | |
# deal with errors from child processes | |
exerr = (err, sout, serr)-> | |
process.stdout.write err if err | |
process.stdout.write sout if sout | |
process.stdout.write serr if serr | |
task 'doc', 'generate documentation for *.coffee files', -> | |
exec "docco #{config.srcDir}/*.coffee", exerr | |
# this will keep the non-minified compiled and joined file updated as files in | |
# `inFile` change. | |
task 'watch', 'watch and compile changes in source dir', -> | |
watch = exec "coffee -j #{outJS}.js -cw #{strFiles}" | |
watch.stdout.on 'data', (data)-> process.stdout.write data | |
task 'build', 'join and compile *.coffee files', -> | |
exec "coffee -j #{outJS}.js -c #{strFiles}", exerr | |
task 'min', 'minify compiled *.js file', -> | |
exec "java -jar #{config.yuic} #{outJS}.js -o #{outJS}.min.js", exerr | |
task 'bam', 'build and minify', -> | |
invoke 'build' | |
invoke 'min' | |
task 'test', 'runs jasmine tests', -> | |
exec 'jasmine-node --coffee --verbose spec', exerr | |
# watch files and run tests automatically | |
task 'watch:test', 'watch and run tests', -> | |
console.log 'watching...' | |
whenChanged = (filename, fun)-> | |
fs.watchFile filename, (curr, prev)-> | |
fun() if curr.mtime > prev.mtime | |
for f in config.inFiles | |
whenChanged "#{f}.coffee", -> | |
console.log "===== TEST #{new Date().toLocaleString()} =====" | |
invoke 'test' | |
Thank you! I'm using this with a bash script to watch my current directory for changes:
while true; do
new=$(find "coffee/" \
-not \( -type f -name ".?*" -prune \) \
-print0 2>/dev/null | xargs -0 stat -f "%m %z %N")
if [ "$new" != "$old" ]; then
cake bam
old=$new
fi
sleep 1
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a nice piece of work :) Thank you, I'm basing my first Cakefile on this one.