"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
require("source-map-support/register");
const glob_1 = require("glob");
const diff_1 = require("diff");
const fs = __importStar(require("fs"));
const utils_1 = require("../../utils");
async function generateDataset() {
    const files = (0, glob_1.globSync)("./**/*.ts", {
        ignore: ["./node_modules/**", "./dist/**", "./.git/**"],
    });
    const dataset = [];
    for (const filePath of files) {
        const commandOutput = await (0, utils_1.execAsync)(`git log --pretty=oneline -- ${filePath}`);
        const commitHashes = commandOutput.stdout.split("\n");
        for (const commitHash of commitHashes) {
            const firstSpaceIndex = commitHash.indexOf(" ");
            const hash = commitHash.slice(0, firstSpaceIndex);
            if (hash === "") {
                continue;
            }
            const { stdout: previousFileContent } = await (0, utils_1.execAsync)(`git show ${hash}:${filePath}`);
            const currentFileContent = fs.readFileSync(filePath, "utf-8");
            const patch = (0, diff_1.createPatch)(filePath, previousFileContent, currentFileContent);
            if (patch.split("\n").length < 10) {
                console.log(`Skipping ${filePath} as the diff is too small`);
                continue;
            }
            console.log(filePath);
            console.log(patch);
            dataset.push({
                before: previousFileContent,
                after: currentFileContent,
                patch,
            });
            fs.writeFileSync("./src/dataset/diffs/dataset.json", JSON.stringify(dataset, null, 2));
            if (dataset.length > 200) {
                break;
            }
        }
    }
    console.log(`Dataset of ${dataset.length} examples generated`);
}
if (require.main === module) {
    generateDataset();
}
//# sourceMappingURL=generate.js.map