Add a `cake watch` task

abstract-chosen
Matthew Beale 2011-07-29 09:36:22 +02:00
parent 761d2040f5
commit f444fb9e38
1 changed files with 12 additions and 3 deletions

View File

@ -15,15 +15,24 @@ run = (cmd, args, cb) ->
process.exit(1) if status != 0
cb() if typeof cb is 'function'
coffescript_files = ->
'coffee/' + file for file in (fs.readdirSync 'coffee') when file.match(/\.coffee$/)
# Build Chosen. Requires `coffee` and `uglifyjs`.
#
task 'build', 'build Chosen from source', build = (cb) ->
files = fs.readdirSync 'coffee'
files = ('coffee/' + file for file in files when file.match(/\.coffee$/))
run 'coffee', ['-c', '-o', 'chosen'].concat(files), ->
run 'coffee', ['-c', '-o', 'chosen'].concat(coffescript_files()), ->
cb() if typeof cb is 'function'
unless process.env.MINIFY is 'false'
for javascript in javascripts
uglified = javascript.replace /\.js$/, '.min.js'
run 'uglifyjs', ['-o', uglified, javascript], cb
task 'watch', 'watch coffee/ for changes and build Chosen', ->
console.log "Watching for changes in coffee/"
for file in coffescript_files()
fs.watchFile file, (curr, prev) ->
if +curr.mtime isnt +prev.mtime
console.log "Saw change in #{file}"
invoke 'build'