const path = require('path');
const fs = require('fs');

function mkdirp(dir) {
  const parent = path.dirname(dir);
  if (parent === dir) return;

  mkdirp(parent);

  try {
    fs.mkdirSync(dir);
  } catch (err) {
    if (err.code !== 'EEXIST') throw err;
  }
}

module.exports = mkdirp;
