Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download all Pebble SDK core packages
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