Skip to content

Instantly share code, notes, and snippets.

@datapimp
Created October 20, 2011 16:22
Show Gist options
  • Save datapimp/1301586 to your computer and use it in GitHub Desktop.
Save datapimp/1301586 to your computer and use it in GitHub Desktop.
Cakefile for watching src, compiling coffee to lib, handling sass etc
{spawn, exec} = require 'child_process'
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
async = require "async"
fs = require "fs"
path = require "fs"
_ = require "underscore"
stdout_handler = (data)->
console.log data.toString().trim()
build = (watch)->
console.log "Watching coffee scripts"
options = ['-c', '-o', 'lib', 'src']
app_options = ['-c', '-o', 'public/javascripts/application', 'client']
if watch is true
options[0] = '-cw'
app_options[0] = '-cw'
coffee = spawn 'coffee', options
app = spawn 'coffee', app_options
coffee.stdout.on 'data', stdout_handler
app.stdout.on 'data', stdout_handler
style = (watch)->
console.log "Watching stylesheets"
options = ['--update', 'stylesheets:public/stylesheets']
if watch is true
options[0] = "--watch"
sass = spawn 'sass', options
sass.stdout.on 'data', (data)-> stdout_handler
sass.stderr.on "data", (data)-> stdout_handler
buildTemplates = (callback) ->
eco = require 'eco'
compile = (name) ->
(callback) ->
fs.readFile "templates/#{name}.eco", "utf8", (err, data) ->
if err then callback err
else fs.writeFile "lib/templates/#{name}.js", eco.compile(data), callback
async.parallel [
compile("sample")
], callback
task 'templates', ->
buildTemplates()
task 'style', (watch)->
style watch
task 'build', 'build the project', (watch)->
build watch
task 'watch', 'watch for changes and rebuild', ->
build true
style true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment