dump-version-info.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var app = require('electron').app
  2. var fs = require('fs')
  3. var request = require('request')
  4. var TARGET_URL = 'https://atom.io/download/electron/index.json'
  5. function getDate () {
  6. var today = new Date()
  7. var year = today.getFullYear()
  8. var month = today.getMonth() + 1
  9. if (month <= 9) month = '0' + month
  10. var day = today.getDate()
  11. if (day <= 9) day = '0' + day
  12. return year + '-' + month + '-' + day
  13. }
  14. function getInfoForCurrentVersion () {
  15. var json = {}
  16. json.version = process.versions.electron
  17. json.date = getDate()
  18. var names = ['node', 'v8', 'uv', 'zlib', 'openssl', 'modules', 'chrome']
  19. for (var i in names) {
  20. var name = names[i]
  21. json[name] = process.versions[name]
  22. }
  23. json.files = [
  24. 'darwin-x64',
  25. 'darwin-x64-symbols',
  26. 'linux-ia32',
  27. 'linux-ia32-symbols',
  28. 'linux-x64',
  29. 'linux-x64-symbols',
  30. 'win32-ia32',
  31. 'win32-ia32-symbols',
  32. 'win32-x64',
  33. 'win32-x64-symbols'
  34. ]
  35. return json
  36. }
  37. function getIndexJsInServer (callback) {
  38. request(TARGET_URL, function (e, res, body) {
  39. if (e) {
  40. callback(e)
  41. } else if (res.statusCode !== 200) {
  42. callback(new Error('Server returned ' + res.statusCode))
  43. } else {
  44. callback(null, JSON.parse(body))
  45. }
  46. })
  47. }
  48. function findObjectByVersion (all, version) {
  49. for (var i in all) {
  50. if (all[i].version === version) return i
  51. }
  52. return -1
  53. }
  54. app.on('ready', function () {
  55. getIndexJsInServer(function (e, all) {
  56. if (e) {
  57. console.error(e)
  58. process.exit(1)
  59. }
  60. var current = getInfoForCurrentVersion()
  61. var found = findObjectByVersion(all, current.version)
  62. if (found === -1) {
  63. all.unshift(current)
  64. } else {
  65. all[found] = current
  66. }
  67. fs.writeFileSync(process.argv[2], JSON.stringify(all))
  68. process.exit(0)
  69. })
  70. })