'use strict';

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

const node_fs = require('node:fs');
const node_path = require('node:path');

const fileExtensionWhitelist = [
  ".woff2",
  ".svg",
  ".img",
  ".jpg",
  ".jpeg",
  ".png"
];
function copyFileSync(source, target) {
  let targetFile = target;
  if (node_fs.existsSync(target)) {
    if (node_fs.lstatSync(target).isDirectory()) {
      targetFile = node_path.join(target, node_path.basename(source));
    }
  }
  if (!fileExtensionWhitelist.includes(node_path.extname(source))) {
    return;
  }
  node_fs.writeFileSync(targetFile, node_fs.readFileSync(source));
}
function copyFolderRecursiveSync(source, target) {
  let files = [];
  const targetFolder = node_path.join(target, node_path.basename(source));
  if (!node_fs.existsSync(targetFolder)) {
    node_fs.mkdirSync(targetFolder);
  }
  if (node_fs.lstatSync(source).isDirectory()) {
    files = node_fs.readdirSync(source);
    for (const file of files) {
      const curSource = node_path.join(source, file);
      if (node_fs.lstatSync(curSource).isDirectory()) {
        copyFolderRecursiveSync(curSource, targetFolder);
      } else {
        copyFileSync(curSource, targetFolder);
      }
    }
  }
}
const copyAssets = (assetDir, assets) => {
  if (!node_fs.existsSync(assetDir)) {
    node_fs.mkdirSync(assetDir, { recursive: true });
  }
  copyFolderRecursiveSync(assets, assetDir);
};

exports.copyAssets = copyAssets;
