module.exports = function(grunt) {
  grunt.initConfig({
    pdflatex: {
      options: {
        executable: "pdflatex"
      },
      thesis: {
        files: [{
          src: "main.tex"
        }]
      }
    },
    watch: {
      thesis: {
        files: ['*.tex', '*.cls'],
        tasks: [
          'pdflatex:main',
          'pdflatex:main',
          'bibtex:main',
          'pdflatex:main',
          'pdflatex:main',
          'wordcount:main'
        ],
        options: {
          spawn: false,
        },
      }
    },
    glossaries: {
      thesis: {
        files: [{
          src: ['*.glo', '*.acn']
        }]
      }
    },
    wordcount: {
      thesis: {
        files: [{
          src: '*.tex'
        }]
      }
    },
    bibtex: {
      options: {
        executable: "bibtex"
      },
      thesis: {
        files: [{
          src: "main.aux"
        }]
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-tex-pdflatex');
  grunt.loadNpmTasks('grunt-tex-bibtex');
  grunt.loadNpmTasks('grunt-tex-wordcount');

  grunt.registerTask('build', [
    'pdflatex:main',
    'pdflatex:main',
    'bibtex:main',
    'pdflatex:main',
    'pdflatex:main',
    'wordcount:main'
  ]);

  grunt.registerTask('default', [
    'pdflatex:main',
    'pdflatex:main',
    'bibtex:main',
    'pdflatex:main',
    'pdflatex:main',
    'wordcount:main',
    'watch:main'
  ]);
};