"use strict";

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

var _fs = require("fs");

var _path = _interopRequireDefault(require("path"));

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

function createParentDir(filename) {
  const {
    dir
  } = _path.default.parse(filename);

  if (!(0, _fs.existsSync)(dir)) {
    (0, _fs.mkdirSync)(dir, {
      recursive: true
    });
  }
}

function copyFile(filename, outputFile) {
  createParentDir(outputFile);
  const readStream = (0, _fs.createReadStream)(filename);
  const writeStream = (0, _fs.createWriteStream)(outputFile);
  return readStream.pipe(writeStream);
}

function writeFile(filename, data) {
  createParentDir(filename);
  return (0, _fs.writeFileSync)(filename, data);
}