import {
  techMap
} from "./chunk-2KG7JDHY.mjs";
import "./chunk-U4AFTAZI.mjs";
import "./chunk-EOKQCSHI.mjs";

// src/import.ts
import fs from "fs";
import path from "path";
var targetFile = process.argv[2];
if (!targetFile) {
  console.error("Please provide a path to a package.json file.");
  console.error("Usage: npm run import -- ../path/to/project/package.json");
  process.exit(1);
}
var absolutePath = path.resolve(process.cwd(), targetFile);
if (!fs.existsSync(absolutePath)) {
  console.error(`File not found: ${absolutePath}`);
  process.exit(1);
}
try {
  const content = fs.readFileSync(absolutePath, "utf-8");
  const pkg = JSON.parse(content);
  const projectName = pkg.name || "unknown-project";
  console.log(`\u{1F4E6} Analyzing stack for: ${projectName}`);
  const allDeps = {
    ...pkg.dependencies,
    ...pkg.devDependencies
  };
  const detectedTechs = [];
  Object.keys(allDeps).forEach((dep) => {
    if (techMap[dep]) {
      const tech = techMap[dep];
      detectedTechs.push({
        name: tech.name,
        slug: dep,
        logo: `https://raw.githubusercontent.com/benjamindotdev/stacksync/main/assets/logos/${tech.logo}`
      });
    }
  });
  const uniqueTechs = Array.from(new Set(detectedTechs.map((t) => t.slug))).map((slug) => detectedTechs.find((t) => t.slug === slug));
  const outputDir = path.join(process.cwd(), "stacksync", "projects", projectName);
  if (!fs.existsSync(outputDir)) {
    fs.mkdirSync(outputDir, { recursive: true });
  }
  const outputPath = path.join(outputDir, "stack.json");
  fs.writeFileSync(outputPath, JSON.stringify(uniqueTechs, null, 2));
  console.log(`\u2705 Stack saved to: ${outputPath}`);
  console.log(`   Found ${uniqueTechs.length} technologies.`);
} catch (error) {
  console.error("Error processing file:", error);
  process.exit(1);
}
