import fs from "fs";
import path from "path";

export const detectFramework = async () => {
  const pkgPath = path.resolve(process.cwd(), "package.json");

  if (!fs.existsSync(pkgPath)) return "Unknown";

  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
  const deps = {
    ...pkg.dependencies,
    ...pkg.devDependencies,
  };

  if (deps["next"]) return "Next.js";
  if (deps["react-scripts"] || deps["react"]) return "React";
  if (deps["vue"]) return "Vue.js";
  if (deps["nuxt"]) return "Nuxt.js";
  if (deps["svelte"]) return "Svelte";
  if (deps["@angular/core"]) return "Angular";
  if (deps["vite"]) return "Vite";

  return "Unknown";
};
