         resolve()
     ).then( ->
       grunt.log.writeln 'migrating...'
-      exec_promise cp.exec, 'python3 manage.py migrate', null
+      execPromise cp.exec, 'python3 manage.py migrate', null
     ).then( ->
       grunt.log.writeln 'loading sample data...'
-      exec_promise cp.exec, 'python3 manage.py loaddata courses', null
+      execPromise cp.exec, 'python3 manage.py loaddata courses', null
     ).then( ->
       done()
     ).catch((error) ->

cp = require 'child_process'
path = require 'path'


lazyCopyFile = (source, target, callback) ->
  if fs.existsSync target
    tstat = fs.statSync target
    sstat = fs.statSync source
    if tstat.mtime.value < sstat.mtime.value
      reader = fs.createReadStream source
      writer = fs.createWriteStream target
      writer.on 'close', callback
      writer.on 'error', callback
      reader.pipe writer
      return
  callback()

exec_promise = (func, args...) ->
  new Promise((resolve, reject) ->
    nargs = args.concat( (errors...) ->
      if errors[0] == null

    func.apply null, nargs
  )

lazyCopyFile = (source, target, callback) ->
  if fs.existsSync target
    tstat = fs.statSync target
    sstat = fs.statSync source
    if tstat.mtime.value >= sstat.mtime.value
      callback()
      return
  reader = fs.createReadStream source
  writer = fs.createWriteStream target
  writer.on 'close', callback
  writer.on 'error', callback
  reader.pipe writer


mkTree = (p) ->
  grunt.log.writeln p.split(path.sep)
  p.split(path.sep).reduce (prev, curr) ->
      n = path.normalize(path.join(prev, curr))
      if not fs.existsSync n
        fs.mkdirSync n
      n
    , '.'


module.exports = (grunt) ->
  grunt.initConfig
    bower:
      relocate:
        base: 'bower_components'
        target: 'src/static/vendor/js'
        files: [
          ['jquery/dist/jquery.min.js', 'jquery.min.js'],
          ['foundation/js/foundation.min.js', 'foundation.min.js'],
