 INSTALL_DIR = path.join('/Applications', APP_NAME)
 
 module.exports = (grunt) ->
+  exec = (command, args, options, callback) ->
+    if _.isFunction(options)
+      callback = options
+      options = undefined
+
+    spawned = spawn(command, args, options)
+    stdoutChunks = []
+    spawned.stdout.on 'data', (data) -> stdoutChunks.push(data)
+    stderrChunks = []
+    spawned.stderr.on 'data', (data) -> stderrChunks.push(data)
+    spawned.on 'close', (code) ->
+      if code is 0
+        callback(null, Buffer.concat(stdoutChunks).toString())
+      else if stderrChunks.length > 0
+        error = Buffer.concat(stderrChunks).toString()
+        grunt.log.error(error)
+        callback(error)
+      else
+        grunt.log.error(error)
+        callback("`#{command}` Failed with code: #{code}")
+
   cp = (source, destination, {filter}={}) ->
     if grunt.file.isDir(source)
       grunt.file.recurse source, (sourcePath, rootDirectory, subDirectory='', filename) ->

    cp 'static', path.join(APP_DIR, 'static'), filter: /.+\.less$/
    cp 'themes', path.join(APP_DIR, 'themes'), filter: /.+\.(cson|less)$/

    grunt.task.run('compile')

  grunt.registerTask 'install', 'Install the built application', ->
    rm INSTALL_DIR

{spawn} = require 'child_process'
fs = require 'fs'
path = require 'path'
_ = require 'underscore'
