'use strict';

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

var _os;

function _load_os() {
  return _os = require('os');
}

var _fsExtra;

function _load_fsExtra() {
  return _fsExtra = require('fs-extra');
}

var _fsChown;

function _load_fsChown() {
  return _fsChown = _interopRequireDefault(require('./fs-chown'));
}

var _promisify;

function _load_promisify() {
  return _promisify = _interopRequireDefault(require('./promisify'));
}

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

function writeFile(path, contents) {
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

  return (0, (_promisify || _load_promisify()).default)((_fsExtra || _load_fsExtra()).outputFile)(path, contents, options).then(function () {
    if (options.gid || options.uid) {
      var user = (0, (_os || _load_os()).userInfo)();
      return (0, (_fsChown || _load_fsChown()).default)(path, options.uid || user.uid, options.gid || user.gid);
    }

    return Promise.resolve();
  });
}