Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (35 sloc) 1.34 KB
fs = require 'fs'
util = require 'util'
{exec} = require 'child_process'
prodSrcCoffeeDir = "src/"
appFiles = [
# omit src/ and .coffee to make the below lines a little shorter
task 'build', 'Build single application file from source files', ->
appContents = new Array remaining = appFiles.length
for file, index in appFiles then do (file, index) ->
fs.readFile "src/#{file}.coffee", 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
process() if --remaining is 0
process = ->
fs.writeFile 'js/', appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec 'coffee --compile js/', (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
fs.unlink 'js/', (err) ->
throw err if err
console.log 'Done.'
task 'watch', 'Watch prod source files and build changes', ->
util.log "Watching for changes in #{prodSrcCoffeeDir}"
for file in appFiles then do (file) ->
fs.watchFile "#{prodSrcCoffeeDir}/#{file}.coffee", (curr, prev) ->
if +curr.mtime isnt +prev.mtime
util.log "Saw change in #{prodSrcCoffeeDir}/#{file}.coffee"
invoke 'build'