module.exports = (grunt) ->
  'use strict'

  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'

    clean:
      dev: src: ['dev/']

    browserify:
      options:
        transform: ['coffeeify'] # <3
        aliasMappings: [
          cwd: 'src/engine/'
          src: ['**/*.coffee']
          dest: 'cgame/'
        ]

      demo:
        src: 'src/game.coffee', dest: 'dev/game.js'
        options: debug: true

    copy:
      index:
        src: 'src/index.html', dest: 'dev/index.html'

    # Clean code is happy code
    coffeelint:
      game: ['src/**/*.coffee']
      grunt: ['Gruntfile.coffee']

    # Refresh anytime we change something
    watch:
      options: livereload: 35729
      rebuild:
        files: ['src/**/*.coffee', 'src/index.html']
        tasks: ['default']

  # plugins
  grunt.loadNpmTasks 'grunt-contrib-copy'
  grunt.loadNpmTasks 'grunt-contrib-clean'
  grunt.loadNpmTasks 'grunt-contrib-watch'
  grunt.loadNpmTasks 'grunt-browserify'
  grunt.loadNpmTasks 'grunt-coffeelint'

  # My tasks
  grunt.registerTask 'lint', ['coffeelint']

  grunt.registerTask 'build:demo', [
    'lint'
    'clean'
    'browserify:demo'
    'copy:index'
  ]

  grunt.registerTask 'default', ['build:demo']

