"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.ensureFileContent = ensureFileContent;

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

var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));

async function ensureFileContent(file, data) {
  let previousContent = undefined;

  try {
    previousContent = await (0, _fsExtra.readFile)(file, `utf8`);
  } catch (e) {// whatever throws, we'll just write the file
  }

  if (previousContent !== data) {
    _reporter.default.verbose(`Updating "${file}"`);

    await (0, _fsExtra.outputFile)(file, data);
    return true;
  }

  _reporter.default.verbose(`Skipping "${file}"`);

  return false;
}
//# sourceMappingURL=ensure-file-content.js.map