mirror of
https://github.com/atom/atom.git
synced 2026-01-14 01:18:01 -05:00
26 lines
740 B
JavaScript
26 lines
740 B
JavaScript
'use strict';
|
|
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const syncRequest = require('sync-request');
|
|
|
|
module.exports = function(downloadURL, destinationPath) {
|
|
console.log(`Downloading file from GitHub Repository to ${destinationPath}`);
|
|
const response = syncRequest('GET', downloadURL, {
|
|
headers: {
|
|
Accept: 'application/vnd.github.v3.raw',
|
|
'User-Agent': 'Atom Build',
|
|
Authorization: `token ${process.env.GITHUB_TOKEN}`
|
|
}
|
|
});
|
|
|
|
if (response.statusCode === 200) {
|
|
fs.mkdirpSync(path.dirname(destinationPath));
|
|
fs.writeFileSync(destinationPath, response.body);
|
|
} else {
|
|
throw new Error(
|
|
'Error downloading file. HTTP Status ' + response.statusCode + '.'
|
|
);
|
|
}
|
|
};
|