Created
December 11, 2016 20:18
-
-
Save C-D-Lewis/57969af50cbcb99729c97a21cd8d818a to your computer and use it in GitHub Desktop.
Download all Pebble SDK core packages
This file contains hidden or 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
var request = require('request'); | |
var https = require('https'); | |
var fs = require('fs'); | |
var URL = 'https://sdk.getpebble.com/v1/files/sdk-core'; | |
var OUTPUT_DIR = './sdks'; | |
if(!fs.existsSync(OUTPUT_DIR)){ | |
fs.mkdirSync(OUTPUT_DIR); | |
} | |
request(URL, function(err, response, body) { | |
var sdks = JSON.parse(body); | |
var files = sdks.files; | |
for(var i = 0; i < files.length; i++) { | |
request(URL + '/' + files[i].version, function(err, response, body) { | |
var downloadUrl = JSON.parse(body).url; | |
var index = downloadUrl.indexOf('release/'); | |
if(index < 0) { | |
return; // Ignore bad 2.9 URL | |
} | |
var fileName = downloadUrl.substring(index + 'release/'.length); | |
var file = fs.createWriteStream(OUTPUT_DIR + '/' + fileName); | |
https.get(downloadUrl, function(downloadResponse) { | |
downloadResponse.pipe(file); | |
console.log('Got ' + fileName); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment