]> khamidou — GitHub mirrors - electron.git/commitdiff
Download the index.json from server
authorCheng Zhao <zcbenz@gmail.com>
Wed, 21 Jan 2015 05:53:53 +0000 (21:53 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 21 Jan 2015 05:53:53 +0000 (21:53 -0800)
package.json
script/dump_info.js

index f3e0388b6fbbe8626d6eda5eb5dd028dd7395221..e28f9c47090792e2f13e8e6fadf00e8de670b7e9 100644 (file)
@@ -12,7 +12,8 @@
   "devDependencies": {
     "atom-package-manager": "0.112.0",
     "coffee-script": "~1.7.1",
-    "coffeelint": "~1.3.0"
+    "coffeelint": "~1.3.0",
+    "request": "*"
   },
 
   "private": true,
index c95dd736c34927bcae339ea3bc84573f5ef536e1..beea7738f45330b8c645d5cb07fd2b835bff5185 100644 (file)
@@ -1,4 +1,8 @@
 var app = require('app');
+var fs = require('fs');
+var request = require('request');
+
+var TARGET_URL = 'http://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/index.json';
 
 function getDate() {
   var today = new Date();
@@ -12,7 +16,7 @@ function getDate() {
   return year + '-' + month + '-' + day;
 }
 
-app.on('ready', function() {
+function getInfoForCurrentVersion() {
   var json = {};
   json.version = process.versions['atom-shell'];
   json.date = getDate();
@@ -34,6 +38,42 @@ app.on('ready', function() {
     'win32-ia32-symbols',
   ];
 
-  console.log(json);
-  process.exit(0);
+  return json;
+}
+
+function getIndexJsInServer(callback) {
+  request(TARGET_URL, function(e, res, body) {
+    if (e)
+      callback(e);
+    else if (res.statusCode != 200)
+      callback(new Error('Server returned ' + res.statusCode));
+    else
+      callback(null, JSON.parse(body));
+  });
+}
+
+function findObjectByVersion(all, version) {
+  for (var i in all)
+    if (all[i].version == version)
+      return i;
+  return -1;
+}
+
+app.on('ready', function() {
+  getIndexJsInServer(function(e, all) {
+    if (e) {
+      console.error(e);
+      process.exit(1);
+    }
+
+    var current = getInfoForCurrentVersion();
+    var found = findObjectByVersion(all, current.version);
+    if (found == -1)
+      all.unshift(current);
+    else
+      all[found] = current;
+
+    fs.writeFileSync(process.argv[2], JSON.stringify(all));
+    process.exit(0);
+  });
 });