{"size": 2792, "ext": "js", "max_stars_repo_path": "node_modules/npm-upgrade/lib/commands/ignore/reset.js", "max_stars_repo_name": "tranminhduc4796/cryptomon", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/npm-upgrade/lib/commands/ignore/reset.js", "max_issues_repo_name": "tranminhduc4796/cryptomon", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/npm-upgrade/lib/commands/ignore/reset.js", "max_forks_repo_name": "tranminhduc4796/cryptomon", "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": 30.347826087, "max_line_length": 148, "alphanum_fraction": 0.6815902579}
'use strict';

exports.__esModule = true;
exports.handler = exports.describe = exports.command = undefined;

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _catchAsyncError = require('../../catchAsyncError');

var _catchAsyncError2 = _interopRequireDefault(_catchAsyncError);

var _askUser = require('../../askUser');

var _askUser2 = _interopRequireDefault(_askUser);

var _cliStyles = require('../../cliStyles');

var _ignore = require('../ignore');

var _Config = require('../../Config');

var _Config2 = _interopRequireDefault(_Config);

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

const command = exports.command = 'reset [modules...]';
const describe = exports.describe = 'Reset ignored modules';

const handler = exports.handler = (0, _catchAsyncError2.default)((() => {
  var _ref = (0, _asyncToGenerator3.default)(function* (opts) {
    let modulesToReset = opts.modules;

    let invalidModules = [];
    const config = new _Config2.default();
    const ignoredModules = _lodash2.default.keys(config.ignore);

    console.log(`Currently ignored modules:\n\n${(0, _ignore.createIgnoredModulesTable)(config.ignore)}\n`);

    if (modulesToReset.length) {
      var _$partition = _lodash2.default.partition(modulesToReset, function (moduleName) {
        return _lodash2.default.includes(ignoredModules, moduleName);
      });

      modulesToReset = _$partition[0];
      invalidModules = _$partition[1];


      if (invalidModules.length) {
        console.log((0, _cliStyles.attention)(`These modules are not in the ignored list: ${(0, _cliStyles.strong)(invalidModules.join(', '))}\n`));
      }
    }

    if (!modulesToReset.length || invalidModules.length) {
      modulesToReset = yield (0, _askUser2.default)({
        type: 'checkbox',
        message: 'Select ignored modules to reset:',
        choices: ignoredModules,
        default: modulesToReset
      });
      console.log();
    }

    if (!modulesToReset.length) {
      return console.log((0, _cliStyles.attention)('Nothing to reset'));
    }

    console.log(`These ignored modules will be reset:\n\n${(0, _ignore.createIgnoredModulesTable)(config.ignore, modulesToReset)}\n`);

    const confirm = yield (0, _askUser2.default)({
      message: 'Are you sure?',
      type: 'confirm',
      default: false
    });

    if (!confirm) return;

    config.ignore = _lodash2.default.omit(config.ignore, modulesToReset);
    config.save();

    console.log((0, _cliStyles.success)('\nDone!'));
  });

  return function (_x) {
    return _ref.apply(this, arguments);
  };
})());