text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
  
  var fs = require("fs");
  
  var path = require("path");
  
  var Promise = require("bluebird");
  
  var sharp = require("sharp");
  
  var _require = require("./common.js"),
      defaultIcons = _require.defaultIcons,
      doesIconExist = _require.doesIconExist;
  
  sharp.simd(true);
  
  function generateIcons(icons, srcIcon) {
    return Promise.map(icons, function (icon) {
      var size = parseInt(icon.sizes.substring(0, icon.sizes.lastIndexOf("x")));
      var imgPath = path.join("public", icon.src); // For vector graphics, instruct sharp to use a pixel density
      // suitable for the resolution we're rasterizing to.
      // For pixel graphics sources this has no effect.
      // Sharp accept density from 1 to 2400
  
      var density = Math.min(2400, Math.max(1, size));
      return sharp(srcIcon, {
        density: density
      }).resize(size).toFile(imgPath).then(function () {});
    });
  }
  
  exports.onPostBootstrap = function (args, pluginOptions) {
    return new Promise(function (resolve, reject) {
      var icon = pluginOptions.icon,
          manifest = (0, _objectWithoutPropertiesLoose2.default)(pluginOptions, ["icon"]); // Delete options we won't pass to the manifest.webmanifest.
  
      delete manifest.plugins;
      delete manifest.legacy;
      delete manifest.theme_color_in_head;
      delete manifest.crossOrigin; // If icons are not manually defined, use the default icon set.
  
      if (!manifest.icons) {
        manifest.icons = defaultIcons;
      } // Determine destination path for icons.
  
  
      var iconPath = path.join("public", path.dirname(manifest.icons[0].src)); //create destination directory if it doesn't exist
  
      if (!fs.existsSync(iconPath)) {
        fs.mkdirSync(iconPath);
      }
  
      fs.writeFileSync(path.join("public", "manifest.webmanifest"), JSON.stringify(manifest)); // Only auto-generate icons if a src icon is defined.
  
      if (icon !== undefined) {
        // Check if the icon exists
        if (!doesIconExist(icon)) {
          reject("icon (" + icon + ") does not exist as defined in gatsby-config.js. Make sure the file exists relative to the root of the site.");
        }
  
        generateIcons(manifest.icons, icon).then(function () {
          //images have been generated
          console.log("done generating icons for manifest");
          resolve();
        });
      } else {
        resolve();
      }
    });
  };