{"size": 4917, "ext": "js", "max_stars_repo_path": "node_modules/datocms-client/lib/wpImport/import/categories.js", "max_stars_repo_name": "bredtoshred/philmckenziedigital", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/datocms-client/lib/wpImport/import/categories.js", "max_issues_repo_name": "bredtoshred/philmckenziedigital", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/datocms-client/lib/wpImport/import/categories.js", "max_forks_repo_name": "bredtoshred/philmckenziedigital", "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": 28.2586206897, "max_line_length": 241, "alphanum_fraction": 0.552776083}
"use strict";

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

var _allPages = _interopRequireDefault(require("../utils/allPages"));

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

var _require = require('../utils/progress'),
    progress = _require.progress;

function categories(dato, wp, itemTypeId) {
  var mapping, resources, tick, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, category, childCategories, tick2, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _category;

  return regeneratorRuntime.async(function categories$(_context) {
    while (1) {
      switch (_context.prev = _context.next) {
        case 0:
          mapping = {};
          _context.next = 3;
          return regeneratorRuntime.awrap((0, _allPages["default"])('Fetching categories', wp.categories()));

        case 3:
          resources = _context.sent;
          tick = progress('Creating categories', resources.length + 1);
          _iteratorNormalCompletion = true;
          _didIteratorError = false;
          _iteratorError = undefined;
          _context.prev = 8;
          _iterator = resources[Symbol.iterator]();

        case 10:
          if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
            _context.next = 18;
            break;
          }

          category = _step.value;
          _context.next = 14;
          return regeneratorRuntime.awrap(tick(category.name, dato.items.create({
            itemType: itemTypeId,
            name: category.name,
            slug: category.slug,
            description: category.description
          })));

        case 14:
          mapping[category.id] = _context.sent.id;

        case 15:
          _iteratorNormalCompletion = true;
          _context.next = 10;
          break;

        case 18:
          _context.next = 24;
          break;

        case 20:
          _context.prev = 20;
          _context.t0 = _context["catch"](8);
          _didIteratorError = true;
          _iteratorError = _context.t0;

        case 24:
          _context.prev = 24;
          _context.prev = 25;

          if (!_iteratorNormalCompletion && _iterator["return"] != null) {
            _iterator["return"]();
          }

        case 27:
          _context.prev = 27;

          if (!_didIteratorError) {
            _context.next = 30;
            break;
          }

          throw _iteratorError;

        case 30:
          return _context.finish(27);

        case 31:
          return _context.finish(24);

        case 32:
          _context.next = 34;
          return regeneratorRuntime.awrap(tick('Uncategorized', dato.items.create({
            itemType: itemTypeId,
            name: 'Uncategorized',
            slug: 'uncategorized',
            description: 'Uncategorized'
          })));

        case 34:
          mapping[1] = _context.sent.id;
          childCategories = resources.filter(function (c) {
            return c.parent;
          });
          tick2 = progress('Reordering categories', childCategories.length);
          _iteratorNormalCompletion2 = true;
          _didIteratorError2 = false;
          _iteratorError2 = undefined;
          _context.prev = 40;
          _iterator2 = childCategories[Symbol.iterator]();

        case 42:
          if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
            _context.next = 49;
            break;
          }

          _category = _step2.value;
          _context.next = 46;
          return regeneratorRuntime.awrap(tick2(_category.name, dato.items.update(mapping[_category.id], {
            parentId: mapping[_category.parent],
            position: 0
          })));

        case 46:
          _iteratorNormalCompletion2 = true;
          _context.next = 42;
          break;

        case 49:
          _context.next = 55;
          break;

        case 51:
          _context.prev = 51;
          _context.t1 = _context["catch"](40);
          _didIteratorError2 = true;
          _iteratorError2 = _context.t1;

        case 55:
          _context.prev = 55;
          _context.prev = 56;

          if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
            _iterator2["return"]();
          }

        case 58:
          _context.prev = 58;

          if (!_didIteratorError2) {
            _context.next = 61;
            break;
          }

          throw _iteratorError2;

        case 61:
          return _context.finish(58);

        case 62:
          return _context.finish(55);

        case 63:
          return _context.abrupt("return", mapping);

        case 64:
        case "end":
          return _context.stop();
      }
    }
  }, null, null, [[8, 20, 24, 32], [25,, 27, 31], [40, 51, 55, 63], [56,, 58, 62]]);
}