Last active
March 28, 2017 13:46
-
-
Save Catsync/d3b6a487370e2faa414c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Node script to download the Code Combat component source | |
var https = require('https'); | |
var fs = require('fs'); | |
var componentDir = __dirname+'/components'; | |
// Make sure the components directory exists | |
try { | |
fs.mkdirSync(componentDir); | |
} catch(e) { | |
if(e.code != 'EEXIST') { throw e; } | |
} | |
// Get component data | |
https.get({ | |
host: 'direct.codecombat.com', | |
path: '/db/level.component?project=system,name,code' | |
}, function(response) { | |
var json = ''; | |
response.on('data', function(data) { | |
json += data; | |
}); | |
response.on('end', function() { | |
components = JSON.parse(json); | |
for(var i=0; i < components.length; i++) { | |
// console.log(components[i].system+'.'+components[i].name+" -- " +components[i]._id); | |
writeComponentToFile(components[i]); | |
} | |
}); | |
}); | |
// write data to appropriate file | |
function writeComponentToFile(data) { | |
var filename = componentDir+'/'+data.system+'.'+data.name+'.coffee'; | |
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