import fs from "node:fs";
import path from "node:path";

function buildTimestamp() {
  const now = new Date();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const hour = String(now.getHours()).padStart(2, "0");
  const minute = String(now.getMinutes()).padStart(2, "0");
  return `--${month}-${day}-${hour}-${minute}`;
}

function main() {
  const cwd = process.cwd();
  const stamp = buildTimestamp();

  for (const entry of fs.readdirSync(cwd, { withFileTypes: true })) {
    if (!entry.isFile() || !entry.name.endsWith(".tgz")) continue;

    const oldPath = path.join(cwd, entry.name);
    const newName = entry.name.replace(/\.tgz$/, `${stamp}.tgz`);
    const newPath = path.join(cwd, newName);
    fs.renameSync(oldPath, newPath);
  }
}

main();
