import {
  mapCatalogToAstro
} from "./chunk-55D645EH.js";
import {
  verifyRequiredFieldsAreInCatalogConfigFile
} from "./chunk-5T63CXKU.js";

// src/catalog-to-astro-content-directory.js
import { glob } from "glob";
import * as path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
import os from "os";
var __filename = fileURLToPath(import.meta.url);
var rootPkg = path.resolve(path.dirname(__filename), "../");
var copyFiles = async (source, target) => {
  const files = await glob(path.join(source, "**"), {
    nodir: true,
    windowsPathsNoEscape: os.platform() == "win32",
    ignore: ["node_modules/**", "**/dist/**", "**/teams", "**/users", "**/*.mdx", "**/*.md", "**/package.json", "**/Dockerfile"]
  });
  const snippets = await glob(path.join(source, "snippets/**/*.mdx"), {
    nodir: true,
    windowsPathsNoEscape: os.platform() == "win32"
  });
  if (snippets.length > 0) {
    files.push(...snippets);
  }
  if (fs.existsSync(path.join(source, ".env"))) {
    files.push(path.join(source, ".env"));
  }
  for (const file of files) {
    mapCatalogToAstro({
      filePath: file,
      astroDir: target,
      projectDir: source
    }).map((astroPath) => {
      fs.cpSync(file, astroPath);
      return { oldPath: file, newPath: astroPath };
    });
  }
};
var catalogToAstro = async (source, astroDir) => {
  const astroContentDir = path.join(astroDir, "src/content/");
  if (fs.existsSync(astroContentDir)) fs.rmSync(astroContentDir, { recursive: true });
  fs.mkdirSync(astroContentDir);
  await verifyRequiredFieldsAreInCatalogConfigFile(source);
  if (!fs.existsSync(path.join(source, "eventcatalog.styles.css"))) {
    fs.writeFileSync(path.join(source, "eventcatalog.styles.css"), "");
  }
  await copyFiles(source, astroDir);
};

export {
  catalogToAstro
};
