"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = notifyLatestVersion;

var _compareVersions = _interopRequireDefault(require("compare-versions"));

var _fetchPackageInfo = _interopRequireDefault(require("./fetchPackageInfo"));

var _package = _interopRequireDefault(require("../../../package.json"));

var _ = require(".");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

async function notifyLatestVersion() {
  try {
    const versionCurrent = _package.default.version;
    const info = await (0, _fetchPackageInfo.default)();
    const {
      name,
      version
    } = info;
    const compare = (0, _compareVersions.default)(versionCurrent, version);
    const isOudated = compare === -1;

    if (isOudated) {
      _.logger.warn(`New version of ${name} available.
Local version is v${versionCurrent}
Latest version is v${version}
To update, please run:

  npm install -g ${name}

`);
    }
  } catch (error) {// Do nothing, it's ok to fail if app can't check for latest version
  }
}