// Generated by CoffeeScript 1.10.0
(function() {
  var createUpdaterChecker, request;

  request = require('request');

  createUpdaterChecker = function(app) {
    var api, checkForUpdate;
    checkForUpdate = function() {
      if (!app.config.allowUpdateCheck) {
        console.log('Not searching for updates');
        return;
      }
      return request({
        url: 'https://registry.npmjs.org/' + encodeURIComponent(app.packageInfo.name),
        json: true
      }, function(err, res, data) {
        var latestVersion;
        if (err != null) {
          console.error(err);
        }
        if (data && data['dist-tags'] && data['dist-tags'].latest) {
          latestVersion = data['dist-tags'].latest;
          if (latestVersion !== app.packageInfo.version) {
            app.updateInfo = {
              available: true,
              newVersion: latestVersion,
              installedVersion: app.packageInfo.version
            };
            return console.log('Update available: ' + latestVersion + ' (' + app.packageInfo.version + ' installed)');
          }
        } else {
          return app.updateInfo = {
            available: false,
            installedVersion: app.packageInfo.version
          };
        }
      });
    };
    return api = {
      init: function(cb) {
        checkForUpdate();
        return cb();
      }
    };
  };

  module.exports = createUpdaterChecker;

}).call(this);
