Skip to content

Instantly share code, notes, and snippets.

@apcomplete
Created October 10, 2012 16:17
Show Gist options
  • Save apcomplete/3866655 to your computer and use it in GitHub Desktop.
Save apcomplete/3866655 to your computer and use it in GitHub Desktop.
Cake watch file
fs = require 'fs'
{exec} = require 'child_process'
util = require 'util'
appFiles = [
{
destination: "path/to/public/scripts/",
join: true
output: "application.js"
files: [
#path/to/files
]
},
{
destination: "path/to/public/scripts/",
bare: true
files: [
#path/to/files
]
},
]
build = (f) ->
if f.join
scripts = []
for x in f.files
if fs.lstatSync(x).isDirectory()
scripts.push "#{x}/*.coffee"
else
scripts.push x
cmd = "coffee -#{if f.bare then 'b' else ''}o #{f.destination} --join #{f.output} --compile " + scripts.join ' '
else
cmd = "coffee -c#{if f.bare then 'b' else ''}o #{f.destination} " + f.files.join(' ')
exec cmd, (err, stdout, stderr) ->
if err
util.log 'Error compiling coffee file.'
else
util.log 'Done building coffee file.'
task 'watch', 'Watch prod source files and build changes', ->
util.log "Watching for changes in src"
for x in appFiles
for file in x.files then do (file) ->
fs.watchFile file, (curr, prev) ->
if +curr.mtime isnt +prev.mtime
util.log "Saw change in #{file}"
for group in appFiles
for f in group.files
if f is file
build group
task 'build', 'Build single application file from source files', () ->
build g for g in appFiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment