Created
March 10, 2014 05:21
-
-
Save zaius/9459903 to your computer and use it in GitHub Desktop.
Broccoli runner
This file contains 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' | |
util = require 'util' | |
{spawn} = require 'child_process' | |
steps = [] | |
# NOTE: can't use console to output as it's buffered. | |
log = (args...) -> | |
out = process.stdout.write args.join(' ') + '\n' | |
log "Starting... Ctrl-C to quit." | |
run = (cmd, callback) -> | |
process.stdout.write "Running: ", cmd | |
cmd = cmd.split() | |
proc = spawn cmd.shift(), cmd, stdio: 'inherit' | |
proc.on 'close', (code) -> | |
unless code == 0 | |
log "error running #{cmd}" | |
process.exit 1 | |
callback() | |
# Kick off the server | |
args = process.argv.slice(1) | |
args[0] = "build.js.coffee" | |
child = null | |
restart = => | |
if child | |
log "Build code changed. Killing child." | |
child.kill() | |
child.on 'exit', -> | |
restart() | |
else | |
log "Starting builder" | |
child = spawn 'coffee', args, stdio: 'inherit' | |
child.on 'exit', -> | |
child = null | |
restart() | |
# Restart on changes | |
fs.watchFile 'package.json', -> | |
run 'npm install', restart | |
fs.watchFile 'bower.json', -> | |
run 'bower install', restart | |
fs.watchFile 'Brocfile.js.coffee', -> | |
restart() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment