module.exports = (grunt) ->
  grunt.initConfig

    clean:
      all:
        options:
          force: true
        src: 'este/**/*.{js,css}'

    coffee:
      all:
        options:
          bare: true
        files: [
          expand: true
          src: 'este/**/*.coffee'
          ext: '.js'
        ]

    coffee2closure:
      all:
        files: [
          expand: true
          src: 'este/**/*.coffee'
          ext: '.js'
        ]

    esteTemplates:
      all:
        src: 'este/**/*.soy'

    esteDeps:
      all:
        options:
          outputFile: 'build/deps.js'
          prefix: '../../../../'
          root: [
            'node_modules/google-closure-library'
            'este'
          ]

    esteUnitTests:
      app:
        options:
          depsPath: '<%= esteDeps.all.options.outputFile %>'
          prefix: '<%= esteDeps.all.options.prefix %>'
        src: 'este/**/*_test.js'

    esteBuilder:
      options:
        root: '<%= esteDeps.all.options.root %>'
        depsPath: '<%= esteDeps.all.options.outputFile %>'
        compilerFlags: [
          # You will love advanced compilation with verbose warning level.
          '--output_wrapper="(function(){%output%})();"'
          '--compilation_level="ADVANCED_OPTIMIZATIONS"'
          '--warning_level="VERBOSE"'
          # Remove code for ancient browsers (IE<8, very old Gecko/Webkit).
          '--define=goog.net.XmlHttp.ASSUME_NATIVE_XHR=true'
          '--define=este.json.SUPPORTS_NATIVE_JSON=true'
          '--define=goog.style.GET_BOUNDING_CLIENT_RECT_ALWAYS_EXISTS=true'
          '--define=goog.DEBUG=false'
          # Externs. They allow us to use thirdparty code without [] syntax.
          '--externs=externs/react.js'
          '--externs=externs/socketio.js'
        ]

      all:
        options:
          namespace: '*'
          outputFilePath: 'build/all.js'

    bump:
      options:
        commitFiles: ['-a']
        files: ['package.json', 'bower.json']
        pushTo: 'origin'
        tagName: '%VERSION%'

  grunt.loadNpmTasks 'grunt-bump'
  grunt.loadNpmTasks 'grunt-contrib-clean'
  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-este-oldschool'
  grunt.loadNpmTasks 'grunt-npm'

  grunt.registerTask 'test', ->
    grunt.task.run [
      'clean'
      'coffee'
      'coffee2closure'
      'esteDeps'
      #'esteUnitTests'
      'esteBuilder'
    ]