text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = dump;
  
  var _path = require("path");
  
  var _denodeify = _interopRequireDefault(require("denodeify"));
  
  var _prettyError = _interopRequireDefault(require("pretty-error"));
  
  var _rimraf = _interopRequireDefault(require("rimraf"));
  
  var _ora = _interopRequireDefault(require("ora"));
  
  var _createPost2 = _interopRequireDefault(require("./createPost"));
  
  var _createDataFile2 = _interopRequireDefault(require("./createDataFile"));
  
  var _addToDataFile2 = _interopRequireDefault(require("./addToDataFile"));
  
  var _i18n = _interopRequireDefault(require("../utils/i18n"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  
  function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
  
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
  
  function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
  
  var rimraf = (0, _denodeify["default"])(_rimraf["default"]);
  var createDirectory;
  
  function collectOperations(base, config) {
    var operations = [];
    var dsl = {
      directory: function directory(dir, subConfig) {
        operations.push(createDirectory((0, _path.resolve)(base, dir), subConfig));
      },
      createDataFile: function createDataFile(file, format, data) {
        operations.push(function () {
          return Promise.resolve(data).then(function (dr) {
            return _createDataFile2["default"].bind(null, (0, _path.resolve)(base, file), format, dr)();
          });
        });
      },
      createPost: function createPost(file, format, data) {
        operations.push(function () {
          return Promise.resolve(data).then(function (dr) {
            return _createPost2["default"].bind(null, (0, _path.resolve)(base, file), format, dr)();
          });
        });
      },
      addToDataFile: function addToDataFile(file, format, data) {
        operations.push(function () {
          return Promise.resolve(data).then(function (dr) {
            return _addToDataFile2["default"].bind(null, (0, _path.resolve)(base, file), format, dr)();
          });
        });
      }
    };
    config(dsl, _i18n["default"]);
    return operations;
  }
  
  createDirectory = function createDirectory(dir, config) {
    var operations = collectOperations(dir, config);
    return function () {
      return rimraf((0, _path.resolve)(dir, '*')).then(function () {
        return Promise.all(operations.map(function (o) {
          return o();
        }));
      }).then(function (descriptions) {
        var _ref;
  
        var description = "Created ".concat((0, _path.relative)(process.cwd(), dir));
        return (_ref = []).concat.apply(_ref, [description].concat(_toConsumableArray(descriptions)));
      });
    };
  };
  
  function start(path, config) {
    var operations = collectOperations(path, config);
    return function () {
      return Promise.all(operations.map(function (o) {
        return o();
      })).then(function (descriptions) {
        var _ref2;
  
        return (_ref2 = []).concat.apply(_ref2, _toConsumableArray(descriptions));
      });
    };
  }
  
  function dump(configFile, itemsRepo) {
    var quiet = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    var destinationPath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : process.cwd();
  
    /* eslint-disable global-require, import/no-dynamic-require */
    delete require.cache[configFile];
  
    var config = require(configFile);
    /* eslint-enable global-require, import/no-dynamic-require */
  
  
    _i18n["default"].availableLocales = itemsRepo.site.locales;
  
    var _i18n$availableLocale = _slicedToArray(_i18n["default"].availableLocales, 1);
  
    _i18n["default"].locale = _i18n$availableLocale[0];
    var startOperation = start(destinationPath, config.bind(config, itemsRepo));
    var spinner = (0, _ora["default"])('Writing content').start();
    return startOperation().then(function (operations) {
      spinner.succeed();
  
      if (!quiet) {
        process.stdout.write('\n');
        operations.forEach(function (operation) {
          return process.stdout.write("* ".concat(operation, "\n"));
        });
        process.stdout.write('\n');
      }
    })["catch"](function (e) {
      spinner.fail();
      process.stderr.write(new _prettyError["default"]().render(e));
    });
  }