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

export function copyTemplateFiles(
  templateDir: string,
  destinationDir: string,
  includeSampleTest: boolean,
  baseURL: string
) {
  fs.readdirSync(templateDir, { withFileTypes: true }).forEach((entry) => {
    const srcPath = path.join(templateDir, entry.name);
    const destPath = path.join(destinationDir, entry.name);

    if (
      !includeSampleTest &&
      destinationDir.includes("ordino") &&
      entry.isFile() &&
      entry.name.endsWith(".ts") &&
              !srcPath.includes("ordino/support")
    ) {
      console.log(`Skipping .ts file: ${srcPath}`);
      return;
    }

    if (entry.isDirectory()) {
      fs.mkdirSync(destPath, { recursive: true });
      copyTemplateFiles(
        srcPath,
        destPath,
        includeSampleTest,
        baseURL
      );
    } else {
      fs.copyFileSync(srcPath, destPath);
    }
  });
}