Skip to content

Instantly share code, notes, and snippets.

@Catsync
Created March 13, 2015 15:09
Show Gist options
  • Save Catsync/c135b61f550704b5759a to your computer and use it in GitHub Desktop.
Save Catsync/c135b61f550704b5759a to your computer and use it in GitHub Desktop.
// Node script to download the Code Combat systems source
var http = require('http');
var fs = require('fs');
var componentDir = __dirname+'/systems';
// Make sure the components directory exists
try {
fs.mkdirSync(componentDir);
} catch(e) {
if(e.code != 'EEXIST') { throw e; }
}
// Get component data
http.get({
host: 'direct.codecombat.com',
path: '/db/level.system?project=name,code'
}, function(response) {
var json = '';
response.on('data', function(data) {
json += data;
});
response.on('end', function() {
components = JSON.parse(json);
console.log(components[0]);
for(var i=0; i < components.length; i++) {
writeComponentToFile(components[i]);
}
});
});
// write data to appropriate file
function writeComponentToFile(data) {
var filename = componentDir+'/'+data.name+'.coffee';
console.log(filename);
fs.writeFile(filename, data.code, function(err) {
if(err) {
console.log("ERROR writing to file "+filename);
} else {
console.log("Wrote: "+filename);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment