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

function renameFilesInDirectory(directory) {
  fs.readdir(directory, (err, files) => {
    if (err) {
      console.error(`Error reading directory ${directory}:`, err);
      return;
    }

    files.forEach((file) => {
      const ext = path.extname(file);
      if (ext === ".js") {
        const oldPath = path.join(directory, file);
        const newPath = path.join(directory, file.replace(".js", ".cjs"));

        fs.rename(oldPath, newPath, (renameErr) => {
          if (renameErr) {
            console.error(`Error renaming file ${file}:`, renameErr);
          } else {
            console.log(`Renamed: ${file} -> ${path.basename(newPath)}`);
          }
        });
      }
    });
  });
}

renameFilesInDirectory("./database/migrations");
renameFilesInDirectory("./database/seeders");
