2016-05-11 09:07:09 +03:00
|
|
|
var app = require('electron').app
|
2016-03-25 23:03:49 +03:00
|
|
|
var fs = require('fs')
|
|
|
|
var request = require('request')
|
2015-01-21 08:53:53 +03:00
|
|
|
|
2016-11-05 02:13:39 +03:00
|
|
|
var TARGET_URL = 'https://atom.io/download/electron/index.json'
|
2015-01-21 01:39:14 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
function getDate () {
|
|
|
|
var today = new Date()
|
|
|
|
var year = today.getFullYear()
|
|
|
|
var month = today.getMonth() + 1
|
2016-03-28 23:19:41 +03:00
|
|
|
if (month <= 9) month = '0' + month
|
2016-03-25 23:03:49 +03:00
|
|
|
var day = today.getDate()
|
2016-03-28 23:19:41 +03:00
|
|
|
if (day <= 9) day = '0' + day
|
2016-03-25 23:03:49 +03:00
|
|
|
return year + '-' + month + '-' + day
|
2015-01-21 01:39:14 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
function getInfoForCurrentVersion () {
|
|
|
|
var json = {}
|
|
|
|
json.version = process.versions['atom-shell']
|
|
|
|
json.date = getDate()
|
2015-01-21 01:39:14 +03:00
|
|
|
|
2015-01-22 00:37:52 +03:00
|
|
|
var names = ['node', 'v8', 'uv', 'zlib', 'openssl', 'modules', 'chrome']
|
2015-01-21 01:39:14 +03:00
|
|
|
for (var i in names) {
|
2016-03-25 23:03:49 +03:00
|
|
|
var name = names[i]
|
|
|
|
json[name] = process.versions[name]
|
2015-01-21 01:39:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
json.files = [
|
|
|
|
'darwin-x64',
|
|
|
|
'darwin-x64-symbols',
|
|
|
|
'linux-ia32',
|
|
|
|
'linux-ia32-symbols',
|
|
|
|
'linux-x64',
|
|
|
|
'linux-x64-symbols',
|
|
|
|
'win32-ia32',
|
|
|
|
'win32-ia32-symbols',
|
2015-04-11 19:02:45 +03:00
|
|
|
'win32-x64',
|
2016-03-28 23:19:41 +03:00
|
|
|
'win32-x64-symbols'
|
2016-03-25 23:03:49 +03:00
|
|
|
]
|
2015-01-21 01:39:14 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
return json
|
2015-01-21 08:53:53 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
function getIndexJsInServer (callback) {
|
|
|
|
request(TARGET_URL, function (e, res, body) {
|
2016-03-28 23:19:41 +03:00
|
|
|
if (e) {
|
2016-03-25 23:03:49 +03:00
|
|
|
callback(e)
|
2016-03-29 02:11:00 +03:00
|
|
|
} else if (res.statusCode !== 200) {
|
2016-03-25 23:03:49 +03:00
|
|
|
callback(new Error('Server returned ' + res.statusCode))
|
2016-03-28 23:19:41 +03:00
|
|
|
} else {
|
2016-03-25 23:03:49 +03:00
|
|
|
callback(null, JSON.parse(body))
|
2016-03-28 23:19:41 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
2015-01-21 08:53:53 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
function findObjectByVersion (all, version) {
|
2016-03-29 02:11:00 +03:00
|
|
|
for (var i in all) {
|
|
|
|
if (all[i].version === version) return i
|
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
return -1
|
2015-01-21 08:53:53 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
app.on('ready', function () {
|
|
|
|
getIndexJsInServer(function (e, all) {
|
2015-01-21 08:53:53 +03:00
|
|
|
if (e) {
|
2016-03-25 23:03:49 +03:00
|
|
|
console.error(e)
|
|
|
|
process.exit(1)
|
2015-01-21 08:53:53 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
var current = getInfoForCurrentVersion()
|
|
|
|
var found = findObjectByVersion(all, current.version)
|
2016-03-29 02:11:00 +03:00
|
|
|
if (found === -1) {
|
2016-03-25 23:03:49 +03:00
|
|
|
all.unshift(current)
|
2016-03-29 02:11:00 +03:00
|
|
|
} else {
|
2016-03-25 23:03:49 +03:00
|
|
|
all[found] = current
|
2016-03-29 02:11:00 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
fs.writeFileSync(process.argv[2], JSON.stringify(all))
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
})
|