Skip to content

Instantly share code, notes, and snippets.

@edom18
Last active December 14, 2015 01:59
Show Gist options
  • Save edom18/5010285 to your computer and use it in GitHub Desktop.
Save edom18/5010285 to your computer and use it in GitHub Desktop.
This is a Cakefile by coffee script to watch and compile cofee scripts.
{spawn, exec} = require 'child_process'
option '-o', '--output [DIR]', 'Output directory.'
option '-t', '--target [DIR]', 'Watch target directory.'
stdout_handler = (data) ->
console.log data.toString().trim()
build = (watch, output = 'js', target = '_src/coffee') ->
console.log 'Watching coffee scripts'
console.log "Watch to #{target}"
options = ['-cb', '-o', output, target]
if watch is true
options[0] = '-cbw'
coffee = spawn 'coffee', options
coffee.stdout.on 'data', stdout_handler
style = (watch) ->
console.log 'Watching compass files.'
options = ['compile']
if watch is true
options = ['watch', './']
compass = spawn 'compass', options
compass.stdout.on 'data', (data) -> stdout_handler
compass.stderr.on 'data', (data) -> stdout_handler
task 'build', 'build the project', (watch) ->
build watch
task 'watch', 'watch for changes and rebuild', (options) ->
build true, options.output, options.target
style true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment