'use strict';

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

var _fsExtra = require('fs-extra');

var _fsExtra2 = _interopRequireDefault(_fsExtra);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _ = require('../../');

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

function remove(filePath) {
  filePath = _.abeExtend.hooks.instance.trigger('beforeDeleteFile', filePath);

  var revisions = _.cmsData.revision.getVersions(filePath);

  Array.prototype.forEach.call(revisions, function (revision) {
    _.cmsOperations.remove.removeFile(revision.path, revision.htmlPath);
  });

  filePath = _.abeExtend.hooks.instance.trigger('afterDeleteFile', filePath, {});

  _.Manager.instance.removePostFromList(filePath.replace(new RegExp('\\/', 'g'), _path2.default.sep));
}

function removeFile(file, json) {
  if (_.coreUtils.file.exist(file)) {
    _fsExtra2.default.removeSync(file);
  }

  if (_.coreUtils.file.exist(json)) {
    _fsExtra2.default.removeSync(json);
  }
}