"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const rootDir = path_1.default.resolve(__dirname, "../../../");
const ignorePattern = /\/\.git\/|\/\.next\/|\/\.dist\/|node_modules|\/\.local_dist\/|\/\.tmp\/|\/types\/|\.config\.js|\/public\//;
function transformJsToTs(dir) {
    var _a;
    const dirContent = fs_1.default.readdirSync(dir);
    for (let i = 0; i < dirContent.length; i++) {
        const fileFolder = dirContent[i];
        const fullFileFolderPath = path_1.default.join(dir, fileFolder);
        const stat = fs_1.default.statSync(fullFileFolderPath);
        if (stat.isDirectory()) {
            transformJsToTs(fullFileFolderPath);
            continue;
        }
        if (ignorePattern.test(fullFileFolderPath))
            continue;
        if (fullFileFolderPath.match(/\.jsx?$/)) {
            const extension = (_a = fullFileFolderPath.match(/\.jsx?$/)) === null || _a === void 0 ? void 0 : _a[0];
            if (!extension)
                continue;
            const newExtension = extension.replace("js", "ts");
            const newFilePath = fullFileFolderPath.replace(/\.jsx?$/, newExtension);
            console.log(fullFileFolderPath);
            console.log(extension, "=>", newExtension);
            console.log(newFilePath);
            console.log("\n/////////////////////////////////////////");
            console.log("/////////////////////////////////////////\n");
            fs_1.default.copyFileSync(fullFileFolderPath, newFilePath);
            fs_1.default.unlinkSync(fullFileFolderPath);
        }
    }
}
console.log("rootDir", rootDir);
transformJsToTs(rootDir);