{"size": 1098, "ext": "js", "max_stars_repo_path": "node_modules/qext-scripts/scripts/upload-extension.js", "max_stars_repo_name": "jonvitale/QlikSenseExtension-CurateDefinitions", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/qext-scripts/scripts/upload-extension.js", "max_issues_repo_name": "jonvitale/QlikSenseExtension-CurateDefinitions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/qext-scripts/scripts/upload-extension.js", "max_forks_repo_name": "jonvitale/QlikSenseExtension-CurateDefinitions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.1428571429, "max_line_length": 65, "alphanum_fraction": 0.5701275046}
var fs = require('fs-extra');
var Rx = require('rxjs');
var RxQ = require('rxq');

module.exports = function(extensionName, serverConfig) {
  return Rx.Observable.create(observer => {
    var qrs = RxQ.connectQRS(serverConfig, 'cold');

    var extensionPath = `./dist/${extensionName}.zip`;

    var options = {
      "method": "POST",
      "hostname": serverConfig.host,
      "port": null,
      "path": "hdr/qrs/extension/upload?Xrfkey=123456789ABCDEFG",
      "headers": {
        "x-qlik-xrfkey": "123456789ABCDEFG",
        "hdr-usr": serverConfig.headers['hdr-usr'],
        "content-type": "application/zip"
      }
    };

    var http = qrs.http;
    var readZipFile = fs.readFile(extensionPath);

    readZipFile.then(POST_DATA => {
      var req = http.request(options, res => {
        var chunks = [];

        res.on('data', chunk => chunks.push(chunk));
        res.on('end', () => {
          var body = Buffer.concat(chunks);
          observer.next(extensionName);
          observer.complete();
        });
      });

      req.write(POST_DATA);
      req.end();
    })
  })
}