Skip to content

Instantly share code, notes, and snippets.

@brynbellomy
Created September 12, 2012 14:45
Show Gist options
  • Save brynbellomy/3707114 to your computer and use it in GitHub Desktop.
Save brynbellomy/3707114 to your computer and use it in GitHub Desktop.
Cakefile for simple/small projects
fs = require "fs"
{exec} = require "child_process"
util = require "util"
path = require "path"
require "colors"
appFiles = [ ]
coffeeSubdirs = [ "." ]
exclude = [ ".git", "Cakefile", "node_modules", "_x", "public", "uploads", "views" ]
task "coffeeFiles", ->
traverseFileSystem = (currentPath) ->
files = fs.readdirSync currentPath
for file in files
do (file) ->
currentFile = path.join currentPath, file
if currentFile not in exclude
stats = fs.statSync(currentFile)
if stats.isFile() and currentFile.indexOf(".coffee") > 0 and appFiles.join("=").indexOf("#{currentFile}=") < 0
appFiles.push currentFile
else if stats.isDirectory()
traverseFileSystem currentFile
traverseFileSystem subdir for subdir in coffeeSubdirs
console.log "#{appFiles.length} coffee files found."
console.log (appFiles.join "\n").cyan
return appFiles
task "watch", ->
invoke "build"
util.log "Watching for changes..."
for file in appFiles then do (file) ->
fs.watchFile file, (curr, prev) ->
if +curr.mtime isnt +prev.mtime
util.log "Saw change in #{file}"
console.log "Whoa. Saw a change. Building. Hold plz.".red
invoke "build"
task "build", ->
invoke "coffeeFiles"
appContents = new Array remaining = appFiles.length
for file, index in appFiles then do (file, index) ->
exec "coffee --compile #{file}"
console.log "Build complete.".yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment