Skip to content

Instantly share code, notes, and snippets.

@TheZoker
Forked from Wardormeur/gist:5755649f587b2aa7ed0c
Last active February 19, 2016 17:15
Show Gist options
  • Save TheZoker/ce30f1ff289d5a4c9823 to your computer and use it in GitHub Desktop.
Save TheZoker/ce30f1ff289d5a4c9823 to your computer and use it in GitHub Desktop.
Grunt task to check phpbb theme event coverage
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);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment