Created
September 12, 2012 14:45
-
-
Save brynbellomy/3707114 to your computer and use it in GitHub Desktop.
Cakefile for simple/small projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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