|
| 1 | +var app = require('app'); |
| 2 | +var fs = require('fs'); |
| 3 | +var path = require('path'); |
| 4 | +var request = require('request'); |
| 5 | + |
| 6 | +var TARGET_URL = 'http://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/index.json'; |
| 7 | + |
| 8 | +function getDate() { |
| 9 | + var today = new Date(); |
| 10 | + var year = today.getFullYear(); |
| 11 | + var month = today.getMonth() + 1; |
| 12 | + if (month <= 9) |
| 13 | + month = '0' + month; |
| 14 | + var day= today.getDate(); |
| 15 | + if (day <= 9) |
| 16 | + day = '0' + day; |
| 17 | + return year + '-' + month + '-' + day; |
| 18 | +} |
| 19 | + |
| 20 | +function getApmVersion() { |
| 21 | + var package = require(path.resolve(__dirname, '..', 'package.json')); |
| 22 | + return package.devDependencies['atom-package-manager']; |
| 23 | +} |
| 24 | + |
| 25 | +function getInfoForCurrentVersion() { |
| 26 | + var json = {}; |
| 27 | + json.version = process.versions['atom-shell']; |
| 28 | + json.date = getDate(); |
| 29 | + json.apm = getApmVersion(); |
| 30 | + |
| 31 | + var names = ['node', 'v8', 'uv', 'zlib', 'openssl', 'modules', 'chrome'] |
| 32 | + for (var i in names) { |
| 33 | + var name = names[i]; |
| 34 | + json[name] = process.versions[name]; |
| 35 | + } |
| 36 | + |
| 37 | + json.files = [ |
| 38 | + 'darwin-x64', |
| 39 | + 'darwin-x64-symbols', |
| 40 | + 'linux-ia32', |
| 41 | + 'linux-ia32-symbols', |
| 42 | + 'linux-x64', |
| 43 | + 'linux-x64-symbols', |
| 44 | + 'win32-ia32', |
| 45 | + 'win32-ia32-symbols', |
| 46 | + ]; |
| 47 | + |
| 48 | + return json; |
| 49 | +} |
| 50 | + |
| 51 | +function getIndexJsInServer(callback) { |
| 52 | + request(TARGET_URL, function(e, res, body) { |
| 53 | + if (e) |
| 54 | + callback(e); |
| 55 | + else if (res.statusCode != 200) |
| 56 | + callback(new Error('Server returned ' + res.statusCode)); |
| 57 | + else |
| 58 | + callback(null, JSON.parse(body)); |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +function findObjectByVersion(all, version) { |
| 63 | + for (var i in all) |
| 64 | + if (all[i].version == version) |
| 65 | + return i; |
| 66 | + return -1; |
| 67 | +} |
| 68 | + |
| 69 | +app.on('ready', function() { |
| 70 | + getIndexJsInServer(function(e, all) { |
| 71 | + if (e) { |
| 72 | + console.error(e); |
| 73 | + process.exit(1); |
| 74 | + } |
| 75 | + |
| 76 | + var current = getInfoForCurrentVersion(); |
| 77 | + var found = findObjectByVersion(all, current.version); |
| 78 | + if (found == -1) |
| 79 | + all.unshift(current); |
| 80 | + else |
| 81 | + all[found] = current; |
| 82 | + |
| 83 | + fs.writeFileSync(process.argv[2], JSON.stringify(all)); |
| 84 | + process.exit(0); |
| 85 | + }); |
| 86 | +}); |
0 commit comments