function deleteDirRecursively(dir, except = [], currPath = '') {
  const exists = fs.existsSync(dir);
  const stats = exists && fs.statSync(dir);
  const isDirectory = exists && stats.isDirectory();

  if (!exists) {
    console.log(`File ${dir} does not exist`);
    return;
  }

  if (exists && isDirectory) {
    let deleteDir = true;
    fs.readdirSync(dir).forEach((childItemName) => {
      const relativePath = path.join(currPath, childItemName);
      if (
        childItemName.startsWith('.')
        || except.includes(childItemName)
        || except.includes(relativePath)
      ) {
        console.log('\x1b[33m%s\x1b[0m', `skipped: ${relativePath}`); // yellow
        deleteDir = false;
        return;
      }

      deleteDirRecursively(
        path.join(dir, childItemName),
        except,
        childItemName,
      );
    });

    if (deleteDir) {
      console.log('\x1b[31m%s\x1b[0m', `deleted: ${currPath || path.basename(dir)}`); // red
      fs.rmSync(dir, { recursive: true });
    }
  } else {
    console.log('\x1b[31m%s\x1b[0m', `deleted: ${currPath || path.basename(dir)}`); // red
    fs.rmSync(dir);
  }
}
Delete directory recursively
@param {string} dir Directory to delete
@param {string[]} except Files to not delete