Add a cake watch
task
This commit is contained in:
parent
761d2040f5
commit
f444fb9e38
1 changed files with 12 additions and 3 deletions
15
Cakefile
15
Cakefile
|
@ -15,15 +15,24 @@ run = (cmd, args, cb) ->
|
||||||
process.exit(1) if status != 0
|
process.exit(1) if status != 0
|
||||||
cb() if typeof cb is 'function'
|
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`.
|
# Build Chosen. Requires `coffee` and `uglifyjs`.
|
||||||
#
|
#
|
||||||
task 'build', 'build Chosen from source', build = (cb) ->
|
task 'build', 'build Chosen from source', build = (cb) ->
|
||||||
files = fs.readdirSync 'coffee'
|
run 'coffee', ['-c', '-o', 'chosen'].concat(coffescript_files()), ->
|
||||||
files = ('coffee/' + file for file in files when file.match(/\.coffee$/))
|
|
||||||
run 'coffee', ['-c', '-o', 'chosen'].concat(files), ->
|
|
||||||
cb() if typeof cb is 'function'
|
cb() if typeof cb is 'function'
|
||||||
unless process.env.MINIFY is 'false'
|
unless process.env.MINIFY is 'false'
|
||||||
for javascript in javascripts
|
for javascript in javascripts
|
||||||
uglified = javascript.replace /\.js$/, '.min.js'
|
uglified = javascript.replace /\.js$/, '.min.js'
|
||||||
run 'uglifyjs', ['-o', uglified, javascript], cb
|
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'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue