Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #7276 from brave/fix/download-sync
Browse files Browse the repository at this point in the history
convert download-sync-client to node script
  • Loading branch information
bbondy authored Feb 16, 2017
2 parents 48ef31d + 1bafb74 commit 59a41eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clean-tp-data": "node ./tools/clean.js userData TrackingProtection.dat",
"docs": "jsdox js/actions/appActions.js js/actions/windowActions.js --output docs",
"download-languages": "node ./tools/downloadLanguages",
"download-sync-client": "./tools/downloadSyncClient",
"download-sync-client": "node ./tools/downloadSyncClient",
"electron-rebuild": "electron-rebuild",
"flow": "flow; test $? -eq 0 -o $? -eq 2",
"lint": "standard",
Expand Down
8 changes: 0 additions & 8 deletions tools/downloadSyncClient

This file was deleted.

42 changes: 42 additions & 0 deletions tools/downloadSyncClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'

const path = require('path')
const fs = require('fs')
const request = require('request')

const filename = path.join(__dirname, '..',
'app', 'extensions', 'brave', 'content', 'scripts', 'sync.js')
const releaseUrl = 'https://api.github.com/repos/brave/sync/releases/latest'

request({
url: releaseUrl,
headers: { 'User-Agent': 'request' }
}, function (error, response, body) {
if (error || response.statusCode !== 200) {
console.log('could not get', releaseUrl)
return
}
try {
const assets = JSON.parse(body).assets
for (let i = 0; i < assets.length; i++) {
if (assets[i].name === 'bundle.js') {
const downloadUrl = assets[i].browser_download_url
request({
url: downloadUrl,
headers: { 'User-Agent': 'request' }
}, function (error, response, body) {
if (error || response.statusCode !== 200) {
console.log('could not get', downloadUrl)
return
}
// Save the sync bundle
console.log('writing sync bundle to ' + filename)
fs.writeFileSync(filename, body)
})
break
}
}
} catch (e) {
console.log('got error parsing download URL', e)
}
})

0 comments on commit 59a41eb

Please sign in to comment.