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

function removeNodeModules(dir) {
  const entries = fs.readdirSync(dir, { withFileTypes: true });

  for (const entry of entries) {
    const fullPath = path.join(dir, entry.name);

    if (entry.isDirectory()) {
      if (["node_modules", ".next"].includes(entry.name)) {
        fs.rmSync(fullPath, { recursive: true });
      } else {
        removeNodeModules(fullPath);
      }

      if ([".apk", ".log", ".tmp"].some((ext) => entry.name.endsWith(ext))) {
        fs.unlinkSync(fullPath);
      }
    }
  }
}

removeNodeModules(".");
console.log("directories have been removed.");
