Skip to content

Instantly share code, notes, and snippets.

@Takazudo
Created February 17, 2012 18:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Takazudo/1854692 to your computer and use it in GitHub Desktop.
Save Takazudo/1854692 to your computer and use it in GitHub Desktop.
Cakefile to concatenate, minify coffee
# ==================================================================
# Cakefile - compile, concatenate, minify coffee
# ==================================================================
# ├─ Cakefile
# ├─ lib
# │   ├─ all.js
# │   └─ all.min.js
# └─ src
# ├─ fuga.coffee
# └─ hoge.coffee
fs = require 'fs'
{exec, spawn} = require 'child_process'
# order of files in `inFiles` is important
config =
srcDir: 'src'
outDir: 'lib'
inFiles: [
'hoge'
'fuga'
]
outFile: 'all'
yuic: 'yuicompressor'
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
# 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 "#{config.yuic} #{outJS}.js -o #{outJS}.min.js", exerr
task 'bam', 'build and minify', ->
invoke 'build'
invoke 'min'
task 'wam', 'watch and compile changes in source dir', ->
watch = exec "coffee -j #{outJS}.js -cw #{strFiles}"
watch.stdout.on 'data', (data)->
invoke 'min'
process.stdout.write data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment