download-file-from-github.js
1 'use strict'; 2 3 const fs = require('fs-extra'); 4 const path = require('path'); 5 const syncRequest = require('sync-request'); 6 7 module.exports = function(downloadURL, destinationPath) { 8 console.log(`Downloading file from GitHub Repository to ${destinationPath}`); 9 const response = syncRequest('GET', downloadURL, { 10 headers: { 11 Accept: 'application/vnd.github.v3.raw', 12 'User-Agent': 'Atom Build' 13 } 14 }); 15 16 if (response.statusCode === 200) { 17 fs.mkdirpSync(path.dirname(destinationPath)); 18 fs.writeFileSync(destinationPath, response.body); 19 } else { 20 throw new Error( 21 'Error downloading file. HTTP Status ' + response.statusCode + '.' 22 ); 23 } 24 };