Download all Pebble SDK core packages
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
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