fs = require 'fs' path = require 'path' {spawn, exec} = require 'child_process' ncp = (require 'ncp').ncp TARGET = 'js' SOURCE = 'coffee' build = (source, target) -> ### # Build sources directory. ### exec "coffee -c --no-header -o #{target} #{source}", (err, stdout, stderr) -> if err then console.err stderr.trim() else done source, target done = (source, target) -> ### # Show ok message and append to manifest file ### console.log "#{source}: successfully built in #{target}" delete_recursive = (target) -> ### # Delete directory or file recursively ### if not fs.existsSync target return if (fs.lstatSync target).isDirectory() files = fs.readdirSync target delete_recursive path.join target, f for f in files fs.rmdirSync target console.log "#{target}: Deleted on clean" else fs.unlinkSync target console.log "#{target}: Deleted on clean" copy_recursive = (source, target) -> ### # Copy directory recursively ### console.log "" console.log "COMPILING..." console.log "" target_dir = path.dirname target if not fs.existsSync target_dir fs.mkdirSync target_dir ncp source, target, (err)-> if err then console.error err else done source, target task 'build', 'Build coffeescript to javascript', (opt)-> # Compile code folders for source in ['lib', 'test', 'routes', 'views'] target = path.join TARGET, source source = path.join SOURCE, source build source, target # Compile standalone files for source in ['server.coffee'] source = path.join SOURCE, source build source, TARGET # Dump static folders for source in ['views'] target = path.join TARGET, source source = path.join SOURCE, source copy_recursive source, target task 'clean', 'Remove last build', (opt)-> ### # Remove all in Manifest file and the file itself ### console.log "" console.log "CLEANING DIRECTORY..." console.log "" delete_recursive TARGET