module.exports = (grunt) ->

  grunt.initConfig({
    browserify: {
      admin: {
        bundleOptions: {
          debug: true
        }
        src: 'core/scripts/admin/app.coffee'
        dest: 'core/static/js/admin.js'
      }
    }
    clean: {
      build: ['core/static/js/**/*', '!core/static/js/lib/**']
    }
    concurrent: {
      dev: {
        options: {
          logConcurrentOutput: true
        }
        tasks: [
          'nodemon'
          'watch'
        ]
      }
    }
    env: {
      dev: {src: "./ENV.json"}
    }
    less: {
      dev: {
        files: {
          'core/static/css/main.css': 'core/styles/main.less'
        }
      }
    }
    nodemon: {
      dev: {
        script: 'core/app.coffee'
        options: {
          env: require('./ENV.json')
          ext: 'js,coffee,jade'
          watch: ['core', 'models', '**/*', '!core/scripts/**']
        }
      }
    }
    uglify: {
      dev: {
        files: {
          'core/static/js/admin.js': ['core/static/js/admin.js']
        }
      }
    }
    watch: {
      options: {
        livereload: 8007
      }
      browserify: {
        files: [
          'core/scripts/**/*.coffee'
          'core/scripts/**/*.tag'
        ]
        tasks: ['browserify']
      }
    }
  })

  grunt.loadNpmTasks('grunt-browserify')
  grunt.loadNpmTasks('grunt-concurrent')
  grunt.loadNpmTasks('grunt-contrib-clean')
  grunt.loadNpmTasks('grunt-contrib-less')
  grunt.loadNpmTasks('grunt-contrib-uglify')
  grunt.loadNpmTasks('grunt-contrib-watch')
  grunt.loadNpmTasks('grunt-env')
  grunt.loadNpmTasks('grunt-nodemon')

  grunt.registerTask('default', [
    'clean'
    'env:dev'
    'less'
    'browserify'
    'concurrent'
  ])