grunt.registerTask('getEvents', function(){ var http = require('https'); var cheerio = require('cheerio'); var fs = require('fs'); var url = 'https://wiki.phpbb.com/Event_List'; var done = this.async(); var dom = http.get(url, function(response){ var srcContents = ''; //another chunk of data has been recieved, so append it to `str` response.on('data', function (chunk) { srcContents += chunk; }); //the whole response has been recieved, so we just print it out here response.on('end', function () { var $ = cheerio.load(srcContents,{lowerCaseAttributeNames:false}); var objects = []; // grunt.log.writeln(srcContents); $($('table.zebra.sortable')[1]).find('tr') .map(function(index, item){ var id = $(item).find('td:first-child a').text(); var added = $(item).find('td:nth-child(4)').text(); var location = $(item).find('td:nth-child(2)').text(); objects.push({'id': id, 'added': added, 'location': location}); }); fs.writeFile('events.json', JSON.stringify(objects), function (err) { if (err) return console.log(err); console.log('Events successfully saved and updated with ' +objects.length + 'items'); done(); }); }); }).end(); }); grunt.registerTask('checkEvents', function(){ var path = require('path'); var fs = require('fs'); var src = ['template/*.html']; var events = grunt.file.readJSON('./events.json'); grunt.file.expand(src).forEach(function(f){ var srcContents = grunt.file.read(f); events.map(function(event){ if(srcContents.indexOf(event.id) != -1) { event.found = true; grunt.verbose.writeln('event found ' + event.id +' in file '+ f); } }); }); events.forEach(function(event){ if(!event.found){ grunt.log.warn('Event '+ event.id + ' is not defined, added in version'+ event.added + 'and normally found in' + event.location); } }); });